jojochuang commented on code in PR #8502: URL: https://github.com/apache/ozone/pull/8502#discussion_r2116685869
########## hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java: ########## @@ -983,4 +985,40 @@ public static void resolveOmHost(String omHost, int omPort) throw e; } } + + /** + * Return true if both File inputs are under the same mount point. + * @param file1 First File + * @param file2 Second File + * @return true if both File inputs are under the same mount point, false otherwise. + * @throws IOException + */ + public static boolean isUnderSameMountPoint(File file1, File file2) throws IOException { + if (file1 == null || file2 == null) { + return false; + } + // Get and compare mount points of file1 and file2 + java.nio.file.Path mountPoint1 = mountOf(file1.toPath()); + java.nio.file.Path mountPoint2 = mountOf(file2.toPath()); + return mountPoint1.equals(mountPoint2); + } + + /** + * Get top level mount point for the given path. + * From https://stackoverflow.com/a/64169740 + * @param p java.nio.file.Path + * @return Top level mount point for p. + * @throws IOException + */ + private static java.nio.file.Path mountOf(java.nio.file.Path p) throws IOException { + FileStore fs = Files.getFileStore(p); + java.nio.file.Path temp = p.toAbsolutePath(); + java.nio.file.Path mountp = temp; + + while( (temp = temp.getParent()) != null && fs.equals(Files.getFileStore(temp)) ) { + mountp = temp; + } + return mountp; + } Review Comment: would this work? ```suggestion public static boolean isUnderSameMountPoint(File file1, File file2) throws IOException { if (file1 == null || file2 == null) { return false; } FileStore fs1 = Files.getFileStore(file1.toPath()); FileStore fs2 = Files.getFileStore(file2.toPath()); return fs1.equals(fs2); } ``` -- 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...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org