mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Fix oshash calculation for symlinks (#2198)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -117,6 +118,19 @@ func (o Scanner) generateHashes(f *models.File, file SourceFile, regenerate bool
|
|||||||
if o.CalculateOSHash && (regenerate || f.OSHash == "") {
|
if o.CalculateOSHash && (regenerate || f.OSHash == "") {
|
||||||
logger.Infof("Calculating oshash for %s ...", f.Path)
|
logger.Infof("Calculating oshash for %s ...", f.Path)
|
||||||
|
|
||||||
|
size := file.FileInfo().Size()
|
||||||
|
|
||||||
|
// #2196 for symlinks
|
||||||
|
// get the size of the actual file, not the symlink
|
||||||
|
if file.FileInfo().Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||||
|
fi, err := os.Stat(f.Path)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
logger.Debugf("File <%s> is symlink. Size changed from <%d> to <%d>", f.Path, size, fi.Size())
|
||||||
|
size = fi.Size()
|
||||||
|
}
|
||||||
|
|
||||||
src, err = file.Open()
|
src, err = file.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -130,7 +144,7 @@ func (o Scanner) generateHashes(f *models.File, file SourceFile, regenerate bool
|
|||||||
|
|
||||||
// regenerate hash
|
// regenerate hash
|
||||||
var oshash string
|
var oshash string
|
||||||
oshash, err = o.Hasher.OSHash(seekSrc, file.FileInfo().Size())
|
oshash, err = o.Hasher.OSHash(seekSrc, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("error generating oshash for %s: %w", file.Path(), err)
|
return false, fmt.Errorf("error generating oshash for %s: %w", file.Path(), err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
### 🐛 Bug fixes
|
### 🐛 Bug fixes
|
||||||
|
* Fix error when scanning symlinks. ([#2196](https://github.com/stashapp/stash/issues/2196))
|
||||||
* Fix timezone issue with Created/Updated dates in scene/image/gallery details pages. ([#2190](https://github.com/stashapp/stash/pull/2190))
|
* Fix timezone issue with Created/Updated dates in scene/image/gallery details pages. ([#2190](https://github.com/stashapp/stash/pull/2190))
|
||||||
|
|||||||
Reference in New Issue
Block a user