示例#1
0
        internal static void UnixSetFileAccessExecutable(string path)
        {
            if (!File.Exists(path) || !UnixFileSystemInfo.TryGetFileSystemEntry(path, out UnixFileSystemInfo entry))
            {
                return;
            }

            if (!entry.FileAccessPermissions.HasFlag(FileAccessPermissions.UserExecute))
            {
                entry.FileAccessPermissions = entry.FileAccessPermissions | FileAccessPermissions.UserExecute;
            }
        }
        private bool TryFollowSymbolicLink(ref string path, out bool wasSymLink)
        {
            if (!UnixFileSystemInfo.TryGetFileSystemEntry(path, out var fsentry) || !fsentry.Exists)
            {
                wasSymLink = false;
                return(false);
            }

            if (!fsentry.IsSymbolicLink)
            {
                wasSymLink = false;
                return(true);
            }

            var link = UnixPath.TryReadLink(path);

            if (link == null)
            {
                var errno = Stdlib.GetLastError();
                if (errno != Errno.EINVAL)
                {
                    _logger.Trace("Checking path {0} for symlink returned error {1}, assuming it's not a symlink.", path, errno);
                }

                wasSymLink = true;
                return(false);
            }
            else
            {
                if (UnixPath.IsPathRooted(link))
                {
                    path = link;
                }
                else
                {
                    path = UnixPath.GetDirectoryName(path) + UnixPath.DirectorySeparatorChar + link;
                    path = UnixPath.GetCanonicalPath(path);
                }

                wasSymLink = true;
                return(true);
            }
        }