External samba folders show empty until changed from Nextcloud

Nextcloud version: 24.0.4
Operating system and version: Debian 11
Apache or nginx version: Apache 2.4.38
PHP version: 7.4

The issue you are facing:

I have been using Samba/CIFS volumes mounted as users as external storage for a while and it has worked pretty well. However, in the past few weeks, something broke. Even after a full occ files:scan for a user, when they open certain directories, the contents show as empty. However, there should be several files and subdirectories. No specific error is shown in either Nextcloud’s or Samba’s logs.

When a user creates a new file or directory (anything) in one of these folders and then proceeds to reload the page, all other content appears. So it does not seem to be a permission problem: Nextcloud can access these files through samba, but for some reason does not seem to ‘query’ samba when the directory is opened. It seems to assume the directory is empty, without checking, and only checks when there is an update made from within Nextcloud.

I suspect Nextcloud might be maintaining some sort of cache here for these folders? Perhaps as an effect of a previous botched files:scan execution, the folders are remembered as empty. If I am correct, is there a way I could wipe this cache and force Nextcloud to check what files are in these directories when the users open them?

Yes, that’s right. Please have a look on the available occ options which are described here:

https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#file-operations-label

Thanks. I see that there is an occ files:cleanup, but this only seems to remove orphaned cache entries. After execution, it even showed me 0 orphaned file cache entries deleted. I tried a new occ files:scan anyway afterward, but the behaviour is the same: folders show empty when they should have content.

Is there a way to do whatever files:cleanup does but for every file, forcing the cache to be rebuilt?

You can use the -vvv switches to let occ show what it is doing. More important is, that the access rights to the share are correctly set. By default Nextcloud shows all files in a folder independently if it has bee nscanned or not. By default it scans a folder content on the fly. It might be worth to install the SMB connection test app to see what’s going on.

I tried occ files:cleanup with -vvv as well, no output.

Here is something funny though: against recommendations, after taking a backup, I attempted to delete the rows of oc_filecache. This solved the problem: now all files that should be shown are shown, albeit sometimes a reload of the page is needed. But this is already much better than the behaviour before, when Nextcloud would just not show the contents of a folder when permissions are OK and a full scan has been done for the user.

Unfortunately, I found out that regardless of the very obvious hint in its name, oc_filecache is not actually a cache and you are not supposed to alter its contents manually. But it is also true that purging contents helped with the problem I am facing.

I have the same problem. External Storage, SMB, permissions are correct. Most files, folders show correctly, but one folder had no content displaying in Nextcloud. I created a file in this folder through Nextcloud, then suddenly Nextcloud showed all the folder’s content.

Exactly the same here.

Has anyone found a solution?

After updating my working NC 25.0.4 to 26 today i have the same Problem.
Some Folders are empty.
Is there any Way to re-scan my Folders ?
HELP

Not sure if it helps you, but after every upgrade/update of NC i did a

sudo -u www-data php /var/www/nextcloud/occ files:scan-app-data

That usually helps to avoid such strange folder behaviours.

(action can take a long time !!)

Thanks, i try
:+1:

salve ragazzi, ho lo stesso problema!!! Ho sempre utilizzato Openmediavault per la condivisione locale dei miei file in Windows con il classico protocollo SMB, quindi ho installato Nextcloudpi per accesso da remoto ma alcune cartelle della condivisione SMB risultano vuote. E’ stato facile trovare tutorial per installare e far funzionare il container Nextcloud con Docker e Portainer attraverso Openmediavault, però non è facile trovare aiuto per i problemi!!! Questo problema delle cartelle vuote l’ho già risolto aggiungendo all’utente SMB i diritti di appartenenza al gruppo www-data ma adesso si ripresenta su una altro server dati e non riesco a risolvere e vorrei un aiuto o un consiglio

I still have this problem with Nexcloud 26.0.4
I tried
occ files:cleanup --all
occ files:scan --all -vvv
and the outcome is

+---------+-------+--------+--------------+
| Folders | Files | Errors | Elapsed time |
+---------+-------+--------+--------------+
| 6359    | 62703 | 11     | 00:04:25     |
+---------+-------+--------+--------------+

Same, once I create a file in a “empty” folder the rest of the content shows up as well.

try to delete the Share in NC and create a new one
may this helps ?

I got three times the same issue on NC 25 which shares local folders mounted via NFS.
In my case, nothing happens when I create a new text file in the empty folder. Just synchronized the new file with other NC clients.
Only disconnecting the shared folder and then creating a new local share again I got my old files in the empty directory.

What’s the question of this issue?
Does it depend by use of network protocols: SAMBA or NFS ?