Skip to content

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

Open
seenickcode wants to merge 2 commits 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 2 commits 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 2 times, most recently 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
@susnux susnux added the community pull requests from community label Jul 14, 2026
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 15c006f to 68c4740 Compare July 15, 2026 14:07
Comment thread lib/private/Files/Utils/Scanner.php Outdated
SGTM

Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Signed-off-by: Nick Manning <75833+seenickcode@users.noreply.github.com>

@seenickcode seenickcode left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community pull requests from community feedback-requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants