From 72cbecaec29cecc723ce29c87d10048114aeef5b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 18:33:14 +0900 Subject: feat(symfony-filesystem): finish the Filesystem port and trim its API doRemove() renames a directory to a random hidden name before emptying it, and undoes that rename when the final rmdir fails, so a concurrent process cannot recreate the path mid-removal. It also walks one level at a time through FilesystemIterator instead of flattening the whole tree, and lets an inner rmdir failure pass, both as upstream does. copy() keeps the mode fopen($targetFile, 'w') would have left rather than the origin's, symlink() and mirror() call readlink() and getLinkTarget() where upstream does, and a directory iterator that cannot be opened propagates its UnexpectedValueException instead of being swallowed or flattened into an IOException. Error message text is out of scope per docs/known-incompatibilities.md, so the three TODO(phase-c) markers that only tracked wording are gone, along with linkException()'s Windows-only branch. So are the arguments no caller varies -- symlink()'s copyOnWindows, mirror()'s iterator and options, copy()'s overwriteNewerFiles -- which removes the last TODO(phase-c) in the file. New shim functions: readlink, filesystem_iterator, stream_is_local, strrev and SplFileInfo::getLinkTarget. base64_encode takes bytes so random_bytes() can feed it. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-php-shim/src/string.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/shirabe-php-shim/src/string.rs') diff --git a/crates/shirabe-php-shim/src/string.rs b/crates/shirabe-php-shim/src/string.rs index 78688eed..a322e36f 100644 --- a/crates/shirabe-php-shim/src/string.rs +++ b/crates/shirabe-php-shim/src/string.rs @@ -179,6 +179,13 @@ pub fn strrpos(_haystack: &str, _needle: &str) -> Option { _haystack.rfind(_needle) } +// Byte-based, matching PHP: strrev() reverses the bytes, not the characters. +pub fn strrev(s: &str) -> String { + let mut bytes = s.as_bytes().to_vec(); + bytes.reverse(); + String::from_utf8_lossy(&bytes).into_owned() +} + pub fn strtolower(_s: &str) -> String { _s.to_ascii_lowercase() } @@ -485,9 +492,9 @@ pub fn urlencode(s: &str) -> String { out } -pub fn base64_encode(_data: &str) -> String { +pub fn base64_encode(_data: impl AsRef<[u8]>) -> String { const TABLE: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - let bytes = _data.as_bytes(); + let bytes = _data.as_ref(); let mut out = String::with_capacity(bytes.len().div_ceil(3) * 4); for chunk in bytes.chunks(3) { let b1 = chunk.get(1).copied(); -- cgit v1.3.1-4-g156e