Skip to content

Commit

Permalink
Delete shipped apps from both old and new version
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jul 7, 2020
1 parent 50bdca3 commit 1ed9c8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
15 changes: 12 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,22 @@ private function recursiveDelete($folder) {
public function deleteOldFiles() {
$this->silentLog('[info] deleteOldFiles()');

$shippedAppsFile = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/core/shipped.json';
$shippedAppsFile = $this->baseDir . '/../core/shipped.json';
if(!file_exists($shippedAppsFile)) {
throw new \Exception('core/shipped.json is not available');
}

$newShippedAppsFile = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/core/shipped.json';
if(!file_exists($newShippedAppsFile)) {
throw new \Exception('core/shipped.json is not available in the new release');
}

// Delete shipped apps
$shippedApps = json_decode(file_get_contents($shippedAppsFile), true);
foreach($shippedApps['shippedApps'] as $app) {
$shippedApps = array_merge(
json_decode(file_get_contents($shippedAppsFile), true)['shippedApps'],
json_decode(file_get_contents($newShippedAppsFile), true)['shippedApps']
);
foreach($shippedApps as $app) {
$this->recursiveDelete($this->baseDir . '/../apps/' . $app);
}

Expand Down
15 changes: 12 additions & 3 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,22 @@ private function recursiveDelete($folder) {
public function deleteOldFiles() {
$this->silentLog('[info] deleteOldFiles()');

$shippedAppsFile = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/core/shipped.json';
$shippedAppsFile = $this->baseDir . '/../core/shipped.json';
if(!file_exists($shippedAppsFile)) {
throw new \Exception('core/shipped.json is not available');
}

$newShippedAppsFile = $this->getDataDirectoryLocation() . '/updater-'.$this->getConfigOption('instanceid') . '/downloads/nextcloud/core/shipped.json';
if(!file_exists($newShippedAppsFile)) {
throw new \Exception('core/shipped.json is not available in the new release');
}

// Delete shipped apps
$shippedApps = json_decode(file_get_contents($shippedAppsFile), true);
foreach($shippedApps['shippedApps'] as $app) {
$shippedApps = array_merge(
json_decode(file_get_contents($shippedAppsFile), true)['shippedApps'],
json_decode(file_get_contents($newShippedAppsFile), true)['shippedApps']
);
foreach($shippedApps as $app) {
$this->recursiveDelete($this->baseDir . '/../apps/' . $app);
}

Expand Down

0 comments on commit 1ed9c8e

Please sign in to comment.