@@ -12,26 +12,21 @@ namespace System.IO.Compression.Tests
12
12
public partial class ZipFile_Unix : ZipFileTestBase
13
13
{
14
14
[ Fact ]
15
- [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/68293" , TestPlatforms . OSX ) ]
16
- [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/60581" , TestPlatforms . iOS | TestPlatforms . tvOS | TestPlatforms . MacCatalyst ) ]
17
15
public void UnixCreateSetsPermissionsInExternalAttributes ( )
18
16
{
19
17
// '7600' tests that S_ISUID, S_ISGID, and S_ISVTX bits get preserved in ExternalAttributes
20
18
string [ ] testPermissions = new [ ] { "777" , "755" , "644" , "600" , "7600" } ;
21
19
22
20
using ( var tempFolder = new TempDirectory ( Path . Combine ( GetTestFilePath ( ) , "testFolder" ) ) )
23
21
{
24
- foreach ( string permission in testPermissions )
25
- {
26
- CreateFile ( tempFolder . Path , permission ) ;
27
- }
22
+ string [ ] expectedPermissions = CreateFiles ( tempFolder . Path , testPermissions ) ;
28
23
29
24
string archivePath = GetTestFilePath ( ) ;
30
25
ZipFile . CreateFromDirectory ( tempFolder . Path , archivePath ) ;
31
26
32
27
using ( ZipArchive archive = ZipFile . OpenRead ( archivePath ) )
33
28
{
34
- Assert . Equal ( 5 , archive . Entries . Count ) ;
29
+ Assert . Equal ( expectedPermissions . Length , archive . Entries . Count ) ;
35
30
36
31
foreach ( ZipArchiveEntry entry in archive . Entries )
37
32
{
@@ -50,7 +45,7 @@ void EnsureExternalAttributes(string permissions, ZipArchiveEntry entry)
50
45
{
51
46
ZipFile . ExtractToDirectory ( archivePath , extractFolder . Path ) ;
52
47
53
- foreach ( string permission in testPermissions )
48
+ foreach ( string permission in expectedPermissions )
54
49
{
55
50
string filename = Path . Combine ( extractFolder . Path , permission + ".txt" ) ;
56
51
Assert . True ( File . Exists ( filename ) ) ;
@@ -96,12 +91,38 @@ public void UnixExtractSetsFilePermissionsFromExternalAttributes()
96
91
}
97
92
}
98
93
99
- private static void CreateFile ( string folderPath , string permissions )
94
+ private static string [ ] CreateFiles ( string folderPath , string [ ] testPermissions )
100
95
{
101
- string filename = Path . Combine ( folderPath , $ "{ permissions } .txt") ;
102
- File . WriteAllText ( filename , "contents" ) ;
96
+ string [ ] expectedPermissions = new string [ testPermissions . Length ] ;
97
+
98
+ for ( int i = 0 ; i < testPermissions . Length ; i ++ )
99
+ {
100
+ string permissions = testPermissions [ i ] ;
101
+ string filename = Path . Combine ( folderPath , $ "{ permissions } .txt") ;
102
+ File . WriteAllText ( filename , "contents" ) ;
103
+
104
+ Assert . Equal ( 0 , Interop . Sys . ChMod ( filename , Convert . ToInt32 ( permissions , 8 ) ) ) ;
105
+
106
+ // In some environments, the file mode may be modified by the OS.
107
+ // See the Rationale section of https://linux.die.net/man/3/chmod.
103
108
104
- Assert . Equal ( 0 , Interop . Sys . ChMod ( filename , Convert . ToInt32 ( permissions , 8 ) ) ) ;
109
+ // To workaround this, read the file mode back, and if it has changed, update the file name
110
+ // since the name is used to compare the file mode.
111
+ Interop . Sys . FileStatus status ;
112
+ Assert . Equal ( 0 , Interop . Sys . Stat ( filename , out status ) ) ;
113
+ string updatedPermissions = Convert . ToString ( status . Mode & 0xFFF , 8 ) ;
114
+ if ( updatedPermissions != permissions )
115
+ {
116
+ string newFileName = Path . Combine ( folderPath , $ "{ updatedPermissions } .txt") ;
117
+ File . Move ( filename , newFileName ) ;
118
+
119
+ permissions = updatedPermissions ;
120
+ }
121
+
122
+ expectedPermissions [ i ] = permissions ;
123
+ }
124
+
125
+ return expectedPermissions ;
105
126
}
106
127
107
128
private static void EnsureFilePermissions ( string filename , string permissions )
0 commit comments