Added file permissions preservation when archiving video file
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
f3552f3af1
commit
ed4173f3dc
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "zealot"
|
name = "zealot"
|
||||||
description = "Bit Goblin automated video transcoding service."
|
description = "Bit Goblin automated video transcoding service."
|
||||||
version = "0.2.3"
|
version = "0.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "BSD 2-Clause"
|
license = "BSD 2-Clause"
|
||||||
|
@ -60,7 +60,7 @@ impl Repository {
|
|||||||
match fs::copy(&ingest_file, &archive_file) {
|
match fs::copy(&ingest_file, &archive_file) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Archiving video file {}.", ingest_file.to_str().unwrap());
|
info!("Archiving video file {}.", ingest_file.to_str().unwrap());
|
||||||
copy_file_times(ingest_file.to_str().unwrap(), archive_file.to_str().unwrap());
|
copy_file_metadata(ingest_file.to_str().unwrap(), archive_file.to_str().unwrap());
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Error archiving file {}: {}", ingest_file.to_str().unwrap(), e);
|
error!("Error archiving file {}: {}", ingest_file.to_str().unwrap(), e);
|
||||||
@ -93,13 +93,15 @@ fn create_directory(path: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_file_times(old_file: &str, new_file: &str) {
|
fn copy_file_metadata(old_file: &str, new_file: &str) {
|
||||||
// grab old file metadata
|
// grab old file metadata
|
||||||
let old_metadata = fs::metadata(old_file).unwrap();
|
let old_metadata = fs::metadata(old_file).unwrap();
|
||||||
|
let old_permissions = old_metadata.permissions();
|
||||||
let mtime = FileTime::from_last_modification_time(&old_metadata);
|
let mtime = FileTime::from_last_modification_time(&old_metadata);
|
||||||
let atime = FileTime::from_last_access_time(&old_metadata);
|
let atime = FileTime::from_last_access_time(&old_metadata);
|
||||||
|
|
||||||
// set metadata on the new file
|
// set metadata on the new file
|
||||||
let new_path = Path::new(new_file);
|
let new_path = Path::new(new_file);
|
||||||
|
fs::set_permissions(new_file, old_permissions).expect("Failed to set new file permissions.");
|
||||||
filetime::set_file_times(new_path, atime, mtime).expect("Failed to set atime and mtime.");
|
filetime::set_file_times(new_path, atime, mtime).expect("Failed to set atime and mtime.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user