diff --git a/downloader/downloader.go b/downloader/downloader.go index c415269..273e082 100644 --- a/downloader/downloader.go +++ b/downloader/downloader.go @@ -4,6 +4,7 @@ import ( "crypto/md5" "encoding/hex" "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -233,6 +234,18 @@ func (d *Downloader) downloadImage(item *LibraryItem, filePath string) error { return err } + // close file to prevent conflicts with writing new timestamp in next step + output.Close() + + //If timestamp is available, set access time to current timestamp and set modified time to the time the item was first created (not when it was uploaded to Google Photos) + t, err := time.Parse(time.RFC3339, item.MediaMetadata.CreationTime) + if err == nil { + err = os.Chtimes(filePath, time.Now(), t) + if err != nil { + return errors.New("failed writing timestamp to file: " + err.Error()) + } + } + log.Printf("Downloaded '%v' [saved as '%v'] (%v)", item.FileName, item.UsedFileName, humanize.Bytes(uint64(n))) d.stats.UpdateStatsDownloaded(uint64(n), 1)