/** * Checks that source is not an ancestor of dest, throwing an exception if it is. */ private void checkNotAncestor(File source, Directory destParent, FileSystemView destView) throws IOException { // if dest is not in the same file system, it couldn't be in source's subdirectories if (!isSameFileSystem(destView)) { return; } Directory current = destParent; while (true) { if (current.equals(source)) { throw new IOException( "invalid argument: can't move directory into a subdirectory of itself"); } if (current.isRootDirectory()) { return; } else { current = current.parent(); } } }
/** * Returns whether or not the two given paths locate the same file. The second path is located * using the given view rather than this file view. */ public boolean isSameFile(JimfsPath path, FileSystemView view2, JimfsPath path2) throws IOException { if (!isSameFileSystem(view2)) { return false; } store.readLock().lock(); try { File file = lookUp(path, Options.FOLLOW_LINKS).fileOrNull(); File file2 = view2.lookUp(path2, Options.FOLLOW_LINKS).fileOrNull(); return file != null && Objects.equals(file, file2); } finally { store.readLock().unlock(); } }
if (!isSameFileSystem(existingView)) { throw new FileSystemException( link.toString(),
checkNotNull(options); boolean sameFileSystem = isSameFileSystem(destView);
/** * Checks that source is not an ancestor of dest, throwing an exception if it is. */ private void checkNotAncestor(File source, Directory destParent, FileSystemView destView) throws IOException { // if dest is not in the same file system, it couldn't be in source's subdirectories if (!isSameFileSystem(destView)) { return; } Directory current = destParent; while (true) { if (current.equals(source)) { throw new IOException( "invalid argument: can't move directory into a subdirectory of itself"); } if (current.isRootDirectory()) { return; } else { current = current.parent(); } } }
/** * Returns whether or not the two given paths locate the same file. The second path is located * using the given view rather than this file view. */ public boolean isSameFile(JimfsPath path, FileSystemView view2, JimfsPath path2) throws IOException { if (!isSameFileSystem(view2)) { return false; } store.readLock().lock(); try { File file = lookUp(path, Options.FOLLOW_LINKS).fileOrNull(); File file2 = view2.lookUp(path2, Options.FOLLOW_LINKS).fileOrNull(); return file != null && Objects.equals(file, file2); } finally { store.readLock().unlock(); } }
if (!isSameFileSystem(existingView)) { throw new FileSystemException( link.toString(),
checkNotNull(options); boolean sameFileSystem = isSameFileSystem(destView);