Skip to content

Commit 8d6981d

Browse files
committed
Ensure executable permissions in Linux and OSX
1 parent 079273d commit 8d6981d

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
1212
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0002" />
1313
<PackageReference Include="PdfSharp" Version="1.50.4845-RC2a" NoWarn="NU1701" />
14+
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
1415
</ItemGroup>
1516
<ItemGroup>
1617
<Folder Include="Issues\" />

lib/PuppeteerSharp.Tests/PuppeteerTests/BrowserFetcherTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Runtime.InteropServices;
34
using System.Threading.Tasks;
45
using Xunit;
56
using Xunit.Abstractions;
@@ -32,6 +33,12 @@ public async Task ShouldDownloadAndExtractLinuxBinary()
3233
revisionInfo = await browserFetcher.DownloadAsync(123456);
3334
Assert.True(revisionInfo.Local);
3435
Assert.Equal("LINUX BINARY\n", File.ReadAllText(revisionInfo.ExecutablePath));
36+
37+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
38+
{
39+
Mono.Unix.Native.Syscall.stat(revisionInfo.ExecutablePath, out var stat);
40+
Assert.Equal(BrowserFetcher.BrowserPermissionsInLinux, stat.st_mode & BrowserFetcher.BrowserPermissionsInLinux);
41+
}
3542
Assert.Equal(new[] { 123456 }, browserFetcher.LocalRevisions());
3643
browserFetcher.Remove(123456);
3744
Assert.Empty(browserFetcher.LocalRevisions());

lib/PuppeteerSharp/BrowserFetcher.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading.Tasks;
99
using System.Net;
1010
using System.IO.Compression;
11+
using Mono.Unix.Native;
1112

1213
namespace PuppeteerSharp
1314
{
@@ -33,6 +34,13 @@ public class BrowserFetcher
3334
{Platform.Win64, "{0}/chromium-browser-snapshots/Win_x64/{1}/chrome-win32.zip"}
3435
};
3536

37+
internal static readonly FilePermissions BrowserPermissionsInLinux =
38+
FilePermissions.S_IRWXU |
39+
FilePermissions.S_IRGRP |
40+
FilePermissions.S_IXGRP |
41+
FilePermissions.S_IROTH |
42+
FilePermissions.S_IXOTH;
43+
3644
/// <summary>
3745
/// Default chromiumg revision.
3846
/// </summary>
@@ -164,7 +172,7 @@ public async Task<RevisionInfo> DownloadAsync(int revision)
164172

165173
if (new DirectoryInfo(folderPath).Exists)
166174
{
167-
return null;
175+
return RevisionInfo(revision);
168176
}
169177

170178
var downloadFolder = new DirectoryInfo(DownloadsFolder);
@@ -195,7 +203,13 @@ public async Task<RevisionInfo> DownloadAsync(int revision)
195203

196204
new FileInfo(zipPath).Delete();
197205

198-
return RevisionInfo(revision);
206+
var revisionInfo = RevisionInfo(revision);
207+
208+
if (revisionInfo != null && (GetCurrentPlatform() == Platform.Linux || GetCurrentPlatform() == Platform.MacOS))
209+
{
210+
Syscall.chmod(revisionInfo.ExecutablePath, BrowserPermissionsInLinux);
211+
}
212+
return revisionInfo;
199213
}
200214

201215
/// <summary>

lib/PuppeteerSharp/PuppeteerSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ Changes
4242
<PackageReference Include="System.Net.Http" Version="4.3.3" />
4343
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.0.2" />
4444
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" />
45+
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
4546
</ItemGroup>
4647
</Project>

0 commit comments

Comments
 (0)