Skip to content

Commit 406e8cb

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 39f0aa5 commit 406e8cb

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

apps/files/lib/Command/Scan.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ protected function scanFiles($user, $path, OutputInterface $output, $backgroundS
157157
}
158158
} catch (ForbiddenException $e) {
159159
$output->writeln("<error>Home storage for user $user not writable</error>");
160+
$output->writeln(' ' . $e->getMessage());
160161
$output->writeln('Make sure you\'re running the scan command only as the user the web server runs as');
161162
} catch (InterruptedException $e) {
162163
# 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;
@@ -214,13 +216,23 @@ public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECUR
214216
}
215217

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

0 commit comments

Comments
 (0)