/// <exception cref="System.IO.IOException"/> private string SchemeFromPath(Path path) { string scheme = path.ToUri().GetScheme(); if (scheme == null) { if (fs != null) { scheme = fs.GetUri().GetScheme(); } else { scheme = fc.GetFSofPath(fc.FixRelativePart(path)).GetUri().GetScheme(); } } return(scheme); }
/// <summary> /// Performs the operation specified by the next function, calling it /// repeatedly until all symlinks in the given path are resolved. /// </summary> /// <param name="fc">FileContext used to access file systems.</param> /// <param name="path">The path to resolve symlinks on.</param> /// <returns>Generic type determined by the implementation of next.</returns> /// <exception cref="System.IO.IOException"/> public virtual T Resolve(FileContext fc, Path path) { int count = 0; T @in = null; Path p = path; // 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 (bool isLink = true; isLink;) { try { @in = Next(fs, p); isLink = false; } catch (UnresolvedLinkException e) { if (!fc.resolveSymlinks) { throw new IOException("Path " + path + " contains a symlink" + " and symlink resolution is disabled (" + CommonConfigurationKeys.FsClientResolveRemoteSymlinksKey + ").", e); } if (!FileSystem.AreSymlinksEnabled()) { throw new IOException("Symlink resolution is disabled in" + " this version of Hadoop." ); } if (count++ > FsConstants.MaxPathLinks) { throw new IOException("Possible cyclic loop while " + "following symbolic link " + path); } // Resolve the first unresolved path component p = QualifySymlinkTarget(fs.GetUri(), p, fs.GetLinkTarget(p)); fs = fc.GetFSofPath(p); } } return(@in); }