From d0d89d77f071e923a4f71f6267c42686b4634456 Mon Sep 17 00:00:00 2001 From: "Levy.Xie" Date: Mon, 29 May 2023 11:48:09 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-96012=20=E7=A7=BB=E5=8A=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=88=B0=E8=87=AA=E5=B7=B1=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E4=B8=8B=EF=BC=8C=E6=96=87=E4=BB=B6=E5=A4=B9=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DefaultTemplateTreeDefineProcessor.java | 4 ++-- .../fr/design/file/FileOperationHelper.java | 14 +++++------ .../design/file/FileOperationHelperTest.java | 23 +++++++++++-------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java b/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java index e010986ac0..1d2048fa28 100644 --- a/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java +++ b/designer-base/src/main/java/com/fr/design/file/DefaultTemplateTreeDefineProcessor.java @@ -433,8 +433,8 @@ public class DefaultTemplateTreeDefineProcessor extends AbstractTemplateTreeDefi WARNING_MESSAGE); return false; } - // 检查移动源文件夹是否为目标文件夹的子文件夹 - if (FileOperationHelper.getInstance().isSubDirectory(getFileTree().getSelectedTreeNodes(), getTargetFileNode())) { + // 检查移动的源文件夹是否为目标文件夹相同文件夹或子文件夹 + if (FileOperationHelper.getInstance().isSubDirectoryOrSame(getFileTree().getSelectedTreeNodes(), getTargetFileNode())) { FineJOptionPane.showMessageDialog(this, Toolkit.i18nText("Fine-Design_Basic_Move_To_SubDirectory"), Toolkit.i18nText("Fine-Design_Basic_Alert"), diff --git a/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java b/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java index bc947df414..8bf57ae4ee 100644 --- a/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java +++ b/designer-base/src/main/java/com/fr/design/file/FileOperationHelper.java @@ -36,16 +36,16 @@ public class FileOperationHelper { } /** - * 检查目标文件夹是否为多个源文件夹中,任一文件夹的子文件夹 + * 检查目标文件夹是否为多个源文件夹中的任一文件夹,或者任一文件夹的子文件夹 * * @param fileNodes 需移动的源文件 * @param targetNode 移动后的目标文件夹 * @return */ - public boolean isSubDirectory(@NotNull ExpandMutableTreeNode[] fileNodes, @NotNull FileNode targetNode) { + public boolean isSubDirectoryOrSame(@NotNull ExpandMutableTreeNode[] fileNodes, @NotNull FileNode targetNode) { for (ExpandMutableTreeNode treeNode : fileNodes) { FileNode sourceFileNode = (FileNode) treeNode.getUserObject(); - if (isSubDirectory(sourceFileNode, targetNode)) { + if (isSubDirectoryOrSame(sourceFileNode, targetNode)) { return true; } } @@ -53,17 +53,17 @@ public class FileOperationHelper { } /** - * 检查目标文件夹是否为源文件夹的子文件夹 + * 检查目标文件夹是否为源文件夹,或源文件夹的子文件夹 * * @param sourceFileNode 需移动的源文件 * @param targetNode 移动后的目标文件夹 */ - public boolean isSubDirectory(@NotNull FileNode sourceFileNode, @NotNull FileNode targetNode) { + public boolean isSubDirectoryOrSame(@NotNull FileNode sourceFileNode, @NotNull FileNode targetNode) { if (!sourceFileNode.isDirectory() || !targetNode.isDirectory()) { return false; } - Path sourceDir = Paths.get(sourceFileNode.getEnvPath()); - Path targetDir = Paths.get(targetNode.getEnvPath()); + Path sourceDir = Paths.get(sourceFileNode.getEnvPath()).normalize(); + Path targetDir = Paths.get(targetNode.getEnvPath()).normalize(); return targetDir.startsWith(sourceDir); } diff --git a/designer-base/src/test/java/com/fr/design/file/FileOperationHelperTest.java b/designer-base/src/test/java/com/fr/design/file/FileOperationHelperTest.java index 612a65d70d..2fa25fd17d 100644 --- a/designer-base/src/test/java/com/fr/design/file/FileOperationHelperTest.java +++ b/designer-base/src/test/java/com/fr/design/file/FileOperationHelperTest.java @@ -23,22 +23,27 @@ public class FileOperationHelperTest { FileNode sourceNode5 = new FileNode("/usr/local/webroot/reportlets/demo/test", true); FileNode sourceNode6 = new FileNode("/usr/local/webroot/reportlets/demo/test", false); FileNode sourceNode7 = new FileNode("/usr/local/webroot/reportlets/demo/test123", true); + FileNode sourceNode8 = new FileNode("/usr/local/webroot/reportlets/../reportlets/demo/test", true); + FileNode sourceNode9 = new FileNode("/usr/local/webroot/reportlets/../reportlets/demo/test/c", true); FileNode targetNode = new FileNode("/usr/local/webroot/reportlets/demo/test", true); - Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectory(sourceNode1, targetNode)); - Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectory(sourceNode2, targetNode)); - Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(sourceNode3, targetNode)); - Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(sourceNode4, targetNode)); - Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectory(sourceNode5, targetNode)); - Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(sourceNode6, targetNode)); - Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(sourceNode7, targetNode)); + Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode1, targetNode)); + Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode2, targetNode)); + Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode3, targetNode)); + Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode4, targetNode)); + Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode5, targetNode)); + Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode6, targetNode)); + Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode7, targetNode)); + Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode8, targetNode)); + Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(sourceNode9, targetNode)); + ExpandMutableTreeNode treeNode1 = new ExpandMutableTreeNode(sourceNode1); ExpandMutableTreeNode treeNode2 = new ExpandMutableTreeNode(sourceNode2); ExpandMutableTreeNode treeNode3 = new ExpandMutableTreeNode(sourceNode3); ExpandMutableTreeNode treeNode4 = new ExpandMutableTreeNode(sourceNode4); - Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectory(new ExpandMutableTreeNode[]{treeNode1, treeNode2, treeNode3}, targetNode)); - Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectory(new ExpandMutableTreeNode[]{treeNode3, treeNode4}, targetNode)); + Assert.assertTrue(FileOperationHelper.getInstance().isSubDirectoryOrSame(new ExpandMutableTreeNode[]{treeNode1, treeNode2, treeNode3}, targetNode)); + Assert.assertFalse(FileOperationHelper.getInstance().isSubDirectoryOrSame(new ExpandMutableTreeNode[]{treeNode3, treeNode4}, targetNode)); } } \ No newline at end of file