Php occ files:scan: Exception during scan: Trying to access array offset on value of type null

Today migrated my nextcloud instance from a lxc VM to a docker container. After migrating upgraded from nextcloud 18.0.4 to 19.0.

now when I scan files, for 1 users I get this errors, the rest of the users scans fine without these error. Any idea how to fix this issue?
Also, when running the same scan in the still existing lxc container, I don’t get this error.

www-data@4b0b4a3f1e81:~/html$ php occ files:scan linda
Starting scan for user 1 out of 1 (linda)
Exception during scan: Trying to access array offset on value of type null
#0 /var/www/html/lib/private/Files/Cache/Scanner.php(418): OCA\Files\Command\Scan->exceptionErrorHandler(8, ‘Trying to acces…’, ‘/var/www/html/l…’, 418, Array)
#1 /var/www/html/lib/private/Files/Cache/Scanner.php(388): OC\Files\Cache\Scanner->handleChildren(‘files/Documents…’, true, 3, 36285, true, 654)
#2 /var/www/html/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren(‘files/Documents…’, true, 3, 36285, true)
#3 /var/www/html/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren(‘files/Documents…’, true, 3, 35157, true)
#4 /var/www/html/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren(‘files/Documents’, true, 3, 35061, true)
#5 /var/www/html/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren(‘files’, true, 3, 35060, true)
#6 /var/www/html/lib/private/Files/Cache/Scanner.php(340): OC\Files\Cache\Scanner->scanChildren(’’, true, 3, 35059, true)
#7 /var/www/html/lib/private/Files/Utils/Scanner.php(260): OC\Files\Cache\Scanner->scan(’’, true, 3)
#8 /var/www/html/apps/files/lib/Command/Scan.php(151): OC\Files\Utils\Scanner->scan(’/linda’, true, NULL)
#9 /var/www/html/apps/files/lib/Command/Scan.php(207): OCA\Files\Command\Scan->scanFiles(‘linda’, ‘/linda’, Object(Symfony\Component\Console\Output\ConsoleOutput), false, true, false)
#10 /var/www/html/3rdparty/symfony/console/Command/Command.php(255): OCA\Files\Command\Scan->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/core/Command/Base.php(169): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/3rdparty/symfony/console/Application.php(1012): OC\Core\Command\Base->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/3rdparty/symfony/console/Application.php(272): Symfony\Component\Console\Application->doRunCommand(Object(OCA\Files\Command\Scan), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/3rdparty/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/lib/private/Console/Application.php(215): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/console.php(100): OC\Console\Application->run()
#17 /var/www/html/occ(11): require_once(’/var/www/html/c…’)
#18 {main}
±--------±------±-------------+
| Folders | Files | Elapsed time |
±--------±------±-------------+
| 46 | 833 | 00:00:00 |
±--------±------±-------------+

Hi, I have the same error running “occ files:scan --all”
my nextcloud instance runs in a jail of FreeNAS-11.3-U3.1, FreeBSD 11.3-RELEASE-p9. It was installed via Plugin and upgraded to 19.0 from Plugin - Update.

