|
@@ -292,17 +292,6 @@ public final class FileContext {
|
|
|
DELETE_ON_EXIT.clear();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Pathnames with scheme and relative path are illegal.
|
|
|
- * @param path to be checked
|
|
|
- */
|
|
|
- private static void checkNotSchemeWithRelative(final Path path) {
|
|
|
- if (path.toUri().isAbsolute() && !path.isUriPathAbsolute()) {
|
|
|
- throw new HadoopIllegalArgumentException(
|
|
|
- "Unsupported name: has scheme but relative path-part");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* Get the file system of supplied path.
|
|
@@ -315,13 +304,10 @@ public final class FileContext {
|
|
|
* @throws IOExcepton If the file system for <code>absOrFqPath</code> could
|
|
|
* not be instantiated.
|
|
|
*/
|
|
|
- private AbstractFileSystem getFSofPath(final Path absOrFqPath)
|
|
|
+ protected AbstractFileSystem getFSofPath(final Path absOrFqPath)
|
|
|
throws UnsupportedFileSystemException, IOException {
|
|
|
- checkNotSchemeWithRelative(absOrFqPath);
|
|
|
- if (!absOrFqPath.isAbsolute() && absOrFqPath.toUri().getScheme() == null) {
|
|
|
- throw new HadoopIllegalArgumentException(
|
|
|
- "FileContext Bug: path is relative");
|
|
|
- }
|
|
|
+ absOrFqPath.checkNotSchemeWithRelative();
|
|
|
+ absOrFqPath.checkNotRelative();
|
|
|
|
|
|
try {
|
|
|
// Is it the default FS for this FileContext?
|
|
@@ -523,7 +509,7 @@ public final class FileContext {
|
|
|
* </ul>
|
|
|
*/
|
|
|
public void setWorkingDirectory(final Path newWDir) throws IOException {
|
|
|
- checkNotSchemeWithRelative(newWDir);
|
|
|
+ newWDir.checkNotSchemeWithRelative();
|
|
|
/* wd is stored as a fully qualified path. We check if the given
|
|
|
* path is not relative first since resolve requires and returns
|
|
|
* an absolute path.
|
|
@@ -1128,26 +1114,6 @@ public final class FileContext {
|
|
|
}.resolve(this, absF);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Return a fully qualified version of the given symlink target if it
|
|
|
- * has no scheme and authority. Partially and fully qualified paths
|
|
|
- * are returned unmodified.
|
|
|
- * @param pathFS The AbstractFileSystem of the path
|
|
|
- * @param pathWithLink Path that contains the symlink
|
|
|
- * @param target The symlink's absolute target
|
|
|
- * @return Fully qualified version of the target.
|
|
|
- */
|
|
|
- private Path qualifySymlinkTarget(final AbstractFileSystem pathFS,
|
|
|
- Path pathWithLink, Path target) {
|
|
|
- // NB: makeQualified uses the target's scheme and authority, if
|
|
|
- // specified, and the scheme and authority of pathFS, if not.
|
|
|
- final String scheme = target.toUri().getScheme();
|
|
|
- final String auth = target.toUri().getAuthority();
|
|
|
- return (scheme == null && auth == null)
|
|
|
- ? target.makeQualified(pathFS.getUri(), pathWithLink.getParent())
|
|
|
- : target;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Return a file status object that represents the path. If the path
|
|
|
* refers to a symlink then the FileStatus of the symlink is returned.
|
|
@@ -2166,9 +2132,9 @@ public final class FileContext {
|
|
|
boolean overwrite) throws AccessControlException,
|
|
|
FileAlreadyExistsException, FileNotFoundException,
|
|
|
ParentNotDirectoryException, UnsupportedFileSystemException,
|
|
|
- IOException {
|
|
|
- checkNotSchemeWithRelative(src);
|
|
|
- checkNotSchemeWithRelative(dst);
|
|
|
+ IOException {
|
|
|
+ src.checkNotSchemeWithRelative();
|
|
|
+ dst.checkNotSchemeWithRelative();
|
|
|
Path qSrc = makeQualified(src);
|
|
|
Path qDst = makeQualified(dst);
|
|
|
checkDest(qSrc.getName(), qDst, overwrite);
|
|
@@ -2334,64 +2300,7 @@ public final class FileContext {
|
|
|
}.resolve(this, absF);
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Class used to perform an operation on and resolve symlinks in a
|
|
|
- * path. The operation may potentially span multiple file systems.
|
|
|
- */
|
|
|
- protected abstract class FSLinkResolver<T> {
|
|
|
- // The maximum number of symbolic link components in a path
|
|
|
- private static final int MAX_PATH_LINKS = 32;
|
|
|
-
|
|
|
- /**
|
|
|
- * Generic helper function overridden on instantiation to perform a
|
|
|
- * specific operation on the given file system using the given path
|
|
|
- * which may result in an UnresolvedLinkException.
|
|
|
- * @param fs AbstractFileSystem to perform the operation on.
|
|
|
- * @param p Path given the file system.
|
|
|
- * @return Generic type determined by the specific implementation.
|
|
|
- * @throws UnresolvedLinkException If symbolic link <code>path</code> could
|
|
|
- * not be resolved
|
|
|
- * @throws IOException an I/O error occured
|
|
|
- */
|
|
|
- public abstract T next(final AbstractFileSystem fs, final Path p)
|
|
|
- throws IOException, UnresolvedLinkException;
|
|
|
-
|
|
|
- /**
|
|
|
- * Performs the operation specified by the next function, calling it
|
|
|
- * repeatedly until all symlinks in the given path are resolved.
|
|
|
- * @param fc FileContext used to access file systems.
|
|
|
- * @param p The path to resolve symlinks in.
|
|
|
- * @return Generic type determined by the implementation of next.
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public T resolve(final FileContext fc, Path p) throws IOException {
|
|
|
- int count = 0;
|
|
|
- T in = null;
|
|
|
- Path first = p;
|
|
|
- // NB: More than one AbstractFileSystem can match a scheme, eg
|
|
|
- // "file" resolves to LocalFs but could have come by RawLocalFs.
|
|
|
- AbstractFileSystem fs = fc.getFSofPath(p);
|
|
|
|
|
|
- // Loop until all symlinks are resolved or the limit is reached
|
|
|
- for (boolean isLink = true; isLink;) {
|
|
|
- try {
|
|
|
- in = next(fs, p);
|
|
|
- isLink = false;
|
|
|
- } catch (UnresolvedLinkException e) {
|
|
|
- if (count++ > MAX_PATH_LINKS) {
|
|
|
- throw new IOException("Possible cyclic loop while " +
|
|
|
- "following symbolic link " + first);
|
|
|
- }
|
|
|
- // Resolve the first unresolved path component
|
|
|
- p = qualifySymlinkTarget(fs, p, fs.getLinkTarget(p));
|
|
|
- fs = fc.getFSofPath(p);
|
|
|
- }
|
|
|
- }
|
|
|
- return in;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Get the statistics for a particular file system
|
|
|
*
|