@@ -383,10 +383,18 @@ protected static string Touch(string parent, string file, string content = null,
383383 string dir = Path . GetDirectoryName ( filePath ) ;
384384 Debug . Assert ( dir != null ) ;
385385
386+ var newFile = ! File . Exists ( filePath ) ;
387+
386388 Directory . CreateDirectory ( dir ) ;
387389
388390 File . WriteAllText ( filePath , content ?? string . Empty , encoding ?? Encoding . ASCII ) ;
389391
392+ //Work around .NET Core 1.x behavior where all newly created files have execute permissions set.
393+ if ( Constants . IsRunningOnUnix && newFile )
394+ {
395+ RemoveExecutePermissions ( filePath , newFile ) ;
396+ }
397+
390398 return filePath ;
391399 }
392400
@@ -398,6 +406,8 @@ protected static string Touch(string parent, string file, Stream stream)
398406 string dir = Path . GetDirectoryName ( filePath ) ;
399407 Debug . Assert ( dir != null ) ;
400408
409+ var newFile = ! File . Exists ( filePath ) ;
410+
401411 Directory . CreateDirectory ( dir ) ;
402412
403413 using ( var fs = File . Open ( filePath , FileMode . Create ) )
@@ -406,9 +416,21 @@ protected static string Touch(string parent, string file, Stream stream)
406416 fs . Flush ( ) ;
407417 }
408418
419+ //Work around .NET Core 1.x behavior where all newly created files have execute permissions set.
420+ if ( Constants . IsRunningOnUnix && newFile )
421+ {
422+ RemoveExecutePermissions ( filePath , newFile ) ;
423+ }
424+
409425 return filePath ;
410426 }
411427
428+ private static void RemoveExecutePermissions ( string filePath , bool newFile )
429+ {
430+ var process = Process . Start ( "chmod" , $ "644 { filePath } ") ;
431+ process . WaitForExit ( ) ;
432+ }
433+
412434 protected string Expected ( string filename )
413435 {
414436 return File . ReadAllText ( Path . Combine ( ResourcesDirectory . FullName , "expected/" + filename ) ) ;
0 commit comments