File tree Expand file tree Collapse file tree 6 files changed +33
-90
lines changed
PuppeteerSharp.Tests/PuppeteerTests Expand file tree Collapse file tree 6 files changed +33
-90
lines changed Original file line number Diff line number Diff line change 22using System . IO ;
33using System . Runtime . InteropServices ;
44using System . Threading . Tasks ;
5- using PuppeteerSharp . Helpers . Linux ;
5+ using Mono . Unix ;
66using Xunit ;
77using Xunit . Abstractions ;
8+ using PuppeteerSharp . Helpers . Linux ;
89
910namespace PuppeteerSharp . Tests . PuppeteerTests
1011{
@@ -44,9 +45,11 @@ public async Task ShouldDownloadAndExtractLinuxBinary()
4445
4546 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
4647 {
48+ #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
4749 Assert . Equal (
48- BrowserFetcher . BrowserPermissionsInLinux ,
49- LinuxSysCall . GetFileMode ( revisionInfo . ExecutablePath ) & BrowserFetcher . BrowserPermissionsInLinux ) ;
50+ LinuxPermissionsSetter . ExecutableFilePermissions ,
51+ UnixFileSystemInfo . GetFileSystemEntry ( revisionInfo . ExecutablePath ) . FileAccessPermissions & LinuxPermissionsSetter . ExecutableFilePermissions ) ;
52+ #endif
5053 }
5154 Assert . Equal ( new [ ] { 123456 } , browserFetcher . LocalRevisions ( ) ) ;
5255 browserFetcher . Remove ( 123456 ) ;
Original file line number Diff line number Diff line change 11using System ;
2- using System . Linq ;
32using System . Collections . Generic ;
43using System . Diagnostics ;
54using System . IO ;
5+ using System . IO . Compression ;
6+ using System . Linq ;
7+ using System . Net ;
68using System . Net . Http ;
79using System . Runtime . InteropServices ;
810using System . Threading . Tasks ;
9- using System . Net ;
10- using System . IO . Compression ;
11+ using Mono . Unix ;
1112using PuppeteerSharp . Helpers . Linux ;
1213
1314namespace PuppeteerSharp
@@ -34,13 +35,6 @@ public class BrowserFetcher
3435 { Platform . Win64 , "{0}/chromium-browser-snapshots/Win_x64/{1}/{2}.zip" }
3536 } ;
3637
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-
4438 /// <summary>
4539 /// Default Chromium revision.
4640 /// </summary>
@@ -210,7 +204,7 @@ public async Task<RevisionInfo> DownloadAsync(int revision)
210204
211205 if ( revisionInfo != null && GetCurrentPlatform ( ) == Platform . Linux )
212206 {
213- LinuxSysCall . SetPermissions ( revisionInfo . ExecutablePath , BrowserPermissionsInLinux ) ;
207+ LinuxPermissionsSetter . SetExecutableFilePermissions ( revisionInfo . ExecutablePath ) ;
214208 }
215209 return revisionInfo ;
216210 }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ using Mono . Unix ;
2+
3+ namespace PuppeteerSharp . Helpers . Linux
4+ {
5+ internal static class LinuxPermissionsSetter
6+ {
7+ internal static readonly FileAccessPermissions ExecutableFilePermissions =
8+ FileAccessPermissions . UserRead | FileAccessPermissions . UserWrite | FileAccessPermissions . UserExecute |
9+ FileAccessPermissions . GroupRead |
10+ FileAccessPermissions . GroupExecute |
11+ FileAccessPermissions . OtherRead |
12+ FileAccessPermissions . OtherExecute ;
13+
14+ public static void SetExecutableFilePermissions ( string revisionInfoExecutablePath )
15+ {
16+ var unixFileSystemInfo = UnixFileSystemInfo . GetFileSystemEntry ( revisionInfoExecutablePath ) ;
17+
18+ unixFileSystemInfo . FileAccessPermissions = ExecutableFilePermissions ;
19+ }
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -7,54 +7,5 @@ internal static class LinuxSysCall
77 {
88 [ DllImport ( "libc" , SetLastError = true , EntryPoint = "chmod" ) ]
99 internal static extern int Chmod ( string path , uint mode ) ;
10-
11- [ DllImport ( "MonoPosixHelper" , EntryPoint = "Mono_Posix_FromFilePermissions" ) ]
12- internal static extern int FromFilePermissions ( FilePermissions value , out uint rval ) ;
13-
14- [ DllImport ( "MonoPosixHelper" , EntryPoint = "helper_Mono_Posix_Stat" ) ]
15- internal extern static int GetStats (
16- string filename ,
17- bool dereference ,
18- out int device ,
19- out int inode ,
20- out int mode ,
21- out int nlinks ,
22- out int uid ,
23- out int gid ,
24- out int rdev ,
25- out long size ,
26- out long blksize ,
27- out long blocks ,
28- out long atime ,
29- out long mtime ,
30- out long ctime ) ;
31-
32- internal static void SetPermissions ( string path , FilePermissions filePermissions )
33- {
34- FromFilePermissions ( filePermissions , out var permissions ) ;
35- Chmod ( path , permissions ) ;
36- }
37-
38- internal static FilePermissions GetFileMode ( string filename )
39- {
40- GetStats (
41- filename ,
42- false ,
43- out var device ,
44- out var inode ,
45- out var mode ,
46- out var nlinks ,
47- out var uid ,
48- out var gid ,
49- out var rdev ,
50- out var size ,
51- out var blksize ,
52- out var blocks ,
53- out var atime ,
54- out var mtime ,
55- out var ctime ) ;
56-
57- return ( FilePermissions ) mode ;
58- }
5910 }
6011}
Original file line number Diff line number Diff line change 6363 </PropertyGroup >
6464 <ItemGroup >
6565 <PackageReference Include =" Microsoft.Extensions.Logging" Version =" 2.0.2" />
66+ <PackageReference Include =" Mono.Posix.NETStandard" Version =" 1.0.0" />
6667 <PackageReference Include =" Newtonsoft.Json" Version =" 10.0.3" />
6768 <PackageReference Include =" System.Net.Http" Version =" 4.3.3" />
6869 <PackageReference Include =" Microsoft.AspNetCore.WebUtilities" Version =" 2.0.2" />
You can’t perform that action at this time.
0 commit comments