示例#1
0
        /// <exception cref="System.IO.IOException"/>
        private static void CheckSubtreeReadPermission(FSDirectory fsd, FSPermissionChecker
                                                       pc, string snapshottablePath, string snapshot)
        {
            string fromPath = snapshot == null ? snapshottablePath : Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                              .GetSnapshotPath(snapshottablePath, snapshot);
            INodesInPath iip = fsd.GetINodesInPath(fromPath, true);

            fsd.CheckPermission(pc, iip, false, null, null, FsAction.Read, FsAction.Read);
        }
示例#2
0
        private static bool RenameTo(FSDirectory fsd, FSPermissionChecker pc, string src,
                                     string dst, bool logRetryCache)
        {
            // Rename does not operate on link targets
            // Do not resolveLink when checking permissions of src and dst
            // Check write access to parent of src
            INodesInPath srcIIP = fsd.GetINodesInPath4Write(src, false);
            // Note: We should not be doing this.  This is move() not renameTo().
            string actualDst = fsd.IsDir(dst) ? dst + Path.Separator + new Path(src).GetName(
                ) : dst;
            INodesInPath dstIIP = fsd.GetINodesInPath4Write(actualDst, false);

            if (fsd.IsPermissionEnabled())
            {
                fsd.CheckPermission(pc, srcIIP, false, null, FsAction.Write, null, null, false);
                // Check write access to ancestor of dst
                fsd.CheckPermission(pc, dstIIP, false, FsAction.Write, null, null, null, false);
            }
            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* FSDirectory.renameTo: " + src + " to " + dst);
            }
            long mtime = Time.Now();
            bool stat  = false;

            fsd.WriteLock();
            try
            {
                stat = UnprotectedRenameTo(fsd, src, actualDst, srcIIP, dstIIP, mtime);
            }
            finally
            {
                fsd.WriteUnlock();
            }
            if (stat)
            {
                fsd.GetEditLog().LogRename(src, actualDst, mtime, logRetryCache);
                return(true);
            }
            return(false);
        }
        /// <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));
        }
示例#4
0
        /// <seealso>
        ///
        /// <see cref="UnprotectedRenameTo(FSDirectory, string, string, INodesInPath, INodesInPath, long, BlocksMapUpdateInfo, Org.Apache.Hadoop.FS.Options.Rename[])
        ///     "/>
        /// </seealso>
        /// <exception cref="System.IO.IOException"/>
        internal static void RenameTo(FSDirectory fsd, FSPermissionChecker pc, string src
                                      , string dst, INode.BlocksMapUpdateInfo collectedBlocks, bool logRetryCache, params
                                      Options.Rename[] options)
        {
            INodesInPath srcIIP = fsd.GetINodesInPath4Write(src, false);
            INodesInPath dstIIP = fsd.GetINodesInPath4Write(dst, false);

            if (fsd.IsPermissionEnabled())
            {
                // Rename does not operate on link targets
                // Do not resolveLink when checking permissions of src and dst
                // Check write access to parent of src
                fsd.CheckPermission(pc, srcIIP, false, null, FsAction.Write, null, null, false);
                // Check write access to ancestor of dst
                fsd.CheckPermission(pc, dstIIP, false, FsAction.Write, null, null, null, false);
            }
            if (NameNode.stateChangeLog.IsDebugEnabled())
            {
                NameNode.stateChangeLog.Debug("DIR* FSDirectory.renameTo: " + src + " to " + dst);
            }
            long mtime = Time.Now();

            fsd.WriteLock();
            try
            {
                if (UnprotectedRenameTo(fsd, src, dst, srcIIP, dstIIP, mtime, collectedBlocks, options
                                        ))
                {
                    FSDirDeleteOp.IncrDeletedFileCount(1);
                }
            }
            finally
            {
                fsd.WriteUnlock();
            }
            fsd.GetEditLog().LogRename(src, dst, mtime, logRetryCache, options);
        }
示例#5
0
        /// <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));
        }
        /// <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));
        }