fix: mark files as scanned on upload#600
Open
Antreesy wants to merge 2 commits into
Open
Conversation
1d7eefc to
dbeaed8
Compare
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
dbeaed8 to
62753d6
Compare
62753d6 to
28d1422
Compare
…load Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
28d1422 to
e8d9786
Compare
icewind1991
reviewed
May 13, 2026
Comment on lines
+188
to
+199
| if (preg_match('/\.ocTransferId\d+\.part$/i', $path)) { | ||
| $davFilesPrefix = '/dav/files'; | ||
| $pathInfo = $this->request->getPathInfo(); | ||
| if (str_starts_with($pathInfo, $davFilesPrefix)) { | ||
| $afterPrefix = substr($pathInfo, strlen($davFilesPrefix)); // /{username}/{relative} | ||
| $secondSlash = strpos($afterPrefix, '/', 1); | ||
| if ($secondSlash !== false) { | ||
| // Insert /files between the username segment and the rest of the path | ||
| return substr($afterPrefix, 0, $secondSlash) . '/files' . substr($afterPrefix, $secondSlash); | ||
| } | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
how does this differ from getPathForScanner?
Contributor
Author
There was a problem hiding this comment.
it adds a /files/ suffix, so when the file upload is finished, Node:getPath() matches that.
There might be an easy alternative way, but from I understand, entry in oc_filecache does not exist yet, when AvirWrapper finished scanning; so we either need to:
- know the final path of the clean file to edit the entry
- use another identificator for such file.
Is there something we can use for it?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commit 1
The initial implementation tried to mark files as scanned immediately after the AV scan in AvirWrapper, but this failed because:
Additionally, the follow-up NodeWrittenListener that was introduced to fix the timing issue marked every uploaded file as scanned unconditionally, with no knowledge of whether the scan actually succeeded — meaning unreachable-AV uploads were still silently marked as clean.
Commit 2
Using NodeWrittenEvent to mark files after they're fully written and synced, combined with a ScannedPathsRegistry — a request-scoped in-memory map that bridges the scanning layer and the post-upload persistence layer:
The registry is a plain PHP object resolved as a per-request singleton by Nextcloud's DI container, so it is naturally shared between FilesystemSetupListener (which constructs AvirWrapper) and NodeWrittenListener without any explicit container registration.
Nextcloud DAV uploads use hashed temporary filenames (e.g. ab3cd4.ocTransferId123.part), making it impossible to recover the real filename from the storage path alone. getRegistryPath() detects this case and falls back to the DAV request URI (/dav/files/{user}/{real_path}), transforming it to match the absolute path returned by Node::getPath() (/{user}/files/{real_path}).
Testing
After upload, verify the file is marked:
SELECT fileid, check_time FROM oc_files_antivirus WHERE fileid = <FILE_ID>;
The file should have a check_time timestamp instead of NULL.