Exemplo n.º 1
0
            /// <summary>Construct a list of StatusPair objects</summary>
            /// <param name="fs">The FileSystem where 'path' lives</param>
            /// <param name="path">The directory to query</param>
            /// <param name="filter">A possible filter for entries in the directory</param>
            /// <exception cref="System.IO.IOException"/>
            public StatusPairs(FileSystem fs, Path path, PathFilter filter)
            {
                /* Grab all the file statuses at once in an array */
                FileStatus[] fileStatuses = fs.ListStatus(path, filter);
                /* We'll have an array of StatusPairs of the same length */
                AclStatus aclStatus = null;

                statusPairs = new FSOperations.StatusPair[fileStatuses.Length];

                /*
                 * For each FileStatus, attempt to acquire an AclStatus.  If the
                 * getAclStatus throws an exception, we assume that ACLs are turned
                 * off entirely and abandon the attempt.
                 */
                bool useAcls = true;

                // Assume ACLs work until proven otherwise
                for (int i = 0; i < fileStatuses.Length; i++)
                {
                    if (useAcls)
                    {
                        try
                        {
                            aclStatus = fs.GetAclStatus(fileStatuses[i].GetPath());
                        }
                        catch (AclException)
                        {
                            /* Almost certainly due to an "ACLs not enabled" exception */
                            aclStatus = null;
                            useAcls   = false;
                        }
                        catch (NotSupportedException)
                        {
                            /* Ditto above - this is the case for a local file system */
                            aclStatus = null;
                            useAcls   = false;
                        }
                    }
                    statusPairs[i] = new FSOperations.StatusPair(fileStatuses[i], aclStatus);
                }
            }
Exemplo n.º 2
0
 /// <summary>
 /// Executes the filesystem getFileStatus operation and returns the
 /// result in a JSONish Map.
 /// </summary>
 /// <param name="fs">filesystem instance to use.</param>
 /// <returns>a Map object (JSON friendly) with the file status.</returns>
 /// <exception cref="System.IO.IOException">thrown if an IO error occurred.</exception>
 public virtual IDictionary Execute(FileSystem fs)
 {
     FSOperations.StatusPair sp = new FSOperations.StatusPair(fs, path);
     return(sp.ToJson());
 }