Merge pull request #362 from JustAnotherArchivist/fix-metadata-rewrite

Only rewrite metadata file when the download counter changed
This commit is contained in:
Andrea Spacca 2021-04-24 21:23:51 +02:00 committed by GitHub
commit 31ef712847
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -661,13 +661,11 @@ func (s *Server) CheckMetadata(token, filename string, increaseDownload bool) (M
return metadata, errors.New("MaxDownloads expired.")
} else if !metadata.MaxDate.IsZero() && time.Now().After(metadata.MaxDate) {
return metadata, errors.New("MaxDate expired.")
} else {
} else if increaseDownload {
// todo(nl5887): mutex?
// update number of downloads
if increaseDownload {
metadata.Downloads++
}
metadata.Downloads++
buffer := &bytes.Buffer{}
if err := json.NewEncoder(buffer).Encode(metadata); err != nil {