Skip to content

Commit

Permalink
Do not create __apps dir. Fixes #332, Fixes #290
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed May 3, 2016
1 parent f86457f commit 6354962
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
22 changes: 14 additions & 8 deletions src/Command/ExecuteCoreUpgradeScriptsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

namespace Owncloud\Updater\Command;

use Owncloud\Updater\Utils\Checkpoint;
use Owncloud\Updater\Utils\FilesystemHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
Expand Down Expand Up @@ -49,9 +51,12 @@ protected function configure(){

protected function execute(InputInterface $input, OutputInterface $output){
$locator = $this->container['utils.locator'];
/** @var FilesystemHelper $fsHelper */
$fsHelper = $this->container['utils.filesystemhelper'];
$registry = $this->container['utils.registry'];
$fetcher = $this->container['utils.fetcher'];
/** @var Checkpoint $checkpoint */
$checkpoint = $this->container['utils.checkpoint'];

$installedVersion = implode('.', $locator->getInstalledVersion());
$registry->set('installedVersion', $installedVersion);
Expand Down Expand Up @@ -99,22 +104,23 @@ protected function execute(InputInterface $input, OutputInterface $output){
}

try {
$fsHelper->move($oldSourcesDir . '/apps', $oldSourcesDir . '/__apps');
$fsHelper->mkdir($oldSourcesDir . '/apps');
$appDirectories = $fsHelper->scandirFiltered($oldSourcesDir . '/apps');
foreach ($appDirectories as $appDirectory){
$fsHelper->rmdirr($oldSourcesDir . '/apps/' . $appDirectory);
}
$plain = $this->occRunner->run('upgrade');
$fsHelper->removeIfExists($oldSourcesDir . '/apps');
$fsHelper->move($oldSourcesDir . '/__apps', $oldSourcesDir . '/apps');
$output->writeln($plain);
} catch (ProcessFailedException $e){
$fsHelper->removeIfExists($oldSourcesDir . '/apps');
$fsHelper->move($oldSourcesDir . '/__apps', $oldSourcesDir . '/apps');
$lastCheckpointId = $checkpoint->getLastCheckpointId();
if ($lastCheckpointId){
$lastCheckpointPath = $checkpoint->getCheckpointPath($lastCheckpointId);
$fsHelper->copyr($lastCheckpointPath . '/apps', $oldSourcesDir . '/apps', false);
}
if ($e->getProcess()->getExitCode() != 3){
throw ($e);
}
}

}

}

}
13 changes: 11 additions & 2 deletions src/Utils/Checkpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ public function checkpointExists($checkpointId){
return in_array($checkpointId, $this->getAllCheckpointIds());
}

/**
* Get the most recent checkpoint Id
* @return bool
*/
public function getLastCheckpointId(){
$allCheckpointIds = $this->getAllCheckpointIds();
return count($allCheckpointIds) > 0 ? end($allCheckpointIds) : false;
}

/**
* Return array of all checkpoint ids
* @return array
Expand Down Expand Up @@ -182,14 +191,14 @@ protected function createCheckpointId(){
* @param string $checkpointId id of checkpoint
* @return string
*/
protected function getCheckpointPath($checkpointId){
public function getCheckpointPath($checkpointId){
return $this->locator->getCheckpointDir() . '/' . $checkpointId;
}

/**
* Produce an error on non-existing checkpoints
* @param string $checkpointId id of checkpoint
* @throws UnexpectedValueException if there is no checkpoint with this id
* @throws \UnexpectedValueException if there is no checkpoint with this id
*/
private function assertCheckpointExists($checkpointId){
if (!$this->checkpointExists($checkpointId) || $checkpointId === ''){
Expand Down
14 changes: 14 additions & 0 deletions src/Utils/FilesystemHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public function filemtime($path){
return filemtime($path);
}

/**
* Wrapper for scandir function.
* Filters current and parent directories
* @param string $path
* @return array
*/
public function scandirFiltered($path){
$content = $this->scandir($path);
if (is_array($content)){
return array_diff($content, ['.', '..']);
}
return [];
}

/**
* Wrapper for scandir function
* @param string $path
Expand Down

0 comments on commit 6354962

Please sign in to comment.