-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix file modification date comparisons #14503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
On filesystems like ZFS with higher modification time accuracy than the database, the comparison itemLastModifiedFileSystem != modificationDate fails. Allow a tolerance of 1 second.
6b976c2
to
7105a5d
Compare
I wouldn't mind merging this but I use ZFS too and never had any issue with this while testing before and after we released the RCs. |
I never noticed this until I put 40k music tracks into Jellyfin and found scans took all day and reprocessed all media. With debugging enabled I recorded logs like: [08:42:41] [DBG] [31] MediaBrowser.Providers.TV.EpisodeMetadataService: File modification time changed from 03/12/2025 13:14:21 to 03/12/2025 13:14:21: With the changes a library scan takes a few minutes. |
But |
The problem was on all my media and that episode happened to be the one I chose to reference in the jellyfin developer chat, so I had a record of it in the chat to give here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to find a better way in the long term to do those comparisions like truncating the timestamps to ms accuracy in the DirectoryService and FileService but for now that will do it
Emby.Photos/PhotoProvider.cs
Outdated
@@ -49,7 +49,7 @@ public bool HasChanged(BaseItem item, IDirectoryService directoryService) | |||
if (item.IsFileProtocol) | |||
{ | |||
var file = directoryService.GetFile(item.Path); | |||
return file is not null && file.LastWriteTimeUtc != item.DateModified; | |||
return file is not null && item.DateModified.Subtract(file.LastWriteTimeUtc).Duration().TotalSeconds > 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copied in so many places now that I think it warrants an extension/utility method.
FileService will return whatever with whatever accuracy on a given platform, the database will return with whatever accuracy on a given platform, and Jelly should not care as long as the file modification date is sufficiently different for its purposes. For this change "sufficiently different" was chosen to be 1 second, but there is existing code in Jelly that works the same way for "sufficiently different" being 1 day instead (for once per day updates). It just can't directly compare fileModified == databaseModified, just like floating point values can't be directly compared with == because floating point accuracy can vary. The code is simple and robust; if we are worried about it being ugly, it could easily be done as a helper function (e.g. if fileChanged(databaseModified, fileModified, accuracySeconds = 1) { } and then is also usable in those cases using a 1 day resolution. |
Changes
On filesystems like ZFS with higher modification time accuracy than the database, the comparison itemLastModifiedFileSystem != modificationDate fails. Allow a tolerance of 1 second.
Issues
No issue raised. On ZFS causes every file to be rescanned on every scan run.