diff --git a/lib/PuppeteerSharp.Tests/PuppeteerTests/BrowserFetcherTests.cs b/lib/PuppeteerSharp.Tests/PuppeteerTests/BrowserFetcherTests.cs
index 9957eb9cb..7176542ec 100644
--- a/lib/PuppeteerSharp.Tests/PuppeteerTests/BrowserFetcherTests.cs
+++ b/lib/PuppeteerSharp.Tests/PuppeteerTests/BrowserFetcherTests.cs
@@ -2,9 +2,10 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
-using PuppeteerSharp.Helpers.Linux;
+using Mono.Unix;
using Xunit;
using Xunit.Abstractions;
+using PuppeteerSharp.Helpers.Linux;
namespace PuppeteerSharp.Tests.PuppeteerTests
{
@@ -44,9 +45,11 @@ public async Task ShouldDownloadAndExtractLinuxBinary()
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
+#if NETCOREAPP //don't need to run this code if we're not netcore app since net471 won't run on NIX. And UnixFileSystemInfo is not available for net471
Assert.Equal(
- BrowserFetcher.BrowserPermissionsInLinux,
- LinuxSysCall.GetFileMode(revisionInfo.ExecutablePath) & BrowserFetcher.BrowserPermissionsInLinux);
+ LinuxPermissionsSetter.ExecutableFilePermissions,
+ UnixFileSystemInfo.GetFileSystemEntry(revisionInfo.ExecutablePath).FileAccessPermissions & LinuxPermissionsSetter.ExecutableFilePermissions);
+#endif
}
Assert.Equal(new[] { 123456 }, browserFetcher.LocalRevisions());
browserFetcher.Remove(123456);
diff --git a/lib/PuppeteerSharp/BrowserFetcher.cs b/lib/PuppeteerSharp/BrowserFetcher.cs
index b7e6345bd..e5d0b8162 100755
--- a/lib/PuppeteerSharp/BrowserFetcher.cs
+++ b/lib/PuppeteerSharp/BrowserFetcher.cs
@@ -1,13 +1,14 @@
using System;
-using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
-using System.Net;
-using System.IO.Compression;
+using Mono.Unix;
using PuppeteerSharp.Helpers.Linux;
namespace PuppeteerSharp
@@ -34,13 +35,6 @@ public class BrowserFetcher
{Platform.Win64, "{0}/chromium-browser-snapshots/Win_x64/{1}/{2}.zip"}
};
- internal static readonly FilePermissions BrowserPermissionsInLinux =
- FilePermissions.S_IRWXU |
- FilePermissions.S_IRGRP |
- FilePermissions.S_IXGRP |
- FilePermissions.S_IROTH |
- FilePermissions.S_IXOTH;
-
///
/// Default Chromium revision.
///
@@ -210,7 +204,7 @@ public async Task DownloadAsync(int revision)
if (revisionInfo != null && GetCurrentPlatform() == Platform.Linux)
{
- LinuxSysCall.SetPermissions(revisionInfo.ExecutablePath, BrowserPermissionsInLinux);
+ LinuxPermissionsSetter.SetExecutableFilePermissions(revisionInfo.ExecutablePath);
}
return revisionInfo;
}
diff --git a/lib/PuppeteerSharp/Helpers/Linux/FilePermissions.cs b/lib/PuppeteerSharp/Helpers/Linux/FilePermissions.cs
deleted file mode 100644
index 09ad59dd5..000000000
--- a/lib/PuppeteerSharp/Helpers/Linux/FilePermissions.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-namespace PuppeteerSharp.Helpers.Linux
-{
- [Flags]
- internal enum FilePermissions : uint
- {
- S_ISUID = 0x0800, // Set user ID on execution
- S_ISGID = 0x0400, // Set group ID on execution
- S_ISVTX = 0x0200, // Save swapped text after use (sticky).
- S_IRUSR = 0x0100, // Read by owner
- S_IWUSR = 0x0080, // Write by owner
- S_IXUSR = 0x0040, // Execute by owner
- S_IRGRP = 0x0020, // Read by group
- S_IWGRP = 0x0010, // Write by group
- S_IXGRP = 0x0008, // Execute by group
- S_IROTH = 0x0004, // Read by other
- S_IWOTH = 0x0002, // Write by other
- S_IXOTH = 0x0001, // Execute by other
-
- S_IRWXG = (S_IRGRP | S_IWGRP | S_IXGRP),
- S_IRWXU = (S_IRUSR | S_IWUSR | S_IXUSR),
- S_IRWXO = (S_IROTH | S_IWOTH | S_IXOTH),
- ACCESSPERMS = (S_IRWXU | S_IRWXG | S_IRWXO), // 0777
- ALLPERMS = (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO), // 07777
- DEFFILEMODE = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH), // 0666
- }
-}
\ No newline at end of file
diff --git a/lib/PuppeteerSharp/Helpers/Linux/LinuxPermissionsSetter.cs b/lib/PuppeteerSharp/Helpers/Linux/LinuxPermissionsSetter.cs
new file mode 100644
index 000000000..5b5ce42d6
--- /dev/null
+++ b/lib/PuppeteerSharp/Helpers/Linux/LinuxPermissionsSetter.cs
@@ -0,0 +1,21 @@
+using Mono.Unix;
+
+namespace PuppeteerSharp.Helpers.Linux
+{
+ internal static class LinuxPermissionsSetter
+ {
+ internal static readonly FileAccessPermissions ExecutableFilePermissions =
+ FileAccessPermissions.UserRead | FileAccessPermissions.UserWrite | FileAccessPermissions.UserExecute |
+ FileAccessPermissions.GroupRead |
+ FileAccessPermissions.GroupExecute |
+ FileAccessPermissions.OtherRead |
+ FileAccessPermissions.OtherExecute;
+
+ public static void SetExecutableFilePermissions(string revisionInfoExecutablePath)
+ {
+ var unixFileSystemInfo = UnixFileSystemInfo.GetFileSystemEntry(revisionInfoExecutablePath);
+
+ unixFileSystemInfo.FileAccessPermissions = ExecutableFilePermissions;
+ }
+ }
+}
diff --git a/lib/PuppeteerSharp/Helpers/Linux/LinuxSysCall.cs b/lib/PuppeteerSharp/Helpers/Linux/LinuxSysCall.cs
index 772226fa2..6a42df478 100644
--- a/lib/PuppeteerSharp/Helpers/Linux/LinuxSysCall.cs
+++ b/lib/PuppeteerSharp/Helpers/Linux/LinuxSysCall.cs
@@ -7,54 +7,5 @@ internal static class LinuxSysCall
{
[DllImport("libc", SetLastError = true, EntryPoint = "chmod")]
internal static extern int Chmod(string path, uint mode);
-
- [DllImport("MonoPosixHelper", EntryPoint = "Mono_Posix_FromFilePermissions")]
- internal static extern int FromFilePermissions(FilePermissions value, out uint rval);
-
- [DllImport("MonoPosixHelper", EntryPoint = "helper_Mono_Posix_Stat")]
- internal extern static int GetStats(
- string filename,
- bool dereference,
- out int device,
- out int inode,
- out int mode,
- out int nlinks,
- out int uid,
- out int gid,
- out int rdev,
- out long size,
- out long blksize,
- out long blocks,
- out long atime,
- out long mtime,
- out long ctime);
-
- internal static void SetPermissions(string path, FilePermissions filePermissions)
- {
- FromFilePermissions(filePermissions, out var permissions);
- Chmod(path, permissions);
- }
-
- internal static FilePermissions GetFileMode(string filename)
- {
- GetStats(
- filename,
- false,
- out var device,
- out var inode,
- out var mode,
- out var nlinks,
- out var uid,
- out var gid,
- out var rdev,
- out var size,
- out var blksize,
- out var blocks,
- out var atime,
- out var mtime,
- out var ctime);
-
- return (FilePermissions)mode;
- }
}
}
\ No newline at end of file
diff --git a/lib/PuppeteerSharp/PuppeteerSharp.csproj b/lib/PuppeteerSharp/PuppeteerSharp.csproj
index 70c9cbef0..0c6659b8a 100644
--- a/lib/PuppeteerSharp/PuppeteerSharp.csproj
+++ b/lib/PuppeteerSharp/PuppeteerSharp.csproj
@@ -68,6 +68,7 @@
+