-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
mobile: fall back to mtime rather than ctime when no EXIF date is present #7162
Comments
I have investigated this bug further now and it still reproduces on v1.105.1. This actually only affects a subset of my pictures and I may have found the distinguishing characteristic: They're PNGs. It's really easy to repro by backing up your screenshots as those are typically PNGs. Here are two pictures from the same directory taken by the same app one month apart:
Apparently, I had configured the camera app to use PNG at some point between taking these. Also apparently the PNGs OpenCamera spat out don't have EXIF metadata. The JPG gets the correct time assigned in Immich while the PNG gets assigned its ctime. As you can tell by the file name, the mtime is correct (the atime too but please don't use that). I'd expect Immich to take the I assume this is an error in the fallback path when no EXIF data exists for the date. Another notable fact here is that these images were manually restored after I had to wipe my phone's userdata partition which explains why ctime != mtime. This bug may not surface under "normal" conditions where ctime should almost always equal mtime. Still, the distinction between mtime and ctime exits precisely for cases like these and should be honoured. The bug only occurs in the app (Android, can't test iOS); uploading IMG_20191222_180405.png to the web UI works as expected. This appears to be the nature for this bug: ctimes are used rather than mtimes when there is no exif data. This was supposedly fixed for the server already in #4191. Now that I know the likely root cause, this is probably a duplicate of #1861. I'll leave it up to you to either re-open that issue or continue discussing the bug here. In that issue, @fyfrey raised the point that users may prefer ctime over mtime. To this I'd like to raise the argument that ctime really does not make sense for such a scenario as it's updates when anything about a file changes, including its metadata its metadata in every sense; even the location in the filesystem. This perception might be rooted in the assumption that the "c" in ctime stands for "creation". The Wikipedia article on ctime clears that up:
I do not believe anyone could want the time they renamed an image or moved it into another directory to be used as the canonical "creation time" of the picture. mtime is the sane fallback. |
Very valuable find of the actual ctime meaning. |
I'm not sure I follow. Where is this database located, who controls it and where does its data come from? The source of truth for file metadata is always the filesystem. However that info may be pulled through the layers of abstraction, we want the mtime/modification time associated with the files in the filesystem, not any other time. Some modern filesystems implement a "birth time" metadata attribute but even that probably shouldn't be used though as a file's birth isn't preserved when copying etc. which are actions that should not change a picture's "creation time". mtime says when a file's contents were last modified and is commonly preserved when copying or can be configured to be preserved. It's intended to be controllable by users. ctime and birth time are filesystem-internal and cannot be modified.
The server part actually works fine. The bug only occurs when you upload these pictures using the app. If you upload through the web UI, the dates are correct and, from that point on, it works flawlessly with the app too. The problem is that the app sends the wrong info during upload. |
Android has a internal database for it's media assets. The photo manager library we use, queries that database and we use the returned values. We can probably use their modified time, but this will possibly break other user's data.
Very interesting. So in your instance using file mtime (from the webbrowser) works fine. We should probably try to align the behavior of uploads of the same file from the web/app. We'll need to discuss internally what is the most robust, typically best way for assets without EXIF. |
The bug
Luckily, I was still testing things out but when I added other local albums on my phone, the photos' dates weren't their mtime or exif dates but the mtime of the directory containing the photos.Edit: Far more detailed pdate below.
The OS that Immich Server is running on
NixOS
Version of Immich Server
v1.94.1
Version of Immich Mobile App
v1.94.1
Platform with the issue
Your docker-compose.yml content
Your .env content
Reproduction steps
Additional information
I first thought it was the mtime of the newest file in the directory but it was the same date for multiple local albums; the date I restored a backup on my phone.
The text was updated successfully, but these errors were encountered: