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

Ignore custom app folders #107

Merged
merged 2 commits into from Aug 8, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion index.php
Expand Up @@ -289,7 +289,7 @@ private function getDataDirectoryLocation() {
* @return array
*/
private function getExpectedElementsList() {
return [
$expected = [
// Generic
'.',
'..',
Expand Down Expand Up @@ -327,6 +327,26 @@ private function getExpectedElementsList() {
'occ',
'db_structure.xml',
];
return array_merge($expected, $this->getAppDirectories());
}

/**
* Returns app directories specified in config.php
*
* @return array
*/
private function getAppDirectories() {
$expected = [];
if($appsPaths = $this->getConfigOption('apps_paths')) {
foreach ($appsPaths as $appsPath) {
$parentDir = realpath($this->baseDir . '/../');
$appDir = basename($appsPath['path']);
if(strpos($appsPath['path'], $parentDir) === 0 && $appDir !== 'apps') {
$expected[] = $appDir;
}
}
}
return $expected;
}

/**
Expand Down Expand Up @@ -873,6 +893,7 @@ public function deleteOldFiles() {
'apps',
'updater',
];
$excludedElements = array_merge($excludedElements, $this->getAppDirectories());
/**
* @var string $path
* @var \SplFileInfo $fileInfo
Expand Down
23 changes: 22 additions & 1 deletion lib/Updater.php
Expand Up @@ -174,7 +174,7 @@ private function getDataDirectoryLocation() {
* @return array
*/
private function getExpectedElementsList() {
return [
$expected = [
// Generic
'.',
'..',
Expand Down Expand Up @@ -212,6 +212,26 @@ private function getExpectedElementsList() {
'occ',
'db_structure.xml',
];
return array_merge($expected, $this->getAppDirectories());
}

/**
* Returns app directories specified in config.php
*
* @return array
*/
private function getAppDirectories() {
$expected = [];
if($appsPaths = $this->getConfigOption('apps_paths')) {
foreach ($appsPaths as $appsPath) {
$parentDir = realpath($this->baseDir . '/../');
$appDir = basename($appsPath['path']);
if(strpos($appsPath['path'], $parentDir) === 0 && $appDir !== 'apps') {
$expected[] = $appDir;
}
}
}
return $expected;
}

/**
Expand Down Expand Up @@ -758,6 +778,7 @@ public function deleteOldFiles() {
'apps',
'updater',
];
$excludedElements = array_merge($excludedElements, $this->getAppDirectories());
/**
* @var string $path
* @var \SplFileInfo $fileInfo
Expand Down
34 changes: 34 additions & 0 deletions tests/features/bootstrap/FeatureContext.php
Expand Up @@ -423,4 +423,38 @@ public function theVersionNumberIsDecreasedInTheConfigPHPToEnforceUpgrade()
$content = preg_replace("!'version'\s*=>\s*'(\d+\.\d+\.\d+)\.\d+!", "'version' => '$1", $content);
file_put_contents($configFile, $content);
}

/**
* @Given there is a folder called :name
*/
public function thereIsAFolderCalled($name)
{
mkdir($this->serverDir . 'nextcloud/' . $name);
}

/**
* @Given there is a config for a secondary apps directory called :name
*/
public function thereIsAConfigForASecondaryAppsDirectoryCalled($name)
{
$configFile = $this->serverDir . 'nextcloud/config/config.php';
$content = file_get_contents($configFile);
$appsPaths = <<<EOF
'apps_paths' => [
[
'path'=> dirname(__DIR__) . '/apps',
'url' => '/apps',
'writable' => true,
],
[
'path'=> dirname(__DIR__) . '/%s',
'url' => '/%s',
'writable' => true,
],
],
EOF;
$appsPaths = sprintf($appsPaths, $name, $name);
$content = preg_replace("!\);!", $appsPaths . ');', $content);
file_put_contents($configFile, $content);
}
}
22 changes: 22 additions & 0 deletions tests/features/cli.feature
Expand Up @@ -69,3 +69,25 @@ Feature: CLI updater
Then the installed version should be 10.0.0
And maintenance mode should be off
And upgrade is not required

Scenario: Update is available and apps2 folder is there and configured - 10.0.0 to 10.0.1
Given the current installed version is 10.0.0
And there is an update to version 10.0.1 available
And there is a folder called "apps2"
And there is a config for a secondary apps directory called "apps2"
When the CLI updater is run successfully
Then the installed version should be 10.0.1
And maintenance mode should be off
And upgrade is not required

Scenario: Update is available and apps2 folder is there and not configured - 10.0.0 to 10.0.1
Given the current installed version is 10.0.0
And there is an update to version 10.0.1 available
And there is a folder called "apps2"
When the CLI updater is run
Then the return code should not be 0
And the output should contain "The following extra files have been found"
And the output should contain "apps2"
And the installed version should be 10.0.0
And maintenance mode should be off
And upgrade is not required