Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        internal static IList <XAttr> GetXAttrs(FSDirectory fsd, string srcArg, IList <XAttr
                                                                                       > xAttrs)
        {
            string src = srcArg;

            CheckXAttrsConfigFlag(fsd);
            FSPermissionChecker pc = fsd.GetPermissionChecker();
            bool isRawPath         = FSDirectory.IsReservedRawName(src);
            bool getAll            = xAttrs == null || xAttrs.IsEmpty();

            if (!getAll)
            {
                XAttrPermissionFilter.CheckPermissionForApi(pc, xAttrs, isRawPath);
            }
            byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            src = fsd.ResolvePath(pc, src, pathComponents);
            INodesInPath iip = fsd.GetINodesInPath(src, true);

            if (fsd.IsPermissionEnabled())
            {
                fsd.CheckPathAccess(pc, iip, FsAction.Read);
            }
            IList <XAttr> all         = FSDirXAttrOp.GetXAttrs(fsd, src);
            IList <XAttr> filteredAll = XAttrPermissionFilter.FilterXAttrsForApi(pc, all, isRawPath
                                                                                 );

            if (getAll)
            {
                return(filteredAll);
            }
            if (filteredAll == null || filteredAll.IsEmpty())
            {
                return(null);
            }
            IList <XAttr> toGet = Lists.NewArrayListWithCapacity(xAttrs.Count);

            foreach (XAttr xAttr in xAttrs)
            {
                bool foundIt = false;
                foreach (XAttr a in filteredAll)
                {
                    if (xAttr.GetNameSpace() == a.GetNameSpace() && xAttr.GetName().Equals(a.GetName(
                                                                                               )))
                    {
                        toGet.AddItem(a);
                        foundIt = true;
                        break;
                    }
                }
                if (!foundIt)
                {
                    throw new IOException("At least one of the attributes provided was not found.");
                }
            }
            return(toGet);
        }
Exemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        internal static IList <XAttr> ListXAttrs(FSDirectory fsd, string src)
        {
            FSDirXAttrOp.CheckXAttrsConfigFlag(fsd);
            FSPermissionChecker pc = fsd.GetPermissionChecker();
            bool isRawPath         = FSDirectory.IsReservedRawName(src);

            byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src);
            src = fsd.ResolvePath(pc, src, pathComponents);
            INodesInPath iip = fsd.GetINodesInPath(src, true);

            if (fsd.IsPermissionEnabled())
            {
                /* To access xattr names, you need EXECUTE in the owning directory. */
                fsd.CheckParentAccess(pc, iip, FsAction.Execute);
            }
            IList <XAttr> all = FSDirXAttrOp.GetXAttrs(fsd, src);

            return(XAttrPermissionFilter.FilterXAttrsForApi(pc, all, isRawPath));
        }