Skip to content
Browse files

Removing dependency on mono on linux. (#1036)

* Removing dependency on mono on linux.

* Should resolve running under .net471.

* Resolving review comments.
  • Loading branch information...
scabana authored and kblok committed Mar 30, 2019
1 parent 055d1f2 commit 9a82a81f600f1e8f3b9431a4be4988ee9e840590
@@ -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
LinuxSysCall.GetFileMode(revisionInfo.ExecutablePath) & BrowserFetcher.BrowserPermissionsInLinux);
UnixFileSystemInfo.GetFileSystemEntry(revisionInfo.ExecutablePath).FileAccessPermissions & LinuxPermissionsSetter.ExecutableFilePermissions);
Assert.Equal(new[] { 123456 }, browserFetcher.LocalRevisions());
@@ -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 |

/// <summary>
/// Default Chromium revision.
/// </summary>
@@ -210,7 +204,7 @@ public async Task<RevisionInfo> DownloadAsync(int revision)

if (revisionInfo != null && GetCurrentPlatform() == Platform.Linux)
LinuxSysCall.SetPermissions(revisionInfo.ExecutablePath, BrowserPermissionsInLinux);
return revisionInfo;

This file was deleted.

Oops, something went wrong.
@@ -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 |

public static void SetExecutableFilePermissions(string revisionInfoExecutablePath)
var unixFileSystemInfo = UnixFileSystemInfo.GetFileSystemEntry(revisionInfoExecutablePath);

unixFileSystemInfo.FileAccessPermissions = ExecutableFilePermissions;
@@ -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)
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;
@@ -63,6 +63,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.2" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.0.2" />

0 comments on commit 9a82a81

Please sign in to comment.
You can’t perform that action at this time.