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/stream.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/shirabe-php-shim/src/stream.rs') diff --git a/crates/shirabe-php-shim/src/stream.rs b/crates/shirabe-php-shim/src/stream.rs index daf4c0af..b699b0ae 100644 --- a/crates/shirabe-php-shim/src/stream.rs +++ b/crates/shirabe-php-shim/src/stream.rs @@ -85,6 +85,18 @@ pub fn stream_isatty(stream: PhpResource) -> bool { stream_isatty_resource(&stream) } +/// PHP `stream_is_local()`: true for plain paths and the `file://` wrapper, false for remote +/// wrappers (`http://`, `ftp://`, ...). +/// TODO(phase-c): PHP asks the wrapper registered for the path's scheme whether it is flagged +/// `STREAM_IS_URL`; this classifies by the scheme itself, so a registered custom wrapper claiming to +/// be local (or vice versa) comes out differently than in PHP. +pub fn stream_is_local(path: &str) -> bool { + match crate::parse_url(path, crate::PHP_URL_SCHEME) { + PhpMixed::String(scheme) => scheme.eq_ignore_ascii_case("file"), + _ => true, + } +} + pub fn stream_get_wrappers() -> Vec { // The full registered set depends on compiled-in extensions and runtime // `stream_wrapper_register` calls, which are not modeled. We return the wrappers always -- cgit v1.3.1-4-g156e