File tree 1 file changed +23
-8
lines changed
1 file changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -150,21 +150,36 @@ pub fn unzip(
150
150
) ) ;
151
151
create_parent_path_if_not_exists ( out_path. as_path ( ) ) ;
152
152
153
- let mut outfile = File :: create ( & out_path) ?;
154
- io:: copy ( & mut file, & mut outfile) ?;
155
- unzipped_files += 1 ;
156
-
157
- // Set permissions in Unix-like systems
153
+ let mut outfile;
154
+ // permissions must be set while creating the file in Unix-like systems, otherwise the filesystem might
155
+ // report the old permissions for some milliseconds
158
156
#[ cfg( unix) ]
159
157
{
160
- use std:: os:: unix:: fs:: PermissionsExt ;
158
+ use std:: os:: unix:: fs:: OpenOptionsExt ;
161
159
162
160
if single_file. is_some ( ) {
163
- fs:: set_permissions ( & out_path, fs:: Permissions :: from_mode ( 0o755 ) ) ?;
161
+ outfile = fs:: OpenOptions :: new ( )
162
+ . create ( true )
163
+ . write ( true )
164
+ . mode ( 0o755 )
165
+ . open ( & out_path) ?;
164
166
} else if let Some ( mode) = file. unix_mode ( ) {
165
- fs:: set_permissions ( & out_path, fs:: Permissions :: from_mode ( mode) ) . unwrap ( ) ;
167
+ outfile = fs:: OpenOptions :: new ( )
168
+ . create ( true )
169
+ . write ( true )
170
+ . mode ( mode)
171
+ . open ( & out_path) ?;
172
+ } else {
173
+ outfile = File :: create ( & out_path) ?;
166
174
}
167
175
}
176
+ #[ cfg( not( unix) ) ]
177
+ {
178
+ outfile = File :: create ( & out_path) ?;
179
+ }
180
+
181
+ io:: copy ( & mut file, & mut outfile) ?;
182
+ unzipped_files += 1 ;
168
183
}
169
184
}
170
185
if unzipped_files == 0 || ( single_file. is_some ( ) && unzipped_files != 1 ) {
You can’t perform that action at this time.
0 commit comments