Example #1
0
        /// <summary>Asserts the value of the FsPermission bits on the inode of a specific path.
        ///     </summary>
        /// <param name="fs">FileSystem to use for check</param>
        /// <param name="pathToCheck">Path inode to check</param>
        /// <param name="perm">short expected permission bits</param>
        /// <exception cref="System.IO.IOException">thrown if there is an I/O error</exception>
        public static void AssertPermission(FileSystem fs, Path pathToCheck, short perm)
        {
            short        filteredPerm = (short)(perm & 0x3ff);
            FsPermission fsPermission = fs.GetFileStatus(pathToCheck).GetPermission();

            NUnit.Framework.Assert.AreEqual(filteredPerm, fsPermission.ToShort());
            NUnit.Framework.Assert.AreEqual(((perm & (1 << 12)) != 0), fsPermission.GetAclBit
                                                ());
        }
        // last ditch effort to ensure temp file is removed
        /// <summary>Preserve the attributes of the source to the target.</summary>
        /// <remarks>
        /// Preserve the attributes of the source to the target.
        /// The method calls
        /// <see cref="ShouldPreserve(FileAttribute)"/>
        /// to check what
        /// attribute to preserve.
        /// </remarks>
        /// <param name="src">source to preserve</param>
        /// <param name="target">where to preserve attributes</param>
        /// <param name="preserveRawXAttrs">true if raw.* xattrs should be preserved</param>
        /// <exception cref="System.IO.IOException">if fails to preserve attributes</exception>
        protected internal virtual void PreserveAttributes(PathData src, PathData target,
                                                           bool preserveRawXAttrs)
        {
            if (ShouldPreserve(CommandWithDestination.FileAttribute.Timestamps))
            {
                target.fs.SetTimes(target.path, src.stat.GetModificationTime(), src.stat.GetAccessTime
                                       ());
            }
            if (ShouldPreserve(CommandWithDestination.FileAttribute.Ownership))
            {
                target.fs.SetOwner(target.path, src.stat.GetOwner(), src.stat.GetGroup());
            }
            if (ShouldPreserve(CommandWithDestination.FileAttribute.Permission) || ShouldPreserve
                    (CommandWithDestination.FileAttribute.Acl))
            {
                target.fs.SetPermission(target.path, src.stat.GetPermission());
            }
            if (ShouldPreserve(CommandWithDestination.FileAttribute.Acl))
            {
                FsPermission perm = src.stat.GetPermission();
                if (perm.GetAclBit())
                {
                    IList <AclEntry> srcEntries     = src.fs.GetAclStatus(src.path).GetEntries();
                    IList <AclEntry> srcFullEntries = AclUtil.GetAclFromPermAndEntries(perm, srcEntries
                                                                                       );
                    target.fs.SetAcl(target.path, srcFullEntries);
                }
            }
            bool preserveXAttrs = ShouldPreserve(CommandWithDestination.FileAttribute.Xattr);

            if (preserveXAttrs || preserveRawXAttrs)
            {
                IDictionary <string, byte[]> srcXAttrs = src.fs.GetXAttrs(src.path);
                if (srcXAttrs != null)
                {
                    IEnumerator <KeyValuePair <string, byte[]> > iter = srcXAttrs.GetEnumerator();
                    while (iter.HasNext())
                    {
                        KeyValuePair <string, byte[]> entry = iter.Next();
                        string xattrName = entry.Key;
                        if (xattrName.StartsWith(Raw) || preserveXAttrs)
                        {
                            target.fs.SetXAttr(target.path, entry.Key, entry.Value);
                        }
                    }
                }
            }
        }
Example #3
0
        /// <summary>Convert a AclStatus object to a Json string.</summary>
        public static string ToJsonString(AclStatus status)
        {
            if (status == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["owner"]     = status.GetOwner();
            m["group"]     = status.GetGroup();
            m["stickyBit"] = status.IsStickyBit();
            IList <string> stringEntries = new AList <string>();

            foreach (AclEntry entry in status.GetEntries())
            {
                stringEntries.AddItem(entry.ToString());
            }
            m["entries"] = stringEntries;
            FsPermission perm = status.GetPermission();

            if (perm != null)
            {
                m["permission"] = ToString(perm);
                if (perm.GetAclBit())
                {
                    m["aclBit"] = true;
                }
                if (perm.GetEncryptedBit())
                {
                    m["encBit"] = true;
                }
            }
            IDictionary <string, IDictionary <string, object> > finalMap = new SortedDictionary <
                string, IDictionary <string, object> >();

            finalMap[typeof(AclStatus).Name] = m;
            ObjectMapper mapper = new ObjectMapper();

            try
            {
                return(mapper.WriteValueAsString(finalMap));
            }
            catch (IOException)
            {
            }
            return(null);
        }
Example #4
0
        /// <summary>Convert a HdfsFileStatus object to a Json string.</summary>
        public static string ToJsonString(HdfsFileStatus status, bool includeType)
        {
            if (status == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["pathSuffix"] = status.GetLocalName();
            m["type"]       = JsonUtil.PathType.ValueOf(status);
            if (status.IsSymlink())
            {
                m["symlink"] = status.GetSymlink();
            }
            m["length"] = status.GetLen();
            m["owner"]  = status.GetOwner();
            m["group"]  = status.GetGroup();
            FsPermission perm = status.GetPermission();

            m["permission"] = ToString(perm);
            if (perm.GetAclBit())
            {
                m["aclBit"] = true;
            }
            if (perm.GetEncryptedBit())
            {
                m["encBit"] = true;
            }
            m["accessTime"]       = status.GetAccessTime();
            m["modificationTime"] = status.GetModificationTime();
            m["blockSize"]        = status.GetBlockSize();
            m["replication"]      = status.GetReplication();
            m["fileId"]           = status.GetFileId();
            m["childrenNum"]      = status.GetChildrenNum();
            m["storagePolicy"]    = status.GetStoragePolicy();
            ObjectMapper mapper = new ObjectMapper();

            try
            {
                return(includeType ? ToJsonString(typeof(FileStatus), m) : mapper.WriteValueAsString
                           (m));
            }
            catch (IOException)
            {
            }
            return(null);
        }
Example #5
0
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessPath(PathData item)
            {
                @out.WriteLine("# file: " + item);
                @out.WriteLine("# owner: " + item.stat.GetOwner());
                @out.WriteLine("# group: " + item.stat.GetGroup());
                FsPermission perm = item.stat.GetPermission();

                if (perm.GetStickyBit())
                {
                    @out.WriteLine("# flags: --" + (perm.GetOtherAction().Implies(FsAction.Execute) ?
                                                    "t" : "T"));
                }
                AclStatus        aclStatus = item.fs.GetAclStatus(item.path);
                IList <AclEntry> entries   = perm.GetAclBit() ? aclStatus.GetEntries() : Collections
                                             .EmptyList <AclEntry>();
                ScopedAclEntries scopedEntries = new ScopedAclEntries(AclUtil.GetAclFromPermAndEntries
                                                                          (perm, entries));

                PrintAclEntriesForSingleScope(aclStatus, perm, scopedEntries.GetAccessEntries());
                PrintAclEntriesForSingleScope(aclStatus, perm, scopedEntries.GetDefaultEntries());
                @out.WriteLine();
            }