Added file permissions preservation when archiving video file
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2023-03-29 00:40:33 -04:00
parent f3552f3af1
commit ed4173f3dc
2 changed files with 5 additions and 3 deletions

View File

@ -1,7 +1,7 @@
[package]
name = "zealot"
description = "Bit Goblin automated video transcoding service."
version = "0.2.3"
version = "0.2.4"
edition = "2021"
readme = "README.md"
license = "BSD 2-Clause"

View File

@ -60,7 +60,7 @@ impl Repository {
match fs::copy(&ingest_file, &archive_file) {
Ok(_) => {
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) => {
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
let old_metadata = fs::metadata(old_file).unwrap();
let old_permissions = old_metadata.permissions();
let mtime = FileTime::from_last_modification_time(&old_metadata);
let atime = FileTime::from_last_access_time(&old_metadata);
// set metadata on the 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.");
}