@@ -417,6 +417,14 @@ impl<'a> arbitrary::Arbitrary<'a> for FileOptions<'a, ExtendedFileOptions> {
417
417
}
418
418
419
419
impl < T : FileOptionExtension > FileOptions < ' _ , T > {
420
+ pub ( crate ) fn normalize ( & mut self ) {
421
+ if !self . last_modified_time . is_valid ( ) {
422
+ self . last_modified_time = FileOptions :: < T > :: default ( ) . last_modified_time ;
423
+ }
424
+
425
+ * self . permissions . get_or_insert ( 0o644 ) |= ffi:: S_IFREG ;
426
+ }
427
+
420
428
/// Set the compression method for the new file
421
429
///
422
430
/// The default is `CompressionMethod::Deflated` if it is enabled. If not,
@@ -1168,7 +1176,7 @@ impl<W: Write + Seek> ZipWriter<W> {
1168
1176
name : S ,
1169
1177
mut options : FileOptions < T > ,
1170
1178
) -> ZipResult < ( ) > {
1171
- Self :: normalize_options ( & mut options) ;
1179
+ options. normalize ( ) ;
1172
1180
let make_new_self = self . inner . prepare_next_writer (
1173
1181
options. compression_method ,
1174
1182
options. compression_level ,
@@ -1244,16 +1252,6 @@ impl<W: Write + Seek> ZipWriter<W> {
1244
1252
Ok ( ( ) )
1245
1253
}
1246
1254
1247
- fn normalize_options < T : FileOptionExtension > ( options : & mut FileOptions < T > ) {
1248
- if options. permissions . is_none ( ) {
1249
- options. permissions = Some ( 0o644 ) ;
1250
- }
1251
- if !options. last_modified_time . is_valid ( ) {
1252
- options. last_modified_time = FileOptions :: < T > :: default ( ) . last_modified_time ;
1253
- }
1254
- * options. permissions . as_mut ( ) . unwrap ( ) |= ffi:: S_IFREG ;
1255
- }
1256
-
1257
1255
/// Starts a file, taking a Path as argument.
1258
1256
///
1259
1257
/// This function ensures that the '/' path separator is used and normalizes `.` and `..`. It
@@ -1294,17 +1292,7 @@ impl<W: Write + Seek> ZipWriter<W> {
1294
1292
/// }
1295
1293
/// ```
1296
1294
pub fn raw_copy_file_rename < S : ToString > ( & mut self , file : ZipFile , name : S ) -> ZipResult < ( ) > {
1297
- let mut options = SimpleFileOptions :: default ( )
1298
- . large_file ( file. compressed_size ( ) . max ( file. size ( ) ) > spec:: ZIP64_BYTES_THR )
1299
- . last_modified_time (
1300
- file. last_modified ( )
1301
- . unwrap_or_else ( DateTime :: default_for_write) ,
1302
- )
1303
- . compression_method ( file. compression ( ) ) ;
1304
- if let Some ( perms) = file. unix_mode ( ) {
1305
- options = options. unix_permissions ( perms) ;
1306
- }
1307
- Self :: normalize_options ( & mut options) ;
1295
+ let options = file. options ( ) ;
1308
1296
self . raw_copy_file_rename_internal ( file, name, options)
1309
1297
}
1310
1298
@@ -1399,14 +1387,17 @@ impl<W: Write + Seek> ZipWriter<W> {
1399
1387
unix_mode : Option < u32 > ,
1400
1388
) -> ZipResult < ( ) > {
1401
1389
let name = file. name ( ) . to_owned ( ) ;
1402
- let mut options = SimpleFileOptions :: default ( )
1403
- . large_file ( file. compressed_size ( ) . max ( file. size ( ) ) > spec:: ZIP64_BYTES_THR )
1404
- . last_modified_time ( last_modified_time)
1405
- . compression_method ( file. compression ( ) ) ;
1390
+
1391
+ let mut options = file. options ( ) ;
1392
+
1393
+ options = options. last_modified_time ( last_modified_time) ;
1394
+
1406
1395
if let Some ( perms) = unix_mode {
1407
1396
options = options. unix_permissions ( perms) ;
1408
1397
}
1409
- Self :: normalize_options ( & mut options) ;
1398
+
1399
+ options. normalize ( ) ;
1400
+
1410
1401
self . raw_copy_file_rename_internal ( file, name, options)
1411
1402
}
1412
1403
0 commit comments