Skip to content

Commit

Permalink
Merge pull request #522 from owncloud/feature/499
Browse files Browse the repository at this point in the history
Collect known locations from old and new signature.json as well
  • Loading branch information
VicDeo authored Oct 10, 2019
2 parents af50b6d + 8da7d50 commit d203e30
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/Command/ExecuteCoreUpgradeScriptsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,21 @@ protected function execute(InputInterface $input, OutputInterface $output){
return 1;
}

foreach ($locator->getRootDirContent() as $dir){
$rootDirContent = array_unique(
array_merge(
$locator->getRootDirContent(),
$locator->getRootDirItemsFromSignature($oldSourcesDir),
$locator->getRootDirItemsFromSignature($newSourcesDir)
)
);
foreach ($rootDirContent as $dir){
if ($dir === 'updater') {
continue;
}
$this->getApplication()->getLogger()->debug('Replacing ' . $dir);
$fsHelper->tripleMove($oldSourcesDir, $newSourcesDir, $tmpDir, $dir);
}

$fsHelper->copyr($tmpDir . '/config/config.php', $oldSourcesDir . '/config/config.php');

//Get a new shipped apps list
Expand All @@ -145,7 +155,7 @@ protected function execute(InputInterface $input, OutputInterface $output){
$output->writeln('Copying the application ' . $appId);
$fsHelper->copyr($newAppsDir . '/' . $appId, $locator->getOwnCloudRootPath() . '/apps/' . $appId, false);
}

try {
$plain = $this->occRunner->run('upgrade');
$output->writeln($plain);
Expand Down Expand Up @@ -189,20 +199,20 @@ protected function loadVersion($pathToPackage){
*/
protected function loadAllowedPreviousVersions($pathToPackage) {
$canBeUpgradedFrom = $this->loadCanBeUpgradedFrom($pathToPackage);

$firstItem = reset($canBeUpgradedFrom);
if (!is_array($firstItem)){
$canBeUpgradedFrom = [$canBeUpgradedFrom];
}

$allowedVersions = [];
foreach ($canBeUpgradedFrom as $version){
$allowedVersions[] = implode('.', $version);
}

return $allowedVersions;
}

/**
* @param string $pathToPackage
* @return array
Expand Down
40 changes: 39 additions & 1 deletion src/Utils/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Locator {

/**
* absolute path to ownCloud root
* @var string
* @var string
*/
protected $ownCloudRootPath;

Expand Down Expand Up @@ -106,6 +106,7 @@ public function getUpdaterContent(){
'box.json',
'composer.json',
'composer.lock',
'CHANGELOG.md',
'CONTRIBUTING.md',
'COPYING-AGPL',
'index.php',
Expand All @@ -119,6 +120,27 @@ public function getUpdaterContent(){
];
}

/**
* Get all files and directories in the OC root dir using signature.json as a source
*
* @param string $basePath
*
* @return array
*/
public function getRootDirItemsFromSignature($basePath) {
$signature = $this->getSignature($basePath);
$items = [];
if (isset($signature['hashes'])) {
$allItems = array_keys($signature['hashes']);
foreach ($allItems as $k => $v) {
// Get the part of the string before the first slash or entire string if there is no slash
$allItems[$k] = strtok($v, '/');
}
$items = array_unique($allItems);
}
return $items;
}

/**
* Absolute path to core root dir content
* @return array
Expand Down Expand Up @@ -264,4 +286,20 @@ public function getPathToVersionFile(){
return $this->ownCloudRootPath . '/version.php';
}

/**
* @param string $rootPath
*
* @return array|mixed
*/
private function getSignature($rootPath) {
$signature = [];
$signaturePath = $rootPath . '/core/signature.json';
if (is_file($signaturePath)) {
$signature = \json_decode(file_get_contents($signaturePath), true);
if (!is_array($signature)) {
$signature = [];
}
}
return $signature;
}
}

0 comments on commit d203e30

Please sign in to comment.