Fix zip gallery renaming (#3036)

This commit is contained in:
DingDongSoLong4 2022-10-24 00:38:02 +02:00 committed by GitHub
parent 33de28ce5d
commit 4db0e48f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 29 deletions

View File

@ -129,9 +129,8 @@ func (s *Scanner) Scan(ctx context.Context, handlers []Handler, options ScanOpti
type scanFile struct {
*BaseFile
fs FS
info fs.FileInfo
zipFile *scanFile
fs FS
info fs.FileInfo
}
func (s *scanJob) withTxn(ctx context.Context, fn func(ctx context.Context) error) error {
@ -230,9 +229,15 @@ func (s *scanJob) queueFileFunc(ctx context.Context, f FS, zipFile *scanFile) fs
},
fs: f,
info: info,
// there is no guarantee that the zip file has been scanned
// so we can't just plug in the id.
zipFile: zipFile,
}
if zipFile != nil {
zipFileID, err := s.getZipFileID(ctx, zipFile)
if err != nil {
return err
}
ff.ZipFileID = zipFileID
ff.ZipFile = zipFile
}
if info.IsDir() {
@ -348,7 +353,7 @@ func (s *scanJob) processQueue(ctx context.Context) error {
func (s *scanJob) incrementProgress(f scanFile) {
// don't increment for files inside zip files since these aren't
// counted during the initial walking
if s.ProgressReports != nil && f.zipFile == nil {
if s.ProgressReports != nil && f.ZipFile == nil {
s.ProgressReports.Increment()
}
}
@ -453,23 +458,12 @@ func (s *scanJob) onNewFolder(ctx context.Context, file scanFile) (*Folder, erro
now := time.Now()
toCreate := &Folder{
DirEntry: DirEntry{
ModTime: file.ModTime,
},
DirEntry: file.DirEntry,
Path: file.Path,
CreatedAt: now,
UpdatedAt: now,
}
zipFileID, err := s.getZipFileID(ctx, file.zipFile)
if err != nil {
return nil, err
}
if zipFileID != nil {
toCreate.ZipFileID = zipFileID
}
dir := filepath.Dir(file.Path)
if dir != "." {
parentFolderID, err := s.getFolderID(ctx, dir)
@ -601,15 +595,6 @@ func (s *scanJob) onNewFile(ctx context.Context, f scanFile) (File, error) {
baseFile.ParentFolderID = *parentFolderID
zipFileID, err := s.getZipFileID(ctx, f.zipFile)
if err != nil {
return nil, err
}
if zipFileID != nil {
baseFile.ZipFileID = zipFileID
}
const useExisting = false
fp, err := s.calculateFingerprints(f.fs, baseFile, path, useExisting)
if err != nil {
@ -744,7 +729,8 @@ func (s *scanJob) handleRename(ctx context.Context, f File, fp []Fingerprint) (F
// TODO - handle #1426 scenario
fs, err := s.getFileFS(other.Base())
if err != nil {
return nil, fmt.Errorf("getting FS for %q: %w", other.Base().Path, err)
missing = append(missing, other)
continue
}
if _, err := fs.Lstat(other.Base().Path); err != nil {