Handle zip file modification (#877)

* Rescan zip if updating mod time
* Use inequality for mod time comparison
* Add sort by file_mod_time (fixes #469)
This commit is contained in:
WithoutPants
2020-11-05 10:26:51 +11:00
committed by GitHub
parent 9ec762ae9a
commit 5f482b7b8a
20 changed files with 612 additions and 163 deletions

View File

@@ -11,6 +11,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
@@ -120,6 +121,21 @@ func getFilePath(path string) (zipFilename, filename string) {
return
}
// GetFileDetails returns a pointer to an Image object with the
// width, height and size populated.
func GetFileDetails(path string) (*models.Image, error) {
i := &models.Image{
Path: path,
}
err := SetFileDetails(i)
if err != nil {
return nil, err
}
return i, nil
}
func SetFileDetails(i *models.Image) error {
f, err := stat(i.Path)
if err != nil {
@@ -147,6 +163,20 @@ func SetFileDetails(i *models.Image) error {
return nil
}
// GetFileModTime gets the file modification time, handling files in zip files.
func GetFileModTime(path string) (time.Time, error) {
fi, err := stat(path)
if err != nil {
return time.Time{}, fmt.Errorf("error performing stat on %s: %s", path, err.Error())
}
ret := fi.ModTime()
// truncate to seconds, since we don't store beyond that in the database
ret = ret.Truncate(time.Second)
return ret, nil
}
func stat(path string) (os.FileInfo, error) {
// may need to read from a zip file
zipFilename, filename := getFilePath(path)