diff options
Diffstat (limited to 'crates/shirabe/src/cache.rs')
| -rw-r--r-- | crates/shirabe/src/cache.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs index 47665d0..a193d0b 100644 --- a/crates/shirabe/src/cache.rs +++ b/crates/shirabe/src/cache.rs @@ -74,7 +74,6 @@ impl Cache { pub fn is_usable(path: &str) -> bool { !Preg::is_match(r"{(^|[\\\\/])(\$null|nul|NUL|/dev/null)([\\\\/]|$)}", path) - .unwrap_or(false) } pub fn is_enabled(&mut self) -> bool { @@ -104,8 +103,7 @@ impl Cache { /// @return string|false pub fn read(&mut self, file: &str) -> Option<String> { if self.is_enabled() { - let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file) - .unwrap_or_default(); + let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file); let full_path = format!("{}{}", self.root, file); if file_exists(&full_path) { self.io @@ -122,8 +120,7 @@ impl Cache { let was_enabled = self.enabled == Some(true); if self.is_enabled() && !self.read_only { - let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file) - .unwrap_or_default(); + let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file); self.io .write_error(&format!("Writing {}{} into cache", self.root, file)); @@ -160,7 +157,7 @@ impl Cache { r"{^file_put_contents\(\): Only ([0-9]+) of ([0-9]+) bytes written}", &e.message, Some(&mut m), - )? { + ) { // Remove partial file. unlink(&temp_file_name); @@ -195,8 +192,7 @@ impl Cache { /// Copy a file into the cache pub fn copy_from(&mut self, file: &str, source: &str) -> bool { if self.is_enabled() && !self.read_only { - let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file) - .unwrap_or_default(); + let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file); let full_path = format!("{}{}", self.root, file); self.filesystem .borrow_mut() @@ -225,8 +221,7 @@ impl Cache { /// Copy a file out of the cache pub fn copy_to(&mut self, file: &str, target: &str) -> Result<bool> { if self.is_enabled() { - let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file) - .unwrap_or_default(); + let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file); let full_path = format!("{}{}", self.root, file); if file_exists(&full_path) { let touch_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { @@ -277,8 +272,7 @@ impl Cache { pub fn remove(&mut self, file: &str) -> bool { if self.is_enabled() && !self.read_only { - let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file) - .unwrap_or_default(); + let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file); let full_path = format!("{}{}", self.root, file); if file_exists(&full_path) { return self @@ -309,8 +303,7 @@ impl Cache { /// @phpstan-return int<0, max>|false pub fn get_age(&mut self, file: &str) -> Option<i64> { if self.is_enabled() { - let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file) - .unwrap_or_default(); + let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file); let full_path = format!("{}{}", self.root, file); if file_exists(&full_path) { if let Some(mtime) = filemtime(&full_path) { @@ -385,8 +378,7 @@ impl Cache { /// @return string|false pub fn sha1(&mut self, file: &str) -> Option<String> { if self.is_enabled() { - let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file) - .unwrap_or_default(); + let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file); let full_path = format!("{}{}", self.root, file); if file_exists(&full_path) { return hash_file("sha1", &full_path); @@ -399,8 +391,7 @@ impl Cache { /// @return string|false pub fn sha256(&mut self, file: &str) -> Option<String> { if self.is_enabled() { - let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file) - .unwrap_or_default(); + let file = Preg::replace(&format!("{{[^{}]}}i", self.allowlist), "-", file); let full_path = format!("{}{}", self.root, file); if file_exists(&full_path) { return hash_file("sha256", &full_path); |
