@@ -14,10 +14,15 @@ public enum LocalState { Idle, Connecting, Connected, Error, Disconnected };
14
14
15
15
public class BrowserStackTunnel : IDisposable
16
16
{
17
- static readonly string binaryName = "BrowserStackLocal.exe" ;
18
- static readonly string downloadURL = "https://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal.exe" ;
17
+ static readonly string binaryName = isDarwin ( ) ? "BrowserStackLocal-darwin-x64" : "BrowserStackLocal.exe" ;
18
+ static readonly string downloadURL = isDarwin ( ) ?
19
+ "https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal-darwin-x64" :
20
+ "https://bstack-local-prod.s3.amazonaws.com/BrowserStackLocal.exe" ;
21
+ static readonly string homepath = isDarwin ( ) ?
22
+ Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) :
23
+ Environment . ExpandEnvironmentVariables ( "%HOMEDRIVE%%HOMEPATH%" ) ;
19
24
public static readonly string [ ] basePaths = new string [ ] {
20
- Path . Combine ( Environment . ExpandEnvironmentVariables ( "%HOMEDRIVE%%HOMEPATH%" ) , ".browserstack" ) ,
25
+ Path . Combine ( homepath , ".browserstack" ) ,
21
26
Directory . GetCurrentDirectory ( ) ,
22
27
Path . GetTempPath ( ) } ;
23
28
@@ -32,6 +37,12 @@ public class BrowserStackTunnel : IDisposable
32
37
33
38
Process process = null ;
34
39
40
+ static Boolean isDarwin ( )
41
+ {
42
+ OperatingSystem os = Environment . OSVersion ;
43
+ return os . Platform . ToString ( ) == "Unix" ;
44
+ }
45
+
35
46
public virtual void addBinaryPath ( string binaryAbsolute )
36
47
{
37
48
if ( binaryAbsolute == null || binaryAbsolute . Trim ( ) . Length == 0 )
@@ -60,11 +71,37 @@ public virtual void fallbackPaths()
60
71
{
61
72
if ( basePathsIndex >= basePaths . Length - 1 )
62
73
{
63
- throw new Exception ( "Binary not found or failed to launch. Make sure that BrowserStackLocal.exe is not already running." ) ;
74
+ throw new Exception ( "Binary not found or failed to launch. Make sure that BrowserStackLocal is not already running." ) ;
64
75
}
65
76
basePathsIndex ++ ;
66
77
binaryAbsolute = Path . Combine ( basePaths [ basePathsIndex ] , binaryName ) ;
67
78
}
79
+
80
+ public void modifyBinaryPermission ( )
81
+ {
82
+ if ( isDarwin ( ) )
83
+ {
84
+ try
85
+ {
86
+ using ( Process proc = Process . Start ( "/bin/bash" , $ "-c \" chmod 0755 { this . binaryAbsolute } \" ") )
87
+ {
88
+ proc . WaitForExit ( ) ;
89
+ }
90
+ }
91
+ catch
92
+ {
93
+ throw new Exception ( "Error in changing permission for file " + this . binaryAbsolute ) ;
94
+ }
95
+ }
96
+ else
97
+ {
98
+ DirectoryInfo dInfo = new DirectoryInfo ( binaryAbsolute ) ;
99
+ DirectorySecurity dSecurity = dInfo . GetAccessControl ( ) ;
100
+ dSecurity . AddAccessRule ( new FileSystemAccessRule ( new SecurityIdentifier ( WellKnownSidType . WorldSid , null ) , FileSystemRights . FullControl , InheritanceFlags . ObjectInherit | InheritanceFlags . ContainerInherit , PropagationFlags . NoPropagateInherit , AccessControlType . Allow ) ) ;
101
+ dInfo . SetAccessControl ( dSecurity ) ;
102
+ }
103
+ }
104
+
68
105
public void downloadBinary ( )
69
106
{
70
107
string binaryDirectory = Path . Combine ( this . binaryAbsolute , ".." ) ;
@@ -82,10 +119,7 @@ public void downloadBinary()
82
119
throw new Exception ( "Error accessing file " + binaryAbsolute ) ;
83
120
}
84
121
85
- DirectoryInfo dInfo = new DirectoryInfo ( binaryAbsolute ) ;
86
- DirectorySecurity dSecurity = dInfo . GetAccessControl ( ) ;
87
- dSecurity . AddAccessRule ( new FileSystemAccessRule ( new SecurityIdentifier ( WellKnownSidType . WorldSid , null ) , FileSystemRights . FullControl , InheritanceFlags . ObjectInherit | InheritanceFlags . ContainerInherit , PropagationFlags . NoPropagateInherit , AccessControlType . Allow ) ) ;
88
- dInfo . SetAccessControl ( dSecurity ) ;
122
+ modifyBinaryPermission ( ) ;
89
123
}
90
124
91
125
public virtual void Run ( string accessKey , string folder , string logFilePath , string processType )
@@ -158,6 +192,7 @@ private void RunProcess(string arguments, string processType)
158
192
else if ( connectionState . ToString ( ) . ToLower ( ) . Equals ( "disconnected" ) )
159
193
{
160
194
SetTunnelState ( LocalState . Disconnected ) ;
195
+ throw new Exception ( "Error while executing BrowserStackLocal " + processType + " " + e . Data ) ;
161
196
}
162
197
else
163
198
{
0 commit comments