Skip to content

Commit d17924c

Browse files
authored
Merge pull request #664 from nextcloud/backport/625/stable31
[stable31] fix(exAppArchiveFetcher): correct apps_path handling
2 parents 0b5b305 + 6c188b0 commit d17924c

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lib/Fetcher/ExAppArchiveFetcher.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,36 @@ public function installTranslations(string $appId, string $dirTranslations): str
9595
}
9696

9797
public function getExAppFolder(string $appId): ?string {
98-
$appsPaths = $this->config->getSystemValue('apps_paths');
99-
$existingPath = '';
100-
foreach ($appsPaths as $appPath) {
101-
if ($appPath['writable'] && file_exists($appPath['path'] . '/' . $appId)) {
102-
$existingPath = $appPath['path'] . '/' . $appId;
103-
}
104-
}
105-
if (!empty($existingPath)) {
106-
return $existingPath;
107-
}
98+
$appsPaths = $this->config->getSystemValue('apps_paths', []);
10899
foreach ($appsPaths as $appPath) {
109100
if ($appPath['writable']) {
110-
if (mkdir($appPath['path'] . '/' . $appId)) {
111-
return $appPath['path'] . '/' . $appId;
101+
$fullAppPath = $appPath['path'] . '/' . $appId;
102+
if (is_dir($fullAppPath) || mkdir($fullAppPath)) {
103+
return $fullAppPath;
112104
}
113105
}
114106
}
107+
// Fallback to default ExApp folder
108+
$defaultExAppFolder = \OC::$SERVERROOT . '/apps/' . $appId;
109+
if (is_dir($defaultExAppFolder)) {
110+
return $defaultExAppFolder;
111+
}
115112
return null;
116113
}
117114

118115
public function removeExAppFolder(string $appId): void {
119-
foreach ($this->config->getSystemValue('apps_paths', []) as $appPath) {
120-
if ($appPath['writable']) {
121-
if (file_exists($appPath['path'] . '/' . $appId)) {
122-
$this->rmdirr($appPath['path'] . '/' . $appId);
123-
}
116+
$appsPaths = $this->config->getSystemValue('apps_paths', []);
117+
if (empty($appsPaths)) {
118+
// fallback check of default ExApp folder
119+
$defaultExAppFolder = \OC::$SERVERROOT . '/apps/' . $appId;
120+
if (is_dir($defaultExAppFolder)) {
121+
$this->rmdirr($defaultExAppFolder);
122+
}
123+
return;
124+
}
125+
foreach ($appsPaths as $appPath) {
126+
if ($appPath['writable'] && is_dir($appPath['path'] . '/' . $appId)) {
127+
$this->rmdirr($appPath['path'] . '/' . $appId);
124128
}
125129
}
126130
}

0 commit comments

Comments
 (0)