/// <summary> /// For a given absolute path, create all ancestors as directories along the /// path. /// </summary> /// <remarks> /// For a given absolute path, create all ancestors as directories along the /// path. All ancestors inherit their parent's permission plus an implicit /// u+wx permission. This is used by create() and addSymlink() for /// implicitly creating all directories along the path. /// For example, path="/foo/bar/spam", "/foo" is an existing directory, /// "/foo/bar" is not existing yet, the function will create directory bar. /// </remarks> /// <returns> /// a tuple which contains both the new INodesInPath (with all the /// existing and newly created directories) and the last component in the /// relative path. Or return null if there are errors. /// </returns> /// <exception cref="System.IO.IOException"/> internal static KeyValuePair <INodesInPath, string> CreateAncestorDirectories(FSDirectory fsd, INodesInPath iip, PermissionStatus permission) { string last = new string(iip.GetLastLocalName(), Charsets.Utf8); INodesInPath existing = iip.GetExistingINodes(); IList <string> children = iip.GetPath(existing.Length(), iip.Length() - existing.Length ()); int size = children.Count; if (size > 1) { // otherwise all ancestors have been created IList <string> directories = children.SubList(0, size - 1); INode parentINode = existing.GetLastINode(); // Ensure that the user can traversal the path by adding implicit // u+wx permission to all ancestor directories existing = CreateChildrenDirectories(fsd, existing, directories, AddImplicitUwx(parentINode .GetPermissionStatus(), permission)); if (existing == null) { return(null); } } return(new AbstractMap.SimpleImmutableEntry <INodesInPath, string>(existing, last)); }
/// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/> /// <exception cref="Org.Apache.Hadoop.FS.UnresolvedLinkException"/> /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.AclException"/> /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/> internal static void MkdirForEditLog(FSDirectory fsd, long inodeId, string src, PermissionStatus permissions, IList <AclEntry> aclEntries, long timestamp) { System.Diagnostics.Debug.Assert(fsd.HasWriteLock()); INodesInPath iip = fsd.GetINodesInPath(src, false); byte[] localName = iip.GetLastLocalName(); INodesInPath existing = iip.GetParentINodesInPath(); Preconditions.CheckState(existing.GetLastINode() != null); UnprotectedMkdir(fsd, inodeId, existing, localName, permissions, aclEntries, timestamp ); }
/// <summary> /// Checks file system limits (max component length and max directory items) /// during a rename operation. /// </summary> /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.FSLimitException.PathComponentTooLongException /// "/> /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.FSLimitException.MaxDirectoryItemsExceededException /// "/> internal static void VerifyFsLimitsForRename(FSDirectory fsd, INodesInPath srcIIP , INodesInPath dstIIP) { byte[] dstChildName = dstIIP.GetLastLocalName(); string parentPath = dstIIP.GetParentPath(); fsd.VerifyMaxComponentLength(dstChildName, parentPath); // Do not enforce max directory items if renaming within same directory. if (srcIIP.GetINode(-2) != dstIIP.GetINode(-2)) { fsd.VerifyMaxDirItems(dstIIP.GetINode(-2).AsDirectory(), parentPath); } }
internal virtual bool AddSourceToDestination() { INode dstParent = dstParentIIP.GetLastINode(); byte[] dstChildName = dstIIP.GetLastLocalName(); INode toDst; if (withCount == null) { srcChild.SetLocalName(dstChildName); toDst = srcChild; } else { withCount.GetReferredINode().SetLocalName(dstChildName); toDst = new INodeReference.DstReference(dstParent.AsDirectory(), withCount, dstIIP .GetLatestSnapshotId()); } return(fsd.AddLastINodeNoQuotaCheck(dstParentIIP, toDst) != null); }
/// <summary>Add the given symbolic link to the fs.</summary> /// <remarks>Add the given symbolic link to the fs. Record it in the edits log.</remarks> /// <exception cref="System.IO.IOException"/> private static INodeSymlink AddSymlink(FSDirectory fsd, string path, INodesInPath iip, string target, PermissionStatus dirPerms, bool createParent, bool logRetryCache ) { long mtime = Time.Now(); byte[] localName = iip.GetLastLocalName(); if (createParent) { KeyValuePair <INodesInPath, string> e = FSDirMkdirOp.CreateAncestorDirectories(fsd , iip, dirPerms); if (e == null) { return(null); } iip = INodesInPath.Append(e.Key, null, localName); } string userName = dirPerms.GetUserName(); long id = fsd.AllocateNewInodeId(); PermissionStatus perm = new PermissionStatus(userName, null, FsPermission.GetDefault ()); INodeSymlink newNode = UnprotectedAddSymlink(fsd, iip.GetExistingINodes(), localName , id, target, mtime, mtime, perm); if (newNode == null) { NameNode.stateChangeLog.Info("addSymlink: failed to add " + path); return(null); } fsd.GetEditLog().LogSymlink(path, target, mtime, mtime, newNode, logRetryCache); if (NameNode.stateChangeLog.IsDebugEnabled()) { NameNode.stateChangeLog.Debug("addSymlink: " + path + " is added"); } return(newNode); }