mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user