/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus RemoveDefaultAcl(FSDirectory fsd, string srcArg) { string src = srcArg; CheckAclsConfigFlag(fsd); FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip; fsd.WriteLock(); try { iip = fsd.GetINodesInPath4Write(FSDirectory.NormalizePath(src), true); fsd.CheckOwner(pc, iip); INode inode = FSDirectory.ResolveLastINode(iip); int snapshotId = iip.GetLatestSnapshotId(); IList <AclEntry> existingAcl = AclStorage.ReadINodeLogicalAcl(inode); IList <AclEntry> newAcl = AclTransformation.FilterDefaultAclEntries(existingAcl); AclStorage.UpdateINodeAcl(inode, newAcl, snapshotId); fsd.GetEditLog().LogSetAcl(src, newAcl); } finally { fsd.WriteUnlock(); } return(fsd.GetAuditFileInfo(iip)); }
internal static FSDirRenameOp.RenameOldResult RenameToInt(FSDirectory fsd, string srcArg, string dstArg, bool logRetryCache) { string src = srcArg; string dst = dstArg; if (NameNode.stateChangeLog.IsDebugEnabled()) { NameNode.stateChangeLog.Debug("DIR* NameSystem.renameTo: " + src + " to " + dst); } if (!DFSUtil.IsValidName(dst)) { throw new IOException("Invalid name: " + dst); } FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] srcComponents = FSDirectory.GetPathComponentsForReservedPath(src); byte[][] dstComponents = FSDirectory.GetPathComponentsForReservedPath(dst); HdfsFileStatus resultingStat = null; src = fsd.ResolvePath(pc, src, srcComponents); dst = fsd.ResolvePath(pc, dst, dstComponents); bool status = RenameTo(fsd, pc, src, dst, logRetryCache); if (status) { INodesInPath dstIIP = fsd.GetINodesInPath(dst, false); resultingStat = fsd.GetAuditFileInfo(dstIIP); } return(new FSDirRenameOp.RenameOldResult(status, resultingStat)); }
/// <summary>The new rename which has the POSIX semantic.</summary> /// <exception cref="System.IO.IOException"/> internal static KeyValuePair <INode.BlocksMapUpdateInfo, HdfsFileStatus> RenameToInt (FSDirectory fsd, string srcArg, string dstArg, bool logRetryCache, params Options.Rename [] options) { string src = srcArg; string dst = dstArg; if (NameNode.stateChangeLog.IsDebugEnabled()) { NameNode.stateChangeLog.Debug("DIR* NameSystem.renameTo: with options -" + " " + src + " to " + dst); } if (!DFSUtil.IsValidName(dst)) { throw new InvalidPathException("Invalid name: " + dst); } FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] srcComponents = FSDirectory.GetPathComponentsForReservedPath(src); byte[][] dstComponents = FSDirectory.GetPathComponentsForReservedPath(dst); INode.BlocksMapUpdateInfo collectedBlocks = new INode.BlocksMapUpdateInfo(); src = fsd.ResolvePath(pc, src, srcComponents); dst = fsd.ResolvePath(pc, dst, dstComponents); RenameTo(fsd, pc, src, dst, collectedBlocks, logRetryCache, options); INodesInPath dstIIP = fsd.GetINodesInPath(dst, false); HdfsFileStatus resultingStat = fsd.GetAuditFileInfo(dstIIP); return(new AbstractMap.SimpleImmutableEntry <INode.BlocksMapUpdateInfo, HdfsFileStatus >(collectedBlocks, resultingStat)); }
/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus SetOwner(FSDirectory fsd, string src, string username , string group) { FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); INodesInPath iip; fsd.WriteLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); iip = fsd.GetINodesInPath4Write(src); fsd.CheckOwner(pc, iip); if (!pc.IsSuperUser()) { if (username != null && !pc.GetUser().Equals(username)) { throw new AccessControlException("Non-super user cannot change owner"); } if (group != null && !pc.ContainsGroup(group)) { throw new AccessControlException("User does not belong to " + group); } } UnprotectedSetOwner(fsd, src, username, group); } finally { fsd.WriteUnlock(); } fsd.GetEditLog().LogSetOwner(src, username, group); return(fsd.GetAuditFileInfo(iip)); }
/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus RemoveAcl(FSDirectory fsd, string srcArg) { string src = srcArg; CheckAclsConfigFlag(fsd); FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip; fsd.WriteLock(); try { iip = fsd.GetINodesInPath4Write(src); fsd.CheckOwner(pc, iip); UnprotectedRemoveAcl(fsd, iip); } finally { fsd.WriteUnlock(); } fsd.GetEditLog().LogSetAcl(src, AclFeature.EmptyEntryList); return(fsd.GetAuditFileInfo(iip)); }
/// <exception cref="System.IO.IOException"/> internal static bool SetReplication(FSDirectory fsd, BlockManager bm, string src, short replication) { bm.VerifyReplication(src, replication, null); bool isFile; FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); fsd.WriteLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath4Write(src); if (fsd.IsPermissionEnabled()) { fsd.CheckPathAccess(pc, iip, FsAction.Write); } short[] blockRepls = new short[2]; // 0: old, 1: new Block[] blocks = UnprotectedSetReplication(fsd, src, replication, blockRepls); isFile = blocks != null; if (isFile) { fsd.GetEditLog().LogSetReplication(src, replication); bm.SetReplication(blockRepls[0], blockRepls[1], src, blocks); } } finally { fsd.WriteUnlock(); } return(isFile); }
/// <summary>Set xattr for a file or directory.</summary> /// <param name="src">- path on which it sets the xattr</param> /// <param name="xAttr">- xAttr details to set</param> /// <param name="flag">- xAttrs flags</param> /// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus SetXAttr(FSDirectory fsd, string src, XAttr xAttr, EnumSet <XAttrSetFlag> flag, bool logRetryCache) { CheckXAttrsConfigFlag(fsd); CheckXAttrSize(fsd, xAttr); FSPermissionChecker pc = fsd.GetPermissionChecker(); XAttrPermissionFilter.CheckPermissionForApi(pc, xAttr, FSDirectory.IsReservedRawName (src)); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); IList <XAttr> xAttrs = Lists.NewArrayListWithCapacity(1); xAttrs.AddItem(xAttr); INodesInPath iip; fsd.WriteLock(); try { iip = fsd.GetINodesInPath4Write(src); CheckXAttrChangeAccess(fsd, iip, xAttr, pc); UnprotectedSetXAttrs(fsd, src, xAttrs, flag); } finally { fsd.WriteUnlock(); } fsd.GetEditLog().LogSetXAttrs(src, xAttrs, logRetryCache); return(fsd.GetAuditFileInfo(iip)); }
/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus SetAcl(FSDirectory fsd, string srcArg, IList <AclEntry > aclSpec) { string src = srcArg; CheckAclsConfigFlag(fsd); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); FSPermissionChecker pc = fsd.GetPermissionChecker(); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip; fsd.WriteLock(); try { iip = fsd.GetINodesInPath4Write(src); fsd.CheckOwner(pc, iip); IList <AclEntry> newAcl = UnprotectedSetAcl(fsd, src, aclSpec, false); fsd.GetEditLog().LogSetAcl(src, newAcl); } finally { fsd.WriteUnlock(); } return(fsd.GetAuditFileInfo(iip)); }
/// <exception cref="System.IO.IOException"/> internal static IList <XAttr> GetXAttrs(FSDirectory fsd, string srcArg, IList <XAttr > xAttrs) { string src = srcArg; CheckXAttrsConfigFlag(fsd); FSPermissionChecker pc = fsd.GetPermissionChecker(); bool isRawPath = FSDirectory.IsReservedRawName(src); bool getAll = xAttrs == null || xAttrs.IsEmpty(); if (!getAll) { XAttrPermissionFilter.CheckPermissionForApi(pc, xAttrs, isRawPath); } byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, true); if (fsd.IsPermissionEnabled()) { fsd.CheckPathAccess(pc, iip, FsAction.Read); } IList <XAttr> all = FSDirXAttrOp.GetXAttrs(fsd, src); IList <XAttr> filteredAll = XAttrPermissionFilter.FilterXAttrsForApi(pc, all, isRawPath ); if (getAll) { return(filteredAll); } if (filteredAll == null || filteredAll.IsEmpty()) { return(null); } IList <XAttr> toGet = Lists.NewArrayListWithCapacity(xAttrs.Count); foreach (XAttr xAttr in xAttrs) { bool foundIt = false; foreach (XAttr a in filteredAll) { if (xAttr.GetNameSpace() == a.GetNameSpace() && xAttr.GetName().Equals(a.GetName( ))) { toGet.AddItem(a); foundIt = true; break; } } if (!foundIt) { throw new IOException("At least one of the attributes provided was not found."); } } return(toGet); }
/// <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 ContentSummary GetContentSummary(FSDirectory fsd, string src) { byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); FSPermissionChecker pc = fsd.GetPermissionChecker(); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, false); if (fsd.IsPermissionEnabled()) { fsd.CheckPermission(pc, iip, false, null, null, null, FsAction.ReadExecute); } return(GetContentSummaryInt(fsd, iip)); }
/// <summary>Returns true if the file is closed</summary> /// <exception cref="System.IO.IOException"/> internal static bool IsFileClosed(FSDirectory fsd, string src) { FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, true); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } return(!INodeFile.ValueOf(iip.GetLastINode(), src).IsUnderConstruction()); }
/// <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)); }
/// <exception cref="System.IO.IOException"/> internal static IList <XAttr> ListXAttrs(FSDirectory fsd, string src) { FSDirXAttrOp.CheckXAttrsConfigFlag(fsd); FSPermissionChecker pc = fsd.GetPermissionChecker(); bool isRawPath = FSDirectory.IsReservedRawName(src); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, true); if (fsd.IsPermissionEnabled()) { /* To access xattr names, you need EXECUTE in the owning directory. */ fsd.CheckParentAccess(pc, iip, FsAction.Execute); } IList <XAttr> all = FSDirXAttrOp.GetXAttrs(fsd, src); return(XAttrPermissionFilter.FilterXAttrsForApi(pc, all, isRawPath)); }
/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus SetTimes(FSDirectory fsd, string src, long mtime, long atime) { if (!fsd.IsAccessTimeSupported() && atime != -1) { throw new IOException("Access time for hdfs is not configured. " + " Please set " + DFSConfigKeys.DfsNamenodeAccesstimePrecisionKey + " configuration parameter." ); } FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); INodesInPath iip; fsd.WriteLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); iip = fsd.GetINodesInPath4Write(src); // Write access is required to set access and modification times if (fsd.IsPermissionEnabled()) { fsd.CheckPathAccess(pc, iip, FsAction.Write); } INode inode = iip.GetLastINode(); if (inode == null) { throw new FileNotFoundException("File/Directory " + src + " does not exist."); } bool changed = UnprotectedSetTimes(fsd, inode, mtime, atime, true, iip.GetLatestSnapshotId ()); if (changed) { fsd.GetEditLog().LogTimes(src, mtime, atime); } } finally { fsd.WriteUnlock(); } return(fsd.GetAuditFileInfo(iip)); }
/// <summary>Remove a file/directory from the namespace.</summary> /// <remarks> /// Remove a file/directory from the namespace. /// <p> /// For large directories, deletion is incremental. The blocks under /// the directory are collected and deleted a small number at a time holding /// the /// <see cref="FSNamesystem"/> /// lock. /// <p> /// For small directory or file the deletion is done in one shot. /// </remarks> /// <exception cref="System.IO.IOException"/> internal static INode.BlocksMapUpdateInfo Delete(FSNamesystem fsn, string src, bool recursive, bool logRetryCache) { FSDirectory fsd = fsn.GetFSDirectory(); FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath4Write(src, false); if (!recursive && fsd.IsNonEmptyDirectory(iip)) { throw new PathIsNotEmptyDirectoryException(src + " is non empty"); } if (fsd.IsPermissionEnabled()) { fsd.CheckPermission(pc, iip, false, null, FsAction.Write, null, FsAction.All, true ); } return(DeleteInternal(fsn, src, iip, logRetryCache)); }
/// <exception cref="System.IO.IOException"/> internal static long GetPreferredBlockSize(FSDirectory fsd, string src) { FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); fsd.ReadLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, false); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } return(INodeFile.ValueOf(iip.GetLastINode(), src).GetPreferredBlockSize()); } finally { fsd.ReadUnlock(); } }
/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus SetStoragePolicy(FSDirectory fsd, BlockManager bm, string src, string policyName) { if (!fsd.IsStoragePolicyEnabled()) { throw new IOException("Failed to set storage policy since " + DFSConfigKeys.DfsStoragePolicyEnabledKey + " is set to false."); } FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); INodesInPath iip; fsd.WriteLock(); try { src = FSDirectory.ResolvePath(src, pathComponents, fsd); iip = fsd.GetINodesInPath4Write(src); if (fsd.IsPermissionEnabled()) { fsd.CheckPathAccess(pc, iip, FsAction.Write); } // get the corresponding policy and make sure the policy name is valid BlockStoragePolicy policy = bm.GetStoragePolicy(policyName); if (policy == null) { throw new HadoopIllegalArgumentException("Cannot find a block policy with the name " + policyName); } UnprotectedSetStoragePolicy(fsd, bm, iip, policy.GetId()); fsd.GetEditLog().LogSetStoragePolicy(src, policy.GetId()); } finally { fsd.WriteUnlock(); } return(fsd.GetAuditFileInfo(iip)); }
/// <exception cref="System.IO.IOException"/> internal static AclStatus GetAclStatus(FSDirectory fsd, string src) { CheckAclsConfigFlag(fsd); FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); string srcs = FSDirectory.NormalizePath(src); fsd.ReadLock(); try { // There is no real inode for the path ending in ".snapshot", so return a // non-null, unpopulated AclStatus. This is similar to getFileInfo. if (srcs.EndsWith(HdfsConstants.SeparatorDotSnapshotDir) && fsd.GetINode4DotSnapshot (srcs) != null) { return(new AclStatus.Builder().Owner(string.Empty).Group(string.Empty).Build()); } INodesInPath iip = fsd.GetINodesInPath(srcs, true); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } INode inode = FSDirectory.ResolveLastINode(iip); int snapshotId = iip.GetPathSnapshotId(); IList <AclEntry> acl = AclStorage.ReadINodeAcl(fsd.GetAttributes(src, inode.GetLocalNameBytes (), inode, snapshotId)); FsPermission fsPermission = inode.GetFsPermission(snapshotId); return(new AclStatus.Builder().Owner(inode.GetUserName()).Group(inode.GetGroupName ()).StickyBit(fsPermission.GetStickyBit()).SetPermission(fsPermission).AddEntries (acl).Build()); } finally { fsd.ReadUnlock(); } }
/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus SetPermission(FSDirectory fsd, string srcArg, FsPermission permission) { string src = srcArg; FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); INodesInPath iip; fsd.WriteLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); iip = fsd.GetINodesInPath4Write(src); fsd.CheckOwner(pc, iip); UnprotectedSetPermission(fsd, src, permission); } finally { fsd.WriteUnlock(); } fsd.GetEditLog().LogSetPermissions(src, permission); return(fsd.GetAuditFileInfo(iip)); }
/// <summary>Remove an xattr for a file or directory.</summary> /// <param name="src">- path to remove the xattr from</param> /// <param name="xAttr">- xAttr to remove</param> /// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus RemoveXAttr(FSDirectory fsd, string src, XAttr xAttr , bool logRetryCache) { FSDirXAttrOp.CheckXAttrsConfigFlag(fsd); FSPermissionChecker pc = fsd.GetPermissionChecker(); XAttrPermissionFilter.CheckPermissionForApi(pc, xAttr, FSDirectory.IsReservedRawName (src)); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); IList <XAttr> xAttrs = Lists.NewArrayListWithCapacity(1); xAttrs.AddItem(xAttr); INodesInPath iip; fsd.WriteLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); iip = fsd.GetINodesInPath4Write(src); CheckXAttrChangeAccess(fsd, iip, xAttr, pc); IList <XAttr> removedXAttrs = UnprotectedRemoveXAttrs(fsd, src, xAttrs); if (removedXAttrs != null && !removedXAttrs.IsEmpty()) { fsd.GetEditLog().LogRemoveXAttrs(src, removedXAttrs, logRetryCache); } else { throw new IOException("No matching attributes found for remove operation"); } } finally { fsd.WriteUnlock(); } return(fsd.GetAuditFileInfo(iip)); }
/// <summary>Get the file info for a specific file.</summary> /// <param name="srcArg">The string representation of the path to the file</param> /// <param name="resolveLink"> /// whether to throw UnresolvedLinkException /// if src refers to a symlink /// </param> /// <returns> /// object containing information regarding the file /// or null if file not found /// </returns> /// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus GetFileInfo(FSDirectory fsd, string srcArg, bool resolveLink ) { string src = srcArg; if (!DFSUtil.IsValidName(src)) { throw new InvalidPathException("Invalid file name: " + src); } FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath(src, resolveLink); bool isSuperUser = true; if (fsd.IsPermissionEnabled()) { fsd.CheckPermission(pc, iip, false, null, null, null, null, false); isSuperUser = pc.IsSuperUser(); } return(GetFileInfo(fsd, src, resolveLink, FSDirectory.IsReservedRawName(srcArg), isSuperUser)); }
/// <exception cref="System.IO.IOException"/> internal static HdfsFileStatus Mkdirs(FSNamesystem fsn, string src, PermissionStatus permissions, bool createParent) { FSDirectory fsd = fsn.GetFSDirectory(); if (NameNode.stateChangeLog.IsDebugEnabled()) { NameNode.stateChangeLog.Debug("DIR* NameSystem.mkdirs: " + src); } if (!DFSUtil.IsValidName(src)) { throw new InvalidPathException(src); } FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); fsd.WriteLock(); try { src = fsd.ResolvePath(pc, src, pathComponents); INodesInPath iip = fsd.GetINodesInPath4Write(src); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } INode lastINode = iip.GetLastINode(); if (lastINode != null && lastINode.IsFile()) { throw new FileAlreadyExistsException("Path is not a directory: " + src); } INodesInPath existing = lastINode != null ? iip : iip.GetExistingINodes(); if (lastINode == null) { if (fsd.IsPermissionEnabled()) { fsd.CheckAncestorAccess(pc, iip, FsAction.Write); } if (!createParent) { fsd.VerifyParentDir(iip, src); } // validate that we have enough inodes. This is, at best, a // heuristic because the mkdirs() operation might need to // create multiple inodes. fsn.CheckFsObjectLimit(); IList <string> nonExisting = iip.GetPath(existing.Length(), iip.Length() - existing .Length()); int length = nonExisting.Count; if (length > 1) { IList <string> ancestors = nonExisting.SubList(0, length - 1); // Ensure that the user can traversal the path by adding implicit // u+wx permission to all ancestor directories existing = CreateChildrenDirectories(fsd, existing, ancestors, AddImplicitUwx(permissions , permissions)); if (existing == null) { throw new IOException("Failed to create directory: " + src); } } if ((existing = CreateChildrenDirectories(fsd, existing, nonExisting.SubList(length - 1, length), permissions)) == null) { throw new IOException("Failed to create directory: " + src); } } return(fsd.GetAuditFileInfo(existing)); } finally { fsd.WriteUnlock(); } }