diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-30 20:59:19 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-30 20:59:19 +0000 |
commit | 7e2ec9984f81d35ed63e90f8dea27f423072c152 (patch) | |
tree | 3efcc661a1e9aeea71a80f49fcc8f89be53caf76 /sca-java-2.x/trunk/modules/contribution/src | |
parent | 8699192185597c315eda4af2b318eabe5b2bad8b (diff) |
Exclude duplicate directories that are linked from different symbolic links
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980960 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/contribution/src')
-rw-r--r-- | sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java index 4a1a222da8..0800dfaac5 100644 --- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java +++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/impl/DirectoryContributionScanner.java @@ -25,7 +25,9 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; @@ -83,8 +85,10 @@ public class DirectoryContributionScanner implements ContributionScanner { private List<String> scanContributionArtifacts(Contribution contribution) throws ContributionReadException { File directory = directory(contribution); List<String> artifacts = new ArrayList<String>(); + // [rfeng] There are cases that the folder contains symbolic links that point to the same physical directory + Set<File> visited = new HashSet<File>(); try { - traverse(artifacts, directory, directory); + traverse(artifacts, directory, directory, visited); } catch (IOException e) { throw new ContributionReadException(e); } @@ -98,22 +102,29 @@ public class DirectoryContributionScanner implements ContributionScanner { * @param fileList * @param file * @param root + * @param visited The visited directories * @throws IOException */ - private static void traverse(List<String> fileList, File file, File root) throws IOException { + private static void traverse(List<String> fileList, File file, File root, Set<File> visited) throws IOException { if (file.isFile()) { fileList.add(root.toURI().relativize(file.toURI()).toString()); } else if (file.isDirectory()) { - String uri = root.toURI().relativize(file.toURI()).toString(); - if (uri.endsWith("/")) { - uri = uri.substring(0, uri.length() - 1); - } - fileList.add(uri); + File dir = file.getCanonicalFile(); + if (!visited.contains(dir)) { + // [rfeng] Add the canonical file into the visited set to avoid duplicate navigation of directories + // following the symbolic links + visited.add(dir); + String uri = root.toURI().relativize(file.toURI()).toString(); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + fileList.add(uri); - File[] files = file.listFiles(); - for (File f: files) { - if (!f.getName().startsWith(".")) { - traverse(fileList, f, root); + File[] files = file.listFiles(); + for (File f : files) { + if (!f.getName().startsWith(".")) { + traverse(fileList, f, root, visited); + } } } } |