From ea4b9dccec32f472aca2358ba828dde9580fdb35 Mon Sep 17 00:00:00 2001 From: sijmenhuizenga Date: Fri, 11 Sep 2020 20:11:23 +0200 Subject: [PATCH 1/3] Set timestamps of downloaded files to media creation timestamp --- downloader/downloader.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/downloader/downloader.go b/downloader/downloader.go index c415269..3faa758 100644 --- a/downloader/downloader.go +++ b/downloader/downloader.go @@ -233,6 +233,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 availabe, 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 { + log.Printf("Warning: Could not write timestamp to '%v': %v", filePath, err) + } + } + log.Printf("Downloaded '%v' [saved as '%v'] (%v)", item.FileName, item.UsedFileName, humanize.Bytes(uint64(n))) d.stats.UpdateStatsDownloaded(uint64(n), 1) From ec55039ed4827b2993c3c88bf69153ea1fd56b31 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Fri, 11 Sep 2020 21:44:58 +0200 Subject: [PATCH 2/3] Update downloader.go --- downloader/downloader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/downloader/downloader.go b/downloader/downloader.go index 3faa758..9fa126d 100644 --- a/downloader/downloader.go +++ b/downloader/downloader.go @@ -241,7 +241,7 @@ func (d *Downloader) downloadImage(item *LibraryItem, filePath string) error { if err == nil { err = os.Chtimes(filePath, time.Now(), t) if err != nil { - log.Printf("Warning: Could not write timestamp to '%v': %v", filePath, err) + return err; } } From fa6259b8ab1c6f06aed161a1d887d4f470d00ff1 Mon Sep 17 00:00:00 2001 From: sijmenhuizenga Date: Fri, 11 Sep 2020 21:56:32 +0200 Subject: [PATCH 3/3] Wrap timestamp error to give better understanding of where the error came from --- downloader/downloader.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/downloader/downloader.go b/downloader/downloader.go index 9fa126d..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" @@ -236,12 +237,12 @@ func (d *Downloader) downloadImage(item *LibraryItem, filePath string) error { // close file to prevent conflicts with writing new timestamp in next step output.Close() - //If timestamp is availabe, 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) + //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 err; + return errors.New("failed writing timestamp to file: " + err.Error()) } }