boolean isDstDirectory = isDirectory(absoluteDst); if (!isDstDirectory) { throw new IOException("Rename destination " + absoluteDst + " does not exist or is not a directory"); boolean isSrcDirectory = isDirectory(absoluteSrc); boolean isDstDirectory = isDirectory(absoluteDst);
/** * Create a new file. Three possibilities: * - This is a data node and you're trying to create a unqualified file => write locally. * - This is a client node and you're trying to create unqualified file => pick a random data node and write there. * - The path you provide is qualified => write to that node. */ @Override public FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { final Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); // Handle root if (absolutePath.isRoot()) { throw new AccessControlException("Cannot create " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } // Only canonicalized path/remote files are allowed throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); return getDelegateFileSystem(remotePath.address).create(remotePath.path, permission, overwrite, bufferSize, replication, blockSize, progress); } catch (IllegalArgumentException e) { throw (IOException) (new IOException("Cannot create file " + absolutePath).initCause(e)); } }
/** * Create a new file. Three possibilities: * - This is a data node and you're trying to append a unqualified file => write locally. * - The path you provide is qualified => write to that node. * * If this is a client node and you try to write to a unqualified file, we'll throw */ @Override public FSDataOutputStream append(Path f, int bufferSize, Progressable progress) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); // Handle root if (absolutePath.isRoot()) { throw new AccessControlException("Cannot open " + f); } if(!isRemoteFile(f)){ if (isDirectory(absolutePath)) { throw new FileAlreadyExistsException("Directory already exists: " + f); } // Only fully canonicalized/remote files are allowed throw new IOException("Cannot create non-canonical path " + f); } try { RemotePath remotePath = getRemotePath(absolutePath); FileSystem delegate = getDelegateFileSystem(remotePath.address); return delegate.append(remotePath.path, bufferSize, progress); } catch (IllegalArgumentException e) { throw (FileNotFoundException) (new FileNotFoundException("No file " + absolutePath).initCause(e)); } }
@Override public Path canonicalizePath(Path p) throws IOException { Path absolutePath = toAbsolutePath(p); checkPath(absolutePath); if (isRemoteFile(absolutePath)) { return absolutePath; } if (isDirectory(absolutePath)) { return absolutePath; } if (localAccessAllowed) { return createRemotePath(localAddress, absolutePath); } // We aren't local or remote. That means we are a client node that wants to create a file. // We'll pick a random external location. final NodeEndpoint randomDelegate = getRandomDelegate(); return createRemotePath(randomDelegate.getAddress(), absolutePath); }