示例#1
0
        /// <summary>
        /// Creates a new Unix file permissions object parsed from the
        /// permission string.
        /// </summary>
        /// <param name="permissions">
        /// A string of length 10 that holds Unix filesystem permissions data.
        /// </param>
        public UnixFilePermissions(string permissions)
        {
            if (permissions != null && permissions.Length >= 10)
            {
                //Parse file type bit
                switch (permissions[0])
                {
                case '-': FileType = UnixFileTypes.Regular; break;

                case 'd': FileType = UnixFileTypes.Directory; break;

                case 'l': FileType = UnixFileTypes.SymbolicLink; break;

                case 'p': FileType = UnixFileTypes.NamedPipe; break;

                case 's': FileType = UnixFileTypes.DomainSocket; break;

                case 'b': FileType = UnixFileTypes.BlockSpecialFile; break;

                case 'c': FileType = UnixFileTypes.CharacterSpecialFile; break;

                case 'D': FileType = UnixFileTypes.Door; break;

                default: FileType = UnixFileTypes.Unknown; break;
                }

                User  = new Triplet(permissions[1], permissions[2], permissions[3]);
                Group = new Triplet(permissions[4], permissions[5], permissions[6]);
                Other = new Triplet(permissions[7], permissions[8], permissions[9]);
            }
            else
            {
                FileType = UnixFileTypes.Unknown;
                User     = new Triplet();
                Group    = new Triplet();
                Other    = new Triplet();
            }
        }
        /// <summary>
        /// Creates a new Unix file permissions object parsed from the
        /// permission string.
        /// </summary>
        /// <param name="permissions">
        /// A string of length 10 that holds Unix filesystem permissions data.
        /// </param>
        public UnixFilePermissions(string permissions)
        {
            if (permissions != null && permissions.Length >= 10)
            {
                //Parse file type bit
                switch (permissions[0])
                {
                    case '-': FileType = UnixFileTypes.Regular; break;
                    case 'd': FileType = UnixFileTypes.Directory; break;
                    case 'l': FileType = UnixFileTypes.SymbolicLink; break;
                    case 'p': FileType = UnixFileTypes.NamedPipe; break;
                    case 's': FileType = UnixFileTypes.DomainSocket; break;
                    case 'b': FileType = UnixFileTypes.BlockSpecialFile; break;
                    case 'c': FileType = UnixFileTypes.CharacterSpecialFile; break;
                    case 'D': FileType = UnixFileTypes.Door; break;
                    default: FileType = UnixFileTypes.Unknown; break;
                }

                User = new Triplet(permissions[1], permissions[2], permissions[3]);
                Group = new Triplet(permissions[4], permissions[5], permissions[6]);
                Other = new Triplet(permissions[7], permissions[8], permissions[9]);
            }
            else
            {
                FileType = UnixFileTypes.Unknown;
                User = new Triplet();
                Group = new Triplet();
                Other = new Triplet();
            }
        }