fixes for permission retention

Signed-off-by: Andy Miller <rhuk@mac.com>
This commit is contained in:
Andy Miller
2025-10-16 15:24:12 -06:00
parent b68872e3fd
commit f10894fe47
2 changed files with 35 additions and 7 deletions

View File

@@ -478,12 +478,22 @@ abstract class Folder
* @return bool
* @throws RuntimeException
*/
public static function rcopy($src, $dest)
public static function rcopy($src, $dest, $preservePermissions = false)
{
// If the src is not a directory do a simple file copy
if (!is_dir($src)) {
copy($src, $dest);
if ($preservePermissions) {
$perm = @fileperms($src);
if ($perm !== false) {
@chmod($dest, $perm & 0777);
}
$mtime = @filemtime($src);
if ($mtime !== false) {
@touch($dest, $mtime);
}
}
return true;
}
@@ -492,14 +502,32 @@ abstract class Folder
static::create($dest);
}
if ($preservePermissions) {
$perm = @fileperms($src);
if ($perm !== false) {
@chmod($dest, $perm & 0777);
}
}
// Open the source directory to read in files
$i = new DirectoryIterator($src);
foreach ($i as $f) {
if ($f->isFile()) {
copy($f->getRealPath(), "{$dest}/" . $f->getFilename());
$target = "{$dest}/" . $f->getFilename();
copy($f->getRealPath(), $target);
if ($preservePermissions) {
$perm = @fileperms($f->getRealPath());
if ($perm !== false) {
@chmod($target, $perm & 0777);
}
$mtime = @filemtime($f->getRealPath());
if ($mtime !== false) {
@touch($target, $mtime);
}
}
} else {
if (!$f->isDot() && $f->isDir()) {
static::rcopy($f->getRealPath(), "{$dest}/{$f}");
static::rcopy($f->getRealPath(), "{$dest}/{$f}", $preservePermissions);
}
}
}

View File

@@ -165,7 +165,7 @@ class SafeUpgradeService
Folder::create($packagePath);
// Copy extracted package into staging area.
Folder::rcopy($extractedPath, $packagePath);
Folder::rcopy($extractedPath, $packagePath, true);
$this->carryOverRootDotfiles($packagePath);
@@ -375,7 +375,7 @@ class SafeUpgradeService
}
Folder::create(dirname($stage));
Folder::rcopy($live, $stage);
Folder::rcopy($live, $stage, true);
}
}
@@ -414,7 +414,7 @@ class SafeUpgradeService
$source = $entry->getPathname();
if ($entry->isDir()) {
Folder::rcopy($source, $target);
Folder::rcopy($source, $target, true);
} elseif ($entry->isFile()) {
Folder::create(dirname($target));
copy($source, $target);
@@ -550,7 +550,7 @@ class SafeUpgradeService
Folder::delete($destinationGit);
}
Folder::rcopy($sourceGit, $destinationGit);
Folder::rcopy($sourceGit, $destinationGit, true);
}
/**