Backend: Re-import missing files #300
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
4fbed12e94
commit
4e3c076511
3 changed files with 24 additions and 13 deletions
|
@ -4,7 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"sync"
|
||||
|
@ -217,26 +217,30 @@ func (imp *Import) DestinationFilename(mainFile *MediaFile, mediaFile *MediaFile
|
|||
|
||||
if !mediaFile.IsSidecar() {
|
||||
if f, err := entity.FirstFileByHash(mediaFile.Hash()); err == nil {
|
||||
existingFilename := imp.conf.OriginalsPath() + string(os.PathSeparator) + f.FileName
|
||||
return existingFilename, fmt.Errorf("%s is identical to %s (sha1 %s)", txt.Quote(mediaFile.FileName()), txt.Quote(f.FileName), mediaFile.Hash())
|
||||
existingFilename := filepath.Join(imp.conf.OriginalsPath(), f.FileName)
|
||||
if fs.FileExists(existingFilename) {
|
||||
return existingFilename, fmt.Errorf("%s is identical to %s (sha1 %s)", txt.Quote(filepath.Base(mediaFile.FileName())), txt.Quote(f.FileName), mediaFile.Hash())
|
||||
} else {
|
||||
return existingFilename, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mon Jan 2 15:04:05 -0700 MST 2006
|
||||
pathName := path.Join(imp.originalsPath(), dateCreated.Format("2006/01"))
|
||||
pathName := filepath.Join(imp.originalsPath(), dateCreated.Format("2006/01"))
|
||||
|
||||
iteration := 0
|
||||
|
||||
result := path.Join(pathName, fileName+fileExtension)
|
||||
result := filepath.Join(pathName, fileName+fileExtension)
|
||||
|
||||
for fs.FileExists(result) {
|
||||
if mediaFile.Hash() == fs.Hash(result) {
|
||||
return result, fmt.Errorf("file already exists: %s", result)
|
||||
return result, fmt.Errorf("%s already exists", txt.Quote(fs.RelativeName(result, imp.originalsPath())))
|
||||
}
|
||||
|
||||
iteration++
|
||||
|
||||
result = path.Join(pathName, fileName+"."+fmt.Sprintf("%04d", iteration)+fileExtension)
|
||||
result = filepath.Join(pathName, fileName+"."+fmt.Sprintf("%04d", iteration)+fileExtension)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
|
|
@ -63,11 +63,15 @@ func ImportWorker(jobs <-chan ImportJob) {
|
|||
log.Errorf("import: could not copy file to %s (%s)", txt.Quote(fs.RelativeName(destinationMainFilename, imp.originalsPath())), err.Error())
|
||||
}
|
||||
}
|
||||
} else if opt.RemoveExistingFiles {
|
||||
if err := f.Remove(); err != nil {
|
||||
log.Errorf("import: could not delete %s (%s)", txt.Quote(fs.RelativeName(f.FileName(), importPath)), err.Error())
|
||||
} else {
|
||||
log.Infof("import: deleted %s (already exists)", txt.Quote(relativeFilename))
|
||||
} else {
|
||||
log.Warnf("import: %s", err)
|
||||
|
||||
if opt.RemoveExistingFiles {
|
||||
if err := f.Remove(); err != nil {
|
||||
log.Errorf("import: could not delete %s (%s)", txt.Quote(fs.RelativeName(f.FileName(), importPath)), err.Error())
|
||||
} else {
|
||||
log.Infof("import: deleted %s (already exists)", txt.Quote(relativeFilename))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,12 +149,16 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
|
|||
// restore photos that have been purged automatically
|
||||
photo.DeletedAt = nil
|
||||
} else if photo.DeletedAt != nil {
|
||||
// don't waste time indexing deleted / archived photos
|
||||
result.Status = IndexArchived
|
||||
return result
|
||||
}
|
||||
|
||||
// file obviously exists: remove deleted and missing flags
|
||||
file.DeletedAt = nil
|
||||
file.FileMissing = false
|
||||
|
||||
// primary files are used for rendering thumbnails and image classification (plus sidecar files if they exist)
|
||||
if file.FilePrimary {
|
||||
primaryFile = file
|
||||
|
||||
|
@ -270,7 +274,6 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
|
|||
|
||||
file.FileSidecar = m.IsSidecar()
|
||||
file.FileVideo = m.IsVideo()
|
||||
file.FileMissing = false
|
||||
file.FileName = fileName
|
||||
file.FileHash = fileHash
|
||||
file.FileSize = fileSize
|
||||
|
|
Loading…
Reference in a new issue