root@Nextcloud:~ # occ files:scan --all
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php
Starting scan for user 1 out of 7 (Andrei)
Exception during scan: Trying to access array offset on value of type null
#0 /usr/local/www/nextcloud/lib/private/Files/Storage/Wrapper/PermissionsMask.php(163): OCA\Files\Command\Scan->exceptionErrorHandler()
#1 [internal function]: OC\Files\Storage\Wrapper\PermissionsMask->getDirectoryContent()
#2 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(408): iterator_to_array()
#3 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(388): OC\Files\Cache\Scanner->handleChildren()
#4 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(340): OC\Files\Cache\Scanner->scanChildren()
#5 /usr/local/www/nextcloud/lib/private/Files/Utils/Scanner.php(260): OC\Files\Cache\Scanner->scan()
#6 /usr/local/www/nextcloud/apps-pkg/files/lib/Command/Scan.php(151): OC\Files\Utils\Scanner->scan()
#7 /usr/local/www/nextcloud/apps-pkg/files/lib/Command/Scan.php(207): OCA\Files\Command\Scan->scanFiles()
#8 /usr/local/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\Files\Command\Scan->execute()
#9 /usr/local/www/nextcloud/core/Command/Base.php(169): Symfony\Component\Console\Command\Command->run()
#10 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(1012): OC\Core\Command\Base->run()
#11 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(272): Symfony\Component\Console\Application->doRunCommand()
#12 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun()
#13 /usr/local/www/nextcloud/lib/private/Console/Application.php(215): Symfony\Component\Console\Application->run()
#14 /usr/local/www/nextcloud/console.php(100): OC\Console\Application->run()
#15 /usr/local/www/nextcloud/occ(11): require_once(’/usr/local/www/…’)
#16 {main}
Starting scan for user 2 out of 7 (bunu)
Exception during scan: Trying to access array offset on value of type null
#0 /usr/local/www/nextcloud/lib/private/Files/Storage/Wrapper/PermissionsMask.php(163): OCA\Files\Command\Scan->exceptionErrorHandler()
#1 [internal function]: OC\Files\Storage\Wrapper\PermissionsMask->getDirectoryContent()
#2 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(408): iterator_to_array()
#3 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(388): OC\Files\Cache\Scanner->handleChildren()
#4 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(340): OC\Files\Cache\Scanner->scanChildren()
#5 /usr/local/www/nextcloud/lib/private/Files/Utils/Scanner.php(260): OC\Files\Cache\Scanner->scan()
#6 /usr/local/www/nextcloud/apps-pkg/files/lib/Command/Scan.php(151): OC\Files\Utils\Scanner->scan()
#7 /usr/local/www/nextcloud/apps-pkg/files/lib/Command/Scan.php(207): OCA\Files\Command\Scan->scanFiles()
#8 /usr/local/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\Files\Command\Scan->execute()
#9 /usr/local/www/nextcloud/core/Command/Base.php(169): Symfony\Component\Console\Command\Command->run()
#10 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(1012): OC\Core\Command\Base->run()
#11 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(272): Symfony\Component\Console\Application->doRunCommand()
#12 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun()
#13 /usr/local/www/nextcloud/lib/private/Console/Application.php(215): Symfony\Component\Console\Application->run()
#14 /usr/local/www/nextcloud/console.php(100): OC\Console\Application->run()
#15 /usr/local/www/nextcloud/occ(11): require_once(’/usr/local/www/…’)
#16 {main}
Starting scan for user 3 out of 7 (Florin)
Exception during scan: Trying to access array offset on value of type null
#0 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(418): OCA\Files\Command\Scan->exceptionErrorHandler()
#1 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(388): OC\Files\Cache\Scanner->handleChildren()
#2 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren()
#3 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(340): OC\Files\Cache\Scanner->scanChildren()
#4 /usr/local/www/nextcloud/lib/private/Files/Utils/Scanner.php(260): OC\Files\Cache\Scanner->scan()
#5 /usr/local/www/nextcloud/apps-pkg/files/lib/Command/Scan.php(151): OC\Files\Utils\Scanner->scan()
#6 /usr/local/www/nextcloud/apps-pkg/files/lib/Command/Scan.php(207): OCA\Files\Command\Scan->scanFiles()
#7 /usr/local/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\Files\Command\Scan->execute()
#8 /usr/local/www/nextcloud/core/Command/Base.php(169): Symfony\Component\Console\Command\Command->run()
#9 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(1012): OC\Core\Command\Base->run()
#10 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(272): Symfony\Component\Console\Application->doRunCommand()
#11 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun()
#12 /usr/local/www/nextcloud/lib/private/Console/Application.php(215): Symfony\Component\Console\Application->run()
#13 /usr/local/www/nextcloud/console.php(100): OC\Console\Application->run()
#14 /usr/local/www/nextcloud/occ(11): require_once(’/usr/local/www/…’)
#15 {main}
Starting scan for user 4 out of 7 (Gina)
Exception during scan: Trying to access array offset on value of type null
#0 /usr/local/www/nextcloud/lib/private/Files/Storage/Wrapper/PermissionsMask.php(163): OCA\Files\Command\Scan->exceptionErrorHandler()
#1 [internal function]: OC\Files\Storage\Wrapper\PermissionsMask->getDirectoryContent()
#2 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(408): iterator_to_array()
#3 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(388): OC\Files\Cache\Scanner->handleChildren()
#4 /usr/local/www/nextcloud/lib/private/Files/Cache/Scanner.php(340): OC\Files\Cache\Scanner->scanChildren()
#5 /usr/local/www/nextcloud/lib/private/Files/Utils/Scanner.php(260): OC\Files\Cache\Scanner->scan()
#6 /usr/local/www/nextcloud/apps-pkg/files/lib/Command/Scan.php(151): OC\Files\Utils\Scanner->scan()
#7 /usr/local/www/nextcloud/apps-pkg/files/lib/Command/Scan.php(207): OCA\Files\Command\Scan->scanFiles()
#8 /usr/local/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OCA\Files\Command\Scan->execute()
#9 /usr/local/www/nextcloud/core/Command/Base.php(169): Symfony\Component\Console\Command\Command->run()
#10 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(1012): OC\Core\Command\Base->run()
#11 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(272): Symfony\Component\Console\Application->doRunCommand()
#12 /usr/local/www/nextcloud/3rdparty/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun()
#13 /usr/local/www/nextcloud/lib/private/Console/Application.php(215): Symfony\Component\Console\Application->run()
#14 /usr/local/www/nextcloud/console.php(100): OC\Console\Application->run()
#15 /usr/local/www/nextcloud/occ(11): require_once(’/usr/local/www/…’)
#16 {main}
Starting scan for user 5 out of 7 (gochi)
Starting scan for user 6 out of 7 (Ioana)
Starting scan for user 7 out of 7 (ncadmin)
±--------±------±-------------+
| Folders | Files | Elapsed time |
±--------±------±-------------+
| 101 | 6459 | 00:01:15 |
±--------±------±-------------+

