@@ -293,7 +293,7 @@ protected function doSelectiveExtract(string $name, array $cache_info, array $fi
293293 // Process file mappings
294294 foreach ($ file_map as $ src_pattern => $ dst_path ) {
295295 $ dst_path = $ this ->replacePathVariables ($ dst_path );
296- $ src_full = "{$ temp_path }/ {$ src_pattern }" ;
296+ $ src_full = FileSystem:: convertPath ( "{$ temp_path }/ {$ src_pattern }" ) ;
297297
298298 // Handle glob patterns
299299 if (str_contains ($ src_pattern , '* ' )) {
@@ -460,40 +460,36 @@ protected function extractArchive(string $filename, string $target): void
460460 $ target = FileSystem::convertPath ($ target );
461461 $ filename = FileSystem::convertPath ($ filename );
462462
463- FileSystem::createDir ($ target );
464-
465- if (PHP_OS_FAMILY === 'Windows ' ) {
466- // Use 7za.exe for Windows
467- $ is_txz = str_ends_with ($ filename , '.txz ' ) || str_ends_with ($ filename , '.tar.xz ' );
468- default_shell ()->execute7zExtract ($ filename , $ target , $ is_txz );
469- return ;
470- }
471-
472- // Unix-like systems: determine compression type
473- if (str_ends_with ($ filename , '.tar.gz ' ) || str_ends_with ($ filename , '.tgz ' )) {
474- default_shell ()->executeTarExtract ($ filename , $ target , 'gz ' );
475- } elseif (str_ends_with ($ filename , '.tar.bz2 ' )) {
476- default_shell ()->executeTarExtract ($ filename , $ target , 'bz2 ' );
477- } elseif (str_ends_with ($ filename , '.tar.xz ' ) || str_ends_with ($ filename , '.txz ' )) {
478- default_shell ()->executeTarExtract ($ filename , $ target , 'xz ' );
479- } elseif (str_ends_with ($ filename , '.tar ' )) {
480- default_shell ()->executeTarExtract ($ filename , $ target , 'none ' );
481- } elseif (str_ends_with ($ filename , '.zip ' )) {
482- // Zip requires special handling for strip-components
483- $ this ->unzipWithStrip ($ filename , $ target );
484- } elseif (str_ends_with ($ filename , '.exe ' )) {
485- // exe just copy to target
486- $ dest_file = FileSystem::convertPath ("{$ target }/ " . basename ($ filename ));
487- FileSystem::copy ($ filename , $ dest_file );
488- } else {
489- throw new FileSystemException ("Unknown archive format: {$ filename }" );
490- }
463+ $ extname = FileSystem::extname ($ filename );
464+
465+ if ($ extname !== 'exe ' && !is_dir ($ target )) {
466+ FileSystem::createDir ($ target );
467+ }
468+ match (SystemTarget::getTargetOS ()) {
469+ 'Windows ' => match ($ extname ) {
470+ 'tar ' => default_shell ()->executeTarExtract ($ filename , $ target , 'none ' ),
471+ 'xz ' , 'txz ' , 'gz ' , 'tgz ' , 'bz2 ' => default_shell ()->execute7zExtract ($ filename , $ target ),
472+ 'zip ' => $ this ->unzipWithStrip ($ filename , $ target ),
473+ 'exe ' => $ this ->copyFile ($ filename , $ target ),
474+ default => throw new FileSystemException ("Unknown archive format: {$ filename }" ),
475+ },
476+ 'Linux ' , 'Darwin ' => match ($ extname ) {
477+ 'tar ' => default_shell ()->executeTarExtract ($ filename , $ target , 'none ' ),
478+ 'gz ' , 'tgz ' => default_shell ()->executeTarExtract ($ filename , $ target , 'gz ' ),
479+ 'bz2 ' => default_shell ()->executeTarExtract ($ filename , $ target , 'bz2 ' ),
480+ 'xz ' , 'txz ' => default_shell ()->executeTarExtract ($ filename , $ target , 'xz ' ),
481+ 'zip ' => $ this ->unzipWithStrip ($ filename , $ target ),
482+ 'exe ' => $ this ->copyFile ($ filename , $ target ),
483+ default => throw new FileSystemException ("Unknown archive format: {$ filename }" ),
484+ },
485+ default => throw new SPCInternalException ('Unsupported OS for archive extraction ' )
486+ };
491487 }
492488
493489 /**
494490 * Unzip file with stripping top-level directory.
495491 */
496- protected function unzipWithStrip (string $ zip_file , string $ extract_path ): void
492+ protected function unzipWithStrip (string $ zip_file , string $ extract_path ): bool
497493 {
498494 $ temp_dir = FileSystem::convertPath (sys_get_temp_dir () . '/spc_unzip_ ' . bin2hex (random_bytes (16 )));
499495 $ zip_file = FileSystem::convertPath ($ zip_file );
@@ -572,6 +568,8 @@ protected function unzipWithStrip(string $zip_file, string $extract_path): void
572568
573569 // Clean up temp directory
574570 FileSystem::removeDir ($ temp_dir );
571+
572+ return true ;
575573 }
576574
577575 /**
@@ -585,6 +583,7 @@ protected function replacePathVariables(string $path): string
585583 '{source_path} ' => SOURCE_PATH ,
586584 '{download_path} ' => DOWNLOAD_PATH ,
587585 '{working_dir} ' => WORKING_DIR ,
586+ '{php_sdk_path} ' => getenv ('PHP_SDK_PATH ' ) ?: '' ,
588587 ];
589588 return str_replace (array_keys ($ replacement ), array_values ($ replacement ), $ path );
590589 }
@@ -627,9 +626,9 @@ private static function moveFileOrDir(string $source, string $dest): void
627626 }
628627 }
629628
630- private function copyFile (string $ source_file , string $ target_path ): void
629+ private function copyFile (string $ source_file , string $ target_path ): bool
631630 {
632631 FileSystem::createDir (dirname ($ target_path ));
633- FileSystem::copy (FileSystem::convertPath ($ source_file ), $ target_path );
632+ return FileSystem::copy (FileSystem::convertPath ($ source_file ), $ target_path );
634633 }
635634}
0 commit comments