/// <inheritdoc />
        public bool HasWritableAccessControl(string path)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(path));

            int result = s_fileSystem.GetFilePermission(path, false, true);

            FilePermissions permissions = checked ((FilePermissions)result);

            return(permissions.HasFlag(FilePermissions.S_IWUSR) ||
                   permissions.HasFlag(FilePermissions.S_IWGRP) ||
                   permissions.HasFlag(FilePermissions.S_IWOTH));
        }
示例#2
0
        /// <inheritdoc />
        public bool HasWritableAccessControl(string path)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(path));

            int result = GetFilePermissionsForFilePath(path);

            if (result < 0)
            {
                throw new BuildXLException(I($"Failed to get permissions for file '{path}' - error: {Marshal.GetLastWin32Error()}"));
            }

            FilePermissions permissions = checked ((FilePermissions)result);

            return(permissions.HasFlag(FilePermissions.S_IWUSR) ||
                   permissions.HasFlag(FilePermissions.S_IWGRP) ||
                   permissions.HasFlag(FilePermissions.S_IWOTH));
        }
示例#3
0
        public static StoragePermissions GetOtherPermissions(FilePermissions filePermissions)
        {
            var p = StoragePermissions.None;

            if (filePermissions.HasFlag(FilePermissions.S_IROTH))
            {
                p |= StoragePermissions.Read;
            }
            if (filePermissions.HasFlag(FilePermissions.S_IWOTH))
            {
                p |= StoragePermissions.Write;
            }
            if (filePermissions.HasFlag(FilePermissions.S_IXOTH))
            {
                p |= StoragePermissions.Execute;
            }
            return(p);
        }
示例#4
0
        public static StoragePermissions GetGroupPermissions(FilePermissions filePermissions)
        {
            var p = StoragePermissions.None;

            if (filePermissions.HasFlag(FilePermissions.S_IRGRP))
            {
                p |= StoragePermissions.Read;
            }
            if (filePermissions.HasFlag(FilePermissions.S_IWGRP))
            {
                p |= StoragePermissions.Write;
            }
            if (filePermissions.HasFlag(FilePermissions.S_IXGRP))
            {
                p |= StoragePermissions.Execute;
            }
            return(p);
        }
示例#5
0
        private static bool IsSymlink(string path)
        {
            var mode = TryGetFilePermission(path, followSymlink: false, throwOnFailure: false);

            if (mode < 0)
            {
                return(false);
            }

            FilePermissions permissions = checked ((FilePermissions)mode);

            return(permissions.HasFlag(FilePermissions.S_IFLNK));
        }
示例#6
0
        /// <inheritdoc />
        public Possible <PathExistence, NativeFailure> TryProbePathExistence(string path, bool followSymlink)
        {
            var mode = GetFilePermission(path, followSymlink: false, throwOnFailure: false);

            if (mode < 0)
            {
                return(PathExistence.Nonexistent);
            }

            if (followSymlink)
            {
                return(Directory.Exists(path)
                    ? PathExistence.ExistsAsDirectory
                    : PathExistence.ExistsAsFile);
            }
            else
            {
                FilePermissions permissions = checked ((FilePermissions)mode);
                return
                    (permissions.HasFlag(FilePermissions.S_IFDIR) ? PathExistence.ExistsAsDirectory :
                     permissions.HasFlag(FilePermissions.S_IFLNK) ? PathExistence.ExistsAsFile :
                     PathExistence.ExistsAsFile);
            }
        }
示例#7
0
        static UnixExternalPermissions MapToUnixExternalPermissions(FilePermissions fp)
        {
            UnixExternalPermissions filePermissions = 0;

            if (fp.HasFlag(FilePermissions.S_ISUID))
            {
                filePermissions |= UnixExternalPermissions.ISUID;
            }

            if (fp.HasFlag(FilePermissions.S_ISGID))
            {
                filePermissions |= UnixExternalPermissions.ISGID;
            }

            if (fp.HasFlag(FilePermissions.S_ISVTX))
            {
                filePermissions |= UnixExternalPermissions.ISVTX;
            }

            if (fp.HasFlag(FilePermissions.S_IRUSR))
            {
                filePermissions |= UnixExternalPermissions.IRUSR;
            }

            if (fp.HasFlag(FilePermissions.S_IWUSR))
            {
                filePermissions |= UnixExternalPermissions.IWUSR;
            }

            if (fp.HasFlag(FilePermissions.S_IXUSR))
            {
                filePermissions |= UnixExternalPermissions.IXUSR;
            }

            if (fp.HasFlag(FilePermissions.S_IRGRP))
            {
                filePermissions |= UnixExternalPermissions.IRGRP;
            }

            if (fp.HasFlag(FilePermissions.S_IWGRP))
            {
                filePermissions |= UnixExternalPermissions.IWGRP;
            }

            if (fp.HasFlag(FilePermissions.S_IXGRP))
            {
                filePermissions |= UnixExternalPermissions.IXGRP;
            }

            if (fp.HasFlag(FilePermissions.S_IROTH))
            {
                filePermissions |= UnixExternalPermissions.IROTH;
            }

            if (fp.HasFlag(FilePermissions.S_IWOTH))
            {
                filePermissions |= UnixExternalPermissions.IWOTH;
            }

            if (fp.HasFlag(FilePermissions.S_IXOTH))
            {
                filePermissions |= UnixExternalPermissions.IXOTH;
            }

            if (filePermissions == 0)
            {
                return((UnixExternalPermissions)FilePermissions.DEFFILEMODE);
            }

            return(filePermissions);
        }