ls -l gives:
~# ls -l /usr/local/www/nextcloud/lib/private/Files/Storage/Wrapper
total 56
-rw-r–r-- 1 root wheel 11242 May 26 11:08 Availability.php
-rw-r–r-- 1 root wheel 14058 May 26 11:08 Encoding.php
-rw-r–r-- 1 root wheel 31636 May 26 11:08 Encryption.php
-rw-r–r-- 1 root wheel 14750 May 26 11:08 Jail.php
-rw-r–r-- 1 root wheel 5513 May 26 11:08 PermissionsMask.php
-rw-r–r-- 1 root wheel 6066 May 26 11:08 Quota.php
-rw-r–r-- 1 root wheel 16234 May 26 11:08 Wrapper.php

can it be because owner is root?

definitively not. I changed PermissionsMask.php to www:www, same error

HI florinstef,

not much support on this forum :wink:

only your reaction until now. Did you manage to solve it already?
just checked the permissions in my data folder, all 770 for www-data user and group.

Anyone who can support on this topic?

1 Like

Hi Donald.
seems to be a bug in php 7.4, not fixed yet. unfortunatlly nothing to do for the moment. :frowning:

So what is the impact of the occ files:scan —all, not working correctly for this user? Will it also impact the other users because the script seems to crash? Can we think of any workaround or temporary fix for this? I don’t want to do a rollback to nextcloud 18 ofcoure, if even possible.

I’m not very sure, still searching, but the error seems to be harmless. even so, i’ll not use files:scan anymore until a new patch is available.
the workarownd recommended in a post i found recently was to downgrade to an older version of php. it sounds stupid to me …

Hi Donald,

I found the problem. After the upgrate to NC 19.0 some folders and files do not have the correct owner. It must be www. They can be found easely if you login to NC with your admin account and access Settings \ Administration \ Overview. In my case there were almost all folders under /usr/local/www/nextcloud/apps-pkg.
Simply change their owner to www then run occ files:scan --all.
You can find here -> https://fahadusman.com/installing-nextcloud-plugin-on-freenas-11-3-u1/ very good tips how to get rid of some other warnings which may apper in the overview page.

At least that worked for my instance.

Good luck! :slight_smile:

Please let me know if you need more detailed info to fix it.

I set the permissions recursively to be sure: docker exec nextcloud chown -R www-data:www-data /var/www/html
No luck unfortunately.

Yeah, i just found the issue in this url: https://github.com/nextcloud/server/issues/15149
there was a file in linda’s folder that was causing the issue. It was not an important file, so after removing it the scan works fine! :smile:
For others running in the same issue:
I ran: docker exec -u www-data -it nextcloud php /var/www/html/occ files:scan -vvv linda
The -vvv makes the file scan verbose so you can see what’s happening. Here it errored out on one specific file.
After removing the file here, it errored out on the same file, but then in the trash folder.
Then removed it here, and the scan went fine after that!.