/// <exception cref="Org.Apache.Hadoop.Security.AccessControlException"/> /// <exception cref="System.IO.FileNotFoundException"/> /// <exception cref="System.IO.IOException"/> public override FileStatus[] ListStatus(Path f) { CheckPathIsSlash(f); FileStatus[] result = new FileStatus[theInternalDir.children.Count]; int i = 0; foreach (KeyValuePair <string, InodeTree.INode <FileSystem> > iEntry in theInternalDir .children) { InodeTree.INode <FileSystem> inode = iEntry.Value; if (inode is InodeTree.INodeLink) { InodeTree.INodeLink <FileSystem> link = (InodeTree.INodeLink <FileSystem>)inode; result[i++] = new FileStatus(0, false, 0, 0, creationTime, creationTime, Constants .Permission555, ugi.GetUserName(), ugi.GetGroupNames()[0], link.GetTargetLink(), new Path(inode.fullPath).MakeQualified(myUri, null)); } else { result[i++] = new FileStatus(0, true, 0, 0, creationTime, creationTime, Constants .Permission555, ugi.GetUserName(), ugi.GetGroupNames()[0], new Path(inode.fullPath ).MakeQualified(myUri, null)); } } return(result); }
// file system of this internal directory of mountT /// <exception cref="System.IO.FileNotFoundException"/> internal virtual InodeTree.INode <T> Resolve(string pathComponent) { InodeTree.INode <T> result = ResolveInternal(pathComponent); if (result == null) { throw new FileNotFoundException(); } return(result); }
/// <summary>Resolve the pathname p relative to root InodeDir</summary> /// <param name="p">- inout path</param> /// <param name="resolveLastComponent"></param> /// <returns>ResolveResult which allows further resolution of the remaining path</returns> /// <exception cref="System.IO.FileNotFoundException"/> internal virtual InodeTree.ResolveResult <T> Resolve(string p, bool resolveLastComponent ) { // TO DO: - more efficient to not split the path, but simply compare string[] path = BreakIntoPathComponents(p); if (path.Length <= 1) { // special case for when path is "/" InodeTree.ResolveResult <T> res = new InodeTree.ResolveResult <T>(InodeTree.ResultKind .isInternalDir, root.InodeDirFs, root.fullPath, SlashPath); return(res); } InodeTree.INodeDir <T> curInode = root; int i; // ignore first slash for (i = 1; i < path.Length - (resolveLastComponent ? 0 : 1); i++) { InodeTree.INode <T> nextInode = curInode.ResolveInternal(path[i]); if (nextInode == null) { StringBuilder failedAt = new StringBuilder(path[0]); for (int j = 1; j <= i; ++j) { failedAt.Append('/').Append(path[j]); } throw (new FileNotFoundException(failedAt.ToString())); } if (nextInode is InodeTree.INodeLink) { InodeTree.INodeLink <T> link = (InodeTree.INodeLink <T>)nextInode; Path remainingPath; if (i >= path.Length - 1) { remainingPath = SlashPath; } else { StringBuilder remainingPathStr = new StringBuilder("/" + path[i + 1]); for (int j = i + 2; j < path.Length; ++j) { remainingPathStr.Append('/').Append(path[j]); } remainingPath = new Path(remainingPathStr.ToString()); } InodeTree.ResolveResult <T> res = new InodeTree.ResolveResult <T>(InodeTree.ResultKind .isExternalDir, link.targetFileSystem, nextInode.fullPath, remainingPath); return(res); } else { if (nextInode is InodeTree.INodeDir) { curInode = (InodeTree.INodeDir <T>)nextInode; } } } // We have resolved to an internal dir in mount table. Path remainingPath_1; if (resolveLastComponent) { remainingPath_1 = SlashPath; } else { // note we have taken care of when path is "/" above // for internal dirs rem-path does not start with / since the lookup // that follows will do a children.get(remaningPath) and will have to // strip-out the initial / StringBuilder remainingPathStr = new StringBuilder("/" + path[i]); for (int j = i + 1; j < path.Length; ++j) { remainingPathStr.Append('/').Append(path[j]); } remainingPath_1 = new Path(remainingPathStr.ToString()); } InodeTree.ResolveResult <T> res_1 = new InodeTree.ResolveResult <T>(InodeTree.ResultKind .isInternalDir, curInode.InodeDirFs, curInode.fullPath, remainingPath_1); return(res_1); }
/// <exception cref="URISyntaxException"/> /// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/> /// <exception cref="Org.Apache.Hadoop.FS.UnsupportedFileSystemException"/> private void CreateLink(string src, string target, bool isLinkMerge, UserGroupInformation aUgi) { // Validate that src is valid absolute path Path srcPath = new Path(src); if (!srcPath.IsAbsoluteAndSchemeAuthorityNull()) { throw new IOException("ViewFs:Non absolute mount name in config:" + src); } string[] srcPaths = BreakIntoPathComponents(src); InodeTree.INodeDir <T> curInode = root; int i; // Ignore first initial slash, process all except last component for (i = 1; i < srcPaths.Length - 1; i++) { string iPath = srcPaths[i]; InodeTree.INode <T> nextInode = curInode.ResolveInternal(iPath); if (nextInode == null) { InodeTree.INodeDir <T> newDir = curInode.AddDir(iPath, aUgi); newDir.InodeDirFs = GetTargetFileSystem(newDir); nextInode = newDir; } if (nextInode is InodeTree.INodeLink) { // Error - expected a dir but got a link throw new FileAlreadyExistsException("Path " + nextInode.fullPath + " already exists as link" ); } else { System.Diagnostics.Debug.Assert((nextInode is InodeTree.INodeDir)); curInode = (InodeTree.INodeDir <T>)nextInode; } } // Now process the last component // Add the link in 2 cases: does not exist or a link exists string iPath_1 = srcPaths[i]; // last component if (curInode.ResolveInternal(iPath_1) != null) { // directory/link already exists StringBuilder strB = new StringBuilder(srcPaths[0]); for (int j = 1; j <= i; ++j) { strB.Append('/').Append(srcPaths[j]); } throw new FileAlreadyExistsException("Path " + strB + " already exists as dir; cannot create link here" ); } InodeTree.INodeLink <T> newLink; string fullPath = curInode.fullPath + (curInode == root ? string.Empty : "/") + iPath_1; if (isLinkMerge) { // Target is list of URIs string[] targetsList = StringUtils.GetStrings(target); URI[] targetsListURI = new URI[targetsList.Length]; int k = 0; foreach (string itarget in targetsList) { targetsListURI[k++] = new URI(itarget); } newLink = new InodeTree.INodeLink <T>(fullPath, aUgi, GetTargetFileSystem(targetsListURI ), targetsListURI); } else { newLink = new InodeTree.INodeLink <T>(fullPath, aUgi, GetTargetFileSystem(new URI( target)), new URI(target)); } curInode.AddLink(iPath_1, newLink); mountPoints.AddItem(new InodeTree.MountPoint <T>(src, newLink)); }