mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
set last modified time during zip compression
This commit is contained in:
parent
e92b538d72
commit
09d390608f
@ -4,6 +4,7 @@
|
|||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
|
fs::File,
|
||||||
io::{self, prelude::*},
|
io::{self, prelude::*},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
@ -12,7 +13,7 @@ use std::{
|
|||||||
|
|
||||||
use filetime::{set_file_mtime, FileTime};
|
use filetime::{set_file_mtime, FileTime};
|
||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
use zip::{self, read::ZipFile, ZipArchive};
|
use zip::{self, read::ZipFile, DateTime, ZipArchive};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::FinalError,
|
error::FinalError,
|
||||||
@ -203,9 +204,12 @@ where
|
|||||||
options
|
options
|
||||||
};
|
};
|
||||||
|
|
||||||
writer.start_file(path.to_str().unwrap().to_owned(), options)?;
|
let mut file = File::open(entry.path())?;
|
||||||
let file_bytes = fs::read(entry.path())?;
|
writer.start_file(
|
||||||
writer.write_all(&file_bytes)?;
|
path.to_str().unwrap(),
|
||||||
|
options.last_modified_time(get_last_modified_time(&file)),
|
||||||
|
)?;
|
||||||
|
io::copy(&mut file, &mut writer)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +237,14 @@ fn display_zip_comment_if_exists(file: &ZipFile) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_last_modified_time(file: &File) -> DateTime {
|
||||||
|
file.metadata()
|
||||||
|
.and_then(|metadata| metadata.modified())
|
||||||
|
.map_err(|_| ())
|
||||||
|
.and_then(|time| DateTime::from_time(time.into()))
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
fn set_last_modified_time(zip_file: &ZipFile, path: &Path) -> crate::Result<()> {
|
fn set_last_modified_time(zip_file: &ZipFile, path: &Path) -> crate::Result<()> {
|
||||||
let modification_time_in_seconds = zip_file
|
let modification_time_in_seconds = zip_file
|
||||||
.last_modified()
|
.last_modified()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user