/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus CreateSymlinkInt(FSNamesystem fsn, string target, string linkArg, PermissionStatus dirPerms, bool createParent, bool logRetryCache ) { FSDirectory fsd = fsn.GetFSDirectory(); string link = linkArg; if (!DFSUtil.IsValidName(link)) { throw new InvalidPathException("Invalid link name: " + link); } if (FSDirectory.IsReservedName(target) || target.IsEmpty()) { throw new InvalidPathException("Invalid target name: " + target); } if (NameNode.stateChangeLog.IsDebugEnabled()) { NameNode.stateChangeLog.Debug("DIR* NameSystem.createSymlink: target=" + target + " link=" + link); } FSPermissionChecker pc = fsn.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(link); INodesInPath iip; fsd.WriteLock(); try { link = fsd.ResolvePath(pc, link, pathComponents); iip = fsd.GetINodesInPath4Write(link, false); if (!createParent) { fsd.VerifyParentDir(iip, link); } if (!fsd.IsValidToCreate(link, iip)) { throw new IOException("failed to create link " + link + " either because the filename is invalid or the file exists" ); } if (fsd.IsPermissionEnabled()) { fsd.CheckAncestorAccess(pc, iip, FsAction.Write); } // validate that we have enough inodes. fsn.CheckFsObjectLimit(); // add symbolic link to namespace AddSymlink(fsd, link, iip, target, dirPerms, createParent, logRetryCache); } finally { fsd.WriteUnlock(); } NameNode.GetNameNodeMetrics().IncrCreateSymlinkOps(); return(fsd.GetAuditFileInfo(iip)); }
/// <exception cref="System.IO.IOException"/> internal static DirectoryListing GetListingInt(FSDirectory fsd, string srcArg, byte [] startAfter, bool needLocation) { FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(srcArg); string startAfterString = new string(startAfter, Charsets.Utf8); string src = fsd.ResolvePath(pc, srcArg, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, true); // Get file name when startAfter is an INodePath if (FSDirectory.IsReservedName(startAfterString)) { byte[][] startAfterComponents = FSDirectory.GetPathComponentsForReservedPath(startAfterString ); try { string tmp = FSDirectory.ResolvePath(src, startAfterComponents, fsd); byte[][] regularPath = INode.GetPathComponents(tmp); startAfter = regularPath[regularPath.Length - 1]; } catch (IOException) { // Possibly the inode is deleted throw new DirectoryListingStartAfterNotFoundException("Can't find startAfter " + startAfterString); } } bool isSuperUser = true; if (fsd.IsPermissionEnabled()) { if (iip.GetLastINode() != null && iip.GetLastINode().IsDirectory()) { fsd.CheckPathAccess(pc, iip, FsAction.ReadExecute); } else { fsd.CheckTraverse(pc, iip); } isSuperUser = pc.IsSuperUser(); } return(GetListing(fsd, iip, src, startAfter, needLocation, isSuperUser)); }
private void AddToParent(INodeDirectory parent, INode child) { if (parent == dir.rootDir && FSDirectory.IsReservedName(child)) { throw new HadoopIllegalArgumentException("File name \"" + child.GetLocalName() + "\" is reserved. Please " + " change the name of the existing file or directory to another " + "name before upgrading to this release."); } // NOTE: This does not update space counts for parents if (!parent.AddChild(child)) { return; } dir.CacheName(child); if (child.IsFile()) { UpdateBlocksMap(child.AsFile(), fsn.GetBlockManager()); } }