From e89e1785e3df047a869c48b91709289a3b145b49 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Jun 2026 14:29:50 +0900 Subject: refactor(archiver): yield PathBuf from ArchivableFilesFinder, drop SplFileInfo Migrate ArchivableFilesFinder off Symfony's SplFileInfo onto Path/PathBuf, resolving the phar_archiver TODO(phase-b) that required a .map() adapter to bridge SplFileInfo -> PathBuf. - ArchivableFilesFinder now yields PathBuf; accept() takes &Path; the exclude closure receives &Path and uses Path::canonicalize / is_symlink. The SplFileInfo -> PathBuf conversion happens once at the symfony get_iterator boundary (get_iterator stays SplFileInfo for cache.rs). - symfony Finder::filter callback changed to FnMut(&Path) (sole caller is the finder). - PharArchiver passes the finder straight into ArchivableFilesFilter, mirroring PHP's new ArchivableFilesFilter($files). - ZipArchiver consumes PathBuf items, computing the relative path via strip_prefix(sources) in place of SplFileInfo::getRelativePathname. Co-Authored-By: Claude Opus 4.8 --- .../shirabe/src/package/archiver/zip_archiver.rs | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'crates/shirabe/src/package/archiver/zip_archiver.rs') diff --git a/crates/shirabe/src/package/archiver/zip_archiver.rs b/crates/shirabe/src/package/archiver/zip_archiver.rs index 79d714b..7d9f126 100644 --- a/crates/shirabe/src/package/archiver/zip_archiver.rs +++ b/crates/shirabe/src/package/archiver/zip_archiver.rs @@ -8,6 +8,7 @@ use indexmap::IndexMap; use shirabe_php_shim::{ PhpMixed, RuntimeException, ZipArchive, class_exists, fileperms, method_exists, pack, realpath, }; +use std::path::PathBuf; #[derive(Debug)] pub struct ZipArchiver; @@ -50,24 +51,34 @@ impl ArchiverInterface for ZipArchiver { if zip.open(&target, ZipArchive::CREATE).is_ok() { let files = ArchivableFilesFinder::new(&sources, excludes, ignore_filters)?; for file in files { - let filepath = file.get_pathname(); - let mut relative_path = file.get_relative_path_name(); + let filepath = file; + let mut relative_path = filepath + .strip_prefix(&sources) + .unwrap_or(filepath.as_path()) + .to_path_buf(); if Platform::is_windows() { - relative_path = shirabe_php_shim::strtr(&relative_path, "\\", "/"); + relative_path = PathBuf::from(shirabe_php_shim::strtr( + &relative_path.to_string_lossy(), + "\\", + "/", + )); } - if file.is_dir() { - zip.add_empty_dir(&relative_path); + if filepath.is_dir() { + zip.add_empty_dir(&relative_path.to_string_lossy()); } else { - zip.add_file(&filepath, &relative_path); + zip.add_file( + &filepath.to_string_lossy(), + &relative_path.to_string_lossy(), + ); } // setExternalAttributesName() is only available with libzip 0.11.2 or above if method_exists(&PhpMixed::Null, "setExternalAttributesName") { - let perms = fileperms(&filepath); + let perms = fileperms(&filepath.to_string_lossy()); zip.set_external_attributes_name( - &relative_path, + &relative_path.to_string_lossy(), ZipArchive::OPSYS_UNIX, perms << 16, ); -- cgit v1.3.1