]> source.dussan.org Git - nextcloud-server.git/commitdiff
better error messages if the users home is not writable during scanning 27538/head
authorRobin Appelman <robin@icewind.nl>
Thu, 17 Jun 2021 11:53:11 +0000 (13:53 +0200)
committerRobin Appelman <robin@icewind.nl>
Wed, 5 Apr 2023 11:21:30 +0000 (13:21 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files/lib/Command/Scan.php
lib/private/Files/Utils/Scanner.php

index 710c76de493511f7fef25c655cb0e13ef474d6f0..a59665c56e94eebd885b5da684d87cee2013a83c 100644 (file)
@@ -162,6 +162,7 @@ class Scan extends Base {
                        }
                } catch (ForbiddenException $e) {
                        $output->writeln("<error>Home storage for user $user not writable or 'files' subdirectory missing</error>");
+                       $output->writeln('  ' . $e->getMessage());
                        $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as');
                } catch (InterruptedException $e) {
                        # exit the function if ctrl-c has been pressed
index dc220bc710d92e71493ea0dac7949690303bb7e9..277ce38175f57b4c90728d4872f995c760e503d7 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>
  *
  */
+
 namespace OC\Files\Utils;
 
 use OC\Files\Cache\Cache;
 use OC\Files\Filesystem;
 use OC\Files\Storage\FailedStorage;
+use OC\Files\Storage\Home;
 use OC\ForbiddenException;
 use OC\Hooks\PublicEmitter;
 use OC\Lock\DBLockingProvider;
@@ -211,13 +213,24 @@ class Scanner extends PublicEmitter {
                        }
 
                        // if the home storage isn't writable then the scanner is run as the wrong user
-                       if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and
-                               (!$storage->isCreatable('') or !$storage->isCreatable('files'))
-                       ) {
-                               if ($storage->is_dir('files')) {
-                                       throw new ForbiddenException();
-                               } else {// if the root exists in neither the cache nor the storage the user isn't setup yet
-                                       break;
+                       if ($storage->instanceOfStorage(Home::class)) {
+                               /** @var Home $storage */
+                               foreach (['', 'files'] as $path) {
+                                       if (!$storage->isCreatable($path)) {
+                                               $fullPath = $storage->getSourcePath($path);
+                                               if (!$storage->is_dir($path) && $storage->getCache()->inCache($path)) {
+                                                       throw new NotFoundException("User folder $fullPath exists in cache but not on disk");
+                                               } elseif ($storage->is_dir($path)) {
+                                                       $ownerUid = fileowner($fullPath);
+                                                       $owner = posix_getpwuid($ownerUid);
+                                                       $owner = $owner['name'] ?? $ownerUid;
+                                                       $permissions = decoct(fileperms($fullPath));
+                                                       throw new ForbiddenException("User folder $fullPath is not writable, folders is owned by $owner and has mode $permissions");
+                                               } else {
+                                                       // if the root exists in neither the cache nor the storage the user isn't setup yet
+                                                       break 2;
+                                               }
+                                       }
                                }
                        }