Skip to content

Commit 978722b

Browse files
committed
better error messages if the users home is not writable during scanning
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 59d0e77 commit 978722b

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

apps/files/lib/Command/Scan.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ protected function scanFiles(string $user, string $path, bool $scanMetadata, Out
162162
}
163163
} catch (ForbiddenException $e) {
164164
$output->writeln("<error>Home storage for user $user not writable or 'files' subdirectory missing</error>");
165+
$output->writeln(' ' . $e->getMessage());
165166
$output->writeln('Make sure you\'re running the scan command only as the user the web server runs as');
166167
} catch (InterruptedException $e) {
167168
# exit the function if ctrl-c has been pressed

lib/private/Files/Utils/Scanner.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
* along with this program. If not, see <http://www.gnu.org/licenses/>
2828
*
2929
*/
30+
3031
namespace OC\Files\Utils;
3132

3233
use OC\Files\Cache\Cache;
3334
use OC\Files\Filesystem;
3435
use OC\Files\Storage\FailedStorage;
36+
use OC\Files\Storage\Home;
3537
use OC\ForbiddenException;
3638
use OC\Hooks\PublicEmitter;
3739
use OC\Lock\DBLockingProvider;
@@ -211,13 +213,23 @@ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECUR
211213
}
212214

213215
// if the home storage isn't writable then the scanner is run as the wrong user
214-
if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and
215-
(!$storage->isCreatable('') or !$storage->isCreatable('files'))
216-
) {
217-
if ($storage->is_dir('files')) {
218-
throw new ForbiddenException();
219-
} else {// if the root exists in neither the cache nor the storage the user isn't setup yet
220-
break;
216+
if ($storage->instanceOfStorage(Home::class)) {
217+
/** @var Home $storage */
218+
foreach (['', 'files'] as $path) {
219+
if (!$storage->isCreatable($path)) {
220+
$fullPath = $storage->getSourcePath($path);
221+
if (!$storage->is_dir($path) && $storage->getCache()->inCache($path)) {
222+
throw new NotFoundException("User folder $fullPath exists in cache but not on disk");
223+
} elseif ($storage->is_dir($path)) {
224+
$ownerUid = fileowner($fullPath);
225+
$owner = posix_getpwuid($ownerUid);
226+
$owner = $owner ? $owner['name'] : $ownerUid;
227+
$permissions = decoct(fileperms($fullPath));
228+
throw new ForbiddenException("User folder $fullPath is not writable, folders is owned by $owner and has mode $permissions");
229+
} else {// if the root exists in neither the cache nor the storage the user isn't setup yet
230+
break 2;
231+
}
232+
}
221233
}
222234
}
223235

0 commit comments

Comments
 (0)