Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect known locations from old and new signature.json as well #522

Merged
merged 2 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}