Skip to content

Commit

Permalink
improv. fix files stopped the update badly (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
nivcoo authored Dec 26, 2020
1 parent 308f432 commit f79ae83
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions app/Controller/Component/UpdateComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public function updateCMS($componentUpdated = false)
// We avoid extractTo() method because we need to avoid copying $bypassFiles
$zip = new ZipArchive;
if ($zip->open(ROOT . DS . 'app' . DS . 'tmp' . DS . $this->lastVersion . '.zip') !== true) return false;
$updateFile = [];
for ($i = 0; $i < $zip->numFiles; $i++) {
// Get some infos on file
$filename = $zip->getNameIndex($i);
Expand All @@ -171,17 +172,30 @@ public function updateCMS($componentUpdated = false)
if (!is_dir(ROOT . DS . $dirname)) mkdir(ROOT . DS . $dirname, 0775, true);
// Copy file content if it's a file
if ($stats['size'] > 0) {
// We stop here if the copy fail
// We stop here if the file isn't writable
$path = "zip://" . ROOT . DS . "app" . DS . "tmp" . DS . $this->lastVersion . ".zip#{$this->source['repo']}-{$this->lastVersion}/" . "$filename";
if (!copy($path, ROOT . DS . $filename)) {
$updateFile[$path] = ROOT . DS . $filename;
if (file_exists($updateFile[$path]) && !is_writable($updateFile[$path])) {
$this->errorUpdate = $this->Lang->get('UPDATE__FAILED_FILE', array(
'{FILE}' => ROOT . DS . $filename,
'{FILE}' => $updateFile[$path],
));
$this->log("Failed to copy file from $path to " . ROOT . DS . $filename);
$this->log("The file " . $updateFile[$path] . " is not writable!");
return false;
}
}
}

// We copy the files here
foreach ($updateFile as $key => $v) {
if (!copy($key, $v)) {
$this->errorUpdate = $this->Lang->get('UPDATE__FAILED_FILE', array(
'{FILE}' => $v,
));
$this->log("Failed to copy file from $key to " . $v);
return false;
}
}

$zip->close();

// Remove zip
Expand Down

0 comments on commit f79ae83

Please sign in to comment.