aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/cache.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-14 11:24:36 +0900
committernsfisis <nsfisis@gmail.com>2026-06-14 11:28:19 +0900
commit716f44031a39c5e43fb441ecc470db76efc23dd4 (patch)
treee6f4a31e4bf55a0a8efb06d9dd4844c567e7390f /crates/shirabe/src/cache.rs
parentef9118c788c1cbb22ca7721b6a9e40c2bf2fe243 (diff)
downloadphp-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.tar.gz
php-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.tar.zst
php-shirabe-716f44031a39c5e43fb441ecc470db76efc23dd4.zip
refactor(pcre): drop Result from Preg method return types
The Preg methods panic on PCRE failure (per the file header rationale), so their anyhow::Result wrappers never carried an Err. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/cache.rs')
-rw-r--r--crates/shirabe/src/cache.rs27
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);