コード例 #1
0
        /// <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));
        }
コード例 #2
0
ファイル: FSDirMkdirOp.cs プロジェクト: orf53975/hadoop.net
        /// <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();
            }
        }