diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-19 21:46:01 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-19 21:46:08 +0900 |
| commit | 5e31fa33c3b5cf726a57a063b8e7a070869250fe (patch) | |
| tree | 98522466966fa7df483cad174ab5fc03db39bc09 /crates/shirabe/src/cache.rs | |
| parent | c839244d8d09f3036ebfee8eef7eb6b147e593ab (diff) | |
| download | php-shirabe-5e31fa33c3b5cf726a57a063b8e7a070869250fe.tar.gz php-shirabe-5e31fa33c3b5cf726a57a063b8e7a070869250fe.tar.zst php-shirabe-5e31fa33c3b5cf726a57a063b8e7a070869250fe.zip | |
fix(compile): fix more random compile errors
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/cache.rs')
| -rw-r--r-- | crates/shirabe/src/cache.rs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs index d7b0b7e..848ee80 100644 --- a/crates/shirabe/src/cache.rs +++ b/crates/shirabe/src/cache.rs @@ -23,7 +23,7 @@ pub struct Cache { root: String, enabled: Option<bool>, allowlist: String, - filesystem: Filesystem, + filesystem: std::rc::Rc<std::cell::RefCell<Filesystem>>, read_only: bool, } @@ -39,12 +39,13 @@ impl Cache { io: Box<dyn IOInterface>, cache_dir: &str, allowlist: Option<&str>, - filesystem: Option<Filesystem>, + filesystem: Option<std::rc::Rc<std::cell::RefCell<Filesystem>>>, read_only: bool, ) -> Self { let allowlist = allowlist.unwrap_or("a-z0-9._").to_string(); let root = format!("{}/", cache_dir.trim_end_matches(|c| c == '/' || c == '\\')); - let filesystem = filesystem.unwrap_or_else(|| Filesystem::new(None)); + let filesystem = filesystem + .unwrap_or_else(|| std::rc::Rc::new(std::cell::RefCell::new(Filesystem::new(None)))); let mut this = Self { io, root, @@ -152,6 +153,7 @@ impl Cache { .unwrap_or_default(); let full_path = format!("{}{}", self.root, file); self.filesystem + .borrow_mut() .ensure_directory_exists(&dirname(&full_path)); if !file_exists(source) { @@ -164,7 +166,11 @@ impl Cache { .write_error(&format!("Writing {} into cache from {}", full_path, source)); } - return self.filesystem.copy(source, &full_path).unwrap_or(false); + return self + .filesystem + .borrow_mut() + .copy(source, &full_path) + .unwrap_or(false); } false @@ -197,7 +203,7 @@ impl Cache { self.io .write_error(&format!("Reading {} from cache", full_path)); - return self.filesystem.copy(&full_path, target); + return self.filesystem.borrow_mut().copy(&full_path, target); } } @@ -228,7 +234,11 @@ impl Cache { .unwrap_or_default(); let full_path = format!("{}{}", self.root, file); if file_exists(&full_path) { - return self.filesystem.unlink(&full_path).unwrap_or(false); + return self + .filesystem + .borrow_mut() + .unlink(&full_path) + .unwrap_or(false); } } @@ -237,7 +247,10 @@ impl Cache { pub fn clear(&mut self) -> bool { if self.is_enabled() && !self.read_only { - let _ = self.filesystem.empty_directory(&self.root, true); + let _ = self + .filesystem + .borrow_mut() + .empty_directory(&self.root, true); return true; } @@ -271,16 +284,16 @@ impl Cache { let mut finder = self.get_finder(); finder.date(&format!("until {}", expire.format("%Y-%m-%d %H:%M:%S"))); for file in &mut finder { - let _ = self.filesystem.unlink(&file.get_pathname()); + let _ = self.filesystem.borrow_mut().unlink(&file.get_pathname()); } - let mut total_size = self.filesystem.size(&self.root).unwrap_or(0); + let mut total_size = self.filesystem.borrow_mut().size(&self.root).unwrap_or(0); if total_size > max_size { let mut iterator = self.get_finder().sort_by_accessed_time().get_iterator(); while total_size > max_size && iterator.valid() { let filepath = iterator.current().get_pathname(); - total_size -= self.filesystem.size(&filepath).unwrap_or(0); - let _ = self.filesystem.unlink(&filepath); + total_size -= self.filesystem.borrow_mut().size(&filepath).unwrap_or(0); + let _ = self.filesystem.borrow_mut().unlink(&filepath); iterator.next(); } } @@ -305,7 +318,10 @@ impl Cache { .depth(0) .date(&format!("until {}", expire.format("%Y-%m-%d %H:%M:%S"))); for file in &mut finder { - let _ = self.filesystem.remove_directory(&file.get_pathname()); + let _ = self + .filesystem + .borrow_mut() + .remove_directory(&file.get_pathname()); } *CACHE_COLLECTED.lock().unwrap() = Some(true); |
