mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
Forward-port #978
This commit is contained in:
parent
9903c2294c
commit
c38f174a6b
@ -571,18 +571,30 @@ class ArtifactExtractor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move file or directory to destination.
|
* Move file or directory, handling cross-device scenarios
|
||||||
|
* Uses rename() if possible, falls back to copy+delete for cross-device moves
|
||||||
|
*
|
||||||
|
* @param string $source Source path
|
||||||
|
* @param string $dest Destination path
|
||||||
*/
|
*/
|
||||||
protected function moveFileOrDir(string $source, string $dest): void
|
private static function moveFileOrDir(string $source, string $dest): void
|
||||||
{
|
{
|
||||||
$source = FileSystem::convertPath($source);
|
$source = FileSystem::convertPath($source);
|
||||||
$dest = FileSystem::convertPath($dest);
|
$dest = FileSystem::convertPath($dest);
|
||||||
|
|
||||||
// Try rename first (fast, atomic)
|
// Check if source and dest are on the same device to avoid cross-device rename errors
|
||||||
|
$source_stat = @stat($source);
|
||||||
|
$dest_parent = dirname($dest);
|
||||||
|
$dest_stat = @stat($dest_parent);
|
||||||
|
|
||||||
|
// Only use rename if on same device
|
||||||
|
if ($source_stat !== false && $dest_stat !== false && $source_stat['dev'] === $dest_stat['dev']) {
|
||||||
if (@rename($source, $dest)) {
|
if (@rename($source, $dest)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to copy + delete for cross-device moves or if rename failed
|
||||||
if (is_dir($source)) {
|
if (is_dir($source)) {
|
||||||
FileSystem::copyDir($source, $dest);
|
FileSystem::copyDir($source, $dest);
|
||||||
FileSystem::removeDir($source);
|
FileSystem::removeDir($source);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user