Skip to content

fix(files): report new files as new in the files:scan summary#62024

Open
seenickcode wants to merge 1 commit into
nextcloud:masterfrom
seenickcode:fix/files-scan-new-counter
Open

fix(files): report new files as new in the files:scan summary#62024
seenickcode wants to merge 1 commit into
nextcloud:masterfrom
seenickcode:fix/files-scan-new-counter

Conversation

@seenickcode

@seenickcode seenickcode commented Jul 11, 2026

Copy link
Copy Markdown

Summary

occ files:scan has reported every new file as "Updated" (never "New")
since the summary table was introduced in 292c0e5.

Root cause: the addToCache listener decides between NodeAddedToCache and
FileCacheUpdated by checking if ($fileId), but Cache\Scanner emits
$fileId = -1 for newly inserted entries, which is truthy. As a result,
the NodeAddedToCache branch was unreachable.

What it does

  • Checks for the actual -1 sentinel instead, so newly inserted entries
    dispatch NodeAddedToCache and existing entries dispatch
    FileCacheUpdated
  • Adds a regression test asserting that a first scan dispatches
    NodeAddedToCache and a re-scan of a modified file dispatches
    FileCacheUpdated

How I verified

Setup: Nextcloud master, MariaDB, an S3 (MinIO) external storage mount with
100 files in 35 folders, mounted at /legacy for user demo01.

Before each scan I cleared the mount's rows from the file cache so every
entry the scan finds is guaranteed new:

DELETE FROM oc_filecache WHERE storage = <numeric_id of the mount>;

On master — all 135 entries were just deleted, so all of them are new,
yet the summary reports none:

$ occ files:scan demo01 --path=/demo01/files/legacy
Starting scan for user 1 out of 1 (demo01)
+---------+-------+-----+---------+---------+--------+--------------+
| Folders | Files | New | Updated | Removed | Errors | Elapsed time |
+---------+-------+-----+---------+---------+--------+--------------+
| 35      | 100   | 0   | 135     | 0       | 0      | 00:00:00     |
+---------+-------+-----+---------+---------+--------+--------------+

On this branch — identical steps:

$ occ files:scan demo01 --path=/demo01/files/legacy
Starting scan for user 1 out of 1 (demo01)
+---------+-------+-----+---------+---------+--------+--------------+
| Folders | Files | New | Updated | Removed | Errors | Elapsed time |
+---------+-------+-----+---------+---------+--------+--------------+
| 35      | 100   | 135 | 0       | 0       | 0      | 00:00:00     |
+---------+-------+-----+---------+---------+--------+--------------+

The included regression test also fails against master and passes with the
fix (first scan must dispatch NodeAddedToCache, re-scan of a modified
file must dispatch FileCacheUpdated).

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@seenickcode seenickcode force-pushed the fix/files-scan-new-counter branch from fd27d32 to ae89b55 Compare July 11, 2026 09:02
The addToCache listener decides between NodeAddedToCache and
FileCacheUpdated by checking `if ($fileId)`, but Cache\Scanner emits
$fileId = -1 for newly inserted entries, which is truthy. As a result
the NodeAddedToCache branch was unreachable and `occ files:scan` has
reported every new file as "Updated" (never "New") since the summary
was introduced in 292c0e5.

Check for the actual -1 sentinel instead, and add a regression test
asserting that a first scan dispatches NodeAddedToCache and a re-scan
of a modified file dispatches FileCacheUpdated.

Assisted-by: ClaudeCode:claude-fable-5
Signed-off-by: Nick Manning <nicholas.manning@gmail.com>
@seenickcode seenickcode force-pushed the fix/files-scan-new-counter branch from 956ee9d to 15c006f Compare July 11, 2026 09:22
@seenickcode seenickcode marked this pull request as ready for review July 11, 2026 09:24
@seenickcode seenickcode requested a review from a team as a code owner July 11, 2026 09:24
@seenickcode seenickcode requested review from ArtificialOwl, CarlSchwan, come-nc and icewind1991 and removed request for a team July 11, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant