garydgregory commented on code in PR #732:
URL: https://github.com/apache/commons-io/pull/732#discussion_r2028741086


##########
src/main/java/org/apache/commons/io/file/PathUtils.java:
##########
@@ -148,6 +148,51 @@ private RelativeSortedPaths(final Path dir1, final Path 
dir2, final int maxDepth
             relativeFileList1 = tmpRelativeFileList1;
             relativeFileList2 = tmpRelativeFileList2;
         }
+
+        /**
+         * Compare Path lists in a FileSystem agnostic way
+         *
+         * @param a first list
+         * @param b second list
+         * @return true if the lists are equal
+         */
+        private boolean equals(List<Path> a, List<Path> b) {
+            if (a.size() != b.size()) {
+                return false;
+            }
+            // compare both lists using iterators
+            final Iterator<Path> listAIter = a.iterator();
+            final Iterator<Path> listBIter = b.iterator();
+            while (listAIter.hasNext() && listBIter.hasNext()) {
+                final Path pathA = listAIter.next();
+                final Path pathB = listBIter.next();
+                if (pathA.getFileSystem() == pathB.getFileSystem()) {
+                    if (!pathA.equals(pathB)) {
+                        return false;
+                    }
+                } else if 
(pathA.getFileSystem().getSeparator().equals(pathB.getFileSystem().getSeparator()))
 {
+                    // Separators are the same, so we can use toString 
comparison
+                    if (!pathA.toString().equals(pathB.toString())) {
+                        return false;

Review Comment:
   @dsmiley 
   It's worse than that: Path implementations are OS specific and separators 
are not normalized such that, for example, on macOS: 
`Paths.get("\\foo").normalize().equals(Paths.get("/foo").normalize())` returns 
`false`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to