Skip to content

Commit

Permalink
Fix cache file permission
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Feb 17, 2023
1 parent 9962f12 commit 9a2c542
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
fmt::Display,
fs::Metadata,
io::Error,
os::unix::prelude::PermissionsExt,
path::{Path, PathBuf},
sync::{
atomic::{AtomicU64, AtomicUsize, Ordering::Relaxed},
Expand All @@ -21,7 +22,7 @@ use openssl::sha::Sha1;
use parking_lot::{Mutex, RwLock};
use tempfile::TempPath;
use tokio::{
fs::{copy, create_dir_all, metadata, read_dir, remove_dir_all, remove_file, rename, DirEntry, File},
fs::{copy, create_dir_all, metadata, read_dir, remove_dir_all, remove_file, rename, set_permissions, DirEntry, File},
io::AsyncReadExt,
spawn,
sync::mpsc::UnboundedSender,
Expand Down Expand Up @@ -128,9 +129,15 @@ impl CacheManager {
// Can't cross fs move file, try copy.
if let Err(err) = copy(file_path, &path).await {
error!("Import cache failed: {}", err);
return;
}
}

// Fix permission
if cfg!(unix) {
_ = set_permissions(&path, PermissionsExt::from_mode(0o644)).await;
}

self.mark_recently_accessed(info, false).await;

let total_size = self.total_size.clone();
Expand Down

0 comments on commit 9a2c542

Please sign in to comment.