Пример #1
0
        /// <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));
        }