mirror of https://github.com/stashapp/stash.git
Fix interactive speed being lost when file is moved (#4799)
This commit is contained in:
parent
560bdcd60d
commit
141f60f8fb
|
@ -895,28 +895,35 @@ func (s *scanJob) handleRename(ctx context.Context, f models.File, fp []models.F
|
|||
// assume does not exist, update existing file
|
||||
// it's possible that there may be multiple missing files.
|
||||
// just use the first one to rename.
|
||||
// #4775 - using the new file instance means that any changes made to the existing
|
||||
// file will be lost. Update the existing file instead.
|
||||
other := missing[0]
|
||||
otherBase := other.Base()
|
||||
updated := other.Clone()
|
||||
updatedBase := updated.Base()
|
||||
|
||||
fBase := f.Base()
|
||||
fBaseCopy := *(f.Base())
|
||||
|
||||
logger.Infof("%s moved to %s. Updating path...", otherBase.Path, fBase.Path)
|
||||
fBase.ID = otherBase.ID
|
||||
fBase.CreatedAt = otherBase.CreatedAt
|
||||
fBase.Fingerprints = otherBase.Fingerprints
|
||||
oldPath := updatedBase.Path
|
||||
newPath := fBaseCopy.Path
|
||||
|
||||
logger.Infof("%s moved to %s. Updating path...", oldPath, newPath)
|
||||
fBaseCopy.ID = updatedBase.ID
|
||||
fBaseCopy.CreatedAt = updatedBase.CreatedAt
|
||||
fBaseCopy.Fingerprints = updatedBase.Fingerprints
|
||||
*updatedBase = fBaseCopy
|
||||
|
||||
if err := s.withTxn(ctx, func(ctx context.Context) error {
|
||||
if err := s.Repository.File.Update(ctx, f); err != nil {
|
||||
return fmt.Errorf("updating file for rename %q: %w", fBase.Path, err)
|
||||
if err := s.Repository.File.Update(ctx, updated); err != nil {
|
||||
return fmt.Errorf("updating file for rename %q: %w", newPath, err)
|
||||
}
|
||||
|
||||
if s.isZipFile(fBase.Basename) {
|
||||
if err := transferZipHierarchy(ctx, s.Repository.Folder, s.Repository.File, fBase.ID, otherBase.Path, fBase.Path); err != nil {
|
||||
return fmt.Errorf("moving zip hierarchy for renamed zip file %q: %w", fBase.Path, err)
|
||||
if s.isZipFile(updatedBase.Basename) {
|
||||
if err := transferZipHierarchy(ctx, s.Repository.Folder, s.Repository.File, updatedBase.ID, oldPath, newPath); err != nil {
|
||||
return fmt.Errorf("moving zip hierarchy for renamed zip file %q: %w", newPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.fireHandlers(ctx, f, other); err != nil {
|
||||
if err := s.fireHandlers(ctx, updated, other); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -925,7 +932,7 @@ func (s *scanJob) handleRename(ctx context.Context, f models.File, fp []models.F
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return f, nil
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
func (s *scanJob) isHandlerRequired(ctx context.Context, f models.File) bool {
|
||||
|
|
|
@ -111,6 +111,7 @@ type File interface {
|
|||
Base() *BaseFile
|
||||
SetFingerprints(fp Fingerprints)
|
||||
Open(fs FS) (io.ReadCloser, error)
|
||||
Clone() File
|
||||
}
|
||||
|
||||
// BaseFile represents a file in the file system.
|
||||
|
@ -173,6 +174,12 @@ func (f *BaseFile) Open(fs FS) (io.ReadCloser, error) {
|
|||
return fs.Open(f.Path)
|
||||
}
|
||||
|
||||
func (f *BaseFile) Clone() (ret File) {
|
||||
clone := *f
|
||||
ret = &clone
|
||||
return
|
||||
}
|
||||
|
||||
func (f *BaseFile) Info(fs FS) (fs.FileInfo, error) {
|
||||
return f.info(fs, f.Path)
|
||||
}
|
||||
|
@ -249,6 +256,13 @@ func (f ImageFile) GetFormat() string {
|
|||
return f.Format
|
||||
}
|
||||
|
||||
func (f ImageFile) Clone() (ret File) {
|
||||
clone := f
|
||||
clone.BaseFile = f.BaseFile.Clone().(*BaseFile)
|
||||
ret = &clone
|
||||
return
|
||||
}
|
||||
|
||||
// VideoFile is an extension of BaseFile to represent video files.
|
||||
type VideoFile struct {
|
||||
*BaseFile
|
||||
|
@ -277,6 +291,13 @@ func (f VideoFile) GetFormat() string {
|
|||
return f.Format
|
||||
}
|
||||
|
||||
func (f VideoFile) Clone() (ret File) {
|
||||
clone := f
|
||||
clone.BaseFile = f.BaseFile.Clone().(*BaseFile)
|
||||
ret = &clone
|
||||
return
|
||||
}
|
||||
|
||||
// #1572 - Inf and NaN values cause the JSON marshaller to fail
|
||||
// Replace these values with 0 rather than erroring
|
||||
|
||||
|
|
Loading…
Reference in New Issue