Skip to content

Metadata: Use file mod time instead of birth time as creation time fallback #4157

@kjetilho

Description

@kjetilho

1. What is not working as documented?

In mediafile.go, the import does:

	if fileInfo.HasBirthTime() {
		m.takenAt = fileInfo.BirthTime().UTC()
		log.Infof("media: %s was taken at %s (file birth time)", clean.Log(filepath.Base(m.fileName)), m.takenAt.String())
	} else {
		m.takenAt = fileInfo.ModTime().UTC()
		log.Infof("media: %s was taken at %s (file mod time)", clean.Log(filepath.Base(m.fileName)), m.takenAt.String())
	}

However, if you have moved your files around a few times (copied them to a different server), BirthTime will be the time of the last backup (the birth time of the file on that server), not when the file was created for the first time.

Trivial example:

$ stat ./Pictures/sigfried-1927.jpg 
  File: ./Pictures/sigfried-1927.jpg
  Size: 10749     	Blocks: 24         IO Block: 4096   regular file
Device: 253,1	Inode: 4124311     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1232/kjetilho)   Gid: (  960/photoprism)
Access: 2024-04-07 00:33:27.189450507 +0200
Modify: 2014-10-12 02:23:06.000000000 +0200
Change: 2024-04-07 00:25:46.808088926 +0200
 Birth: 2024-03-29 20:53:55.942567413 +0100

Let's do a fresh copy, and see the birth time is updated to the current time.

$ cp --preserve Pictures/sigfried-1927.jpg test.jpg
$ stat test.jpg
  File: test.jpg
  Size: 10749     	Blocks: 24         IO Block: 4096   regular file
Device: 253,1	Inode: 4146744     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1232/kjetilho)   Gid: (  960/photoprism)
Access: 2024-04-07 00:33:27.189450507 +0200
Modify: 2014-10-12 02:23:06.000000000 +0200
Change: 2024-04-07 00:47:33.227091882 +0200
 Birth: 2024-04-07 00:47:33.215092029 +0200

2. How can we reproduce it?

Steps to reproduce the behavior:

  1. Copy an image file without metadata
  2. Import it
  3. See it included in the wrong calendar event.

3. What behavior do you expect?

I would expect PhotoPrism to use the Modify Time.

6. Which software versions do you use?

Installed using podman-compose, but code seems unchanged since that release.

(a) PhotoPrism Architecture & Build Number: photoprism version 231128-f48ff16ef-Linux-AMD64-Plus

(b) Database Type & Version: MariaDB

(c) Operating System Types & Versions: Linux

Metadata

Metadata

Labels

bugSomething isn't workingmetadataRelated to Exif, XMP, IPTC & Co.releasedAvailable in the stable releasetestedChanges have been tested successfully

Type

No type

Projects

Status

Release 🌈

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions