Index: Skip empty files #391

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-07-21 10:44:41 +02:00
parent ad93f04003
commit ab6228fb9a
4 changed files with 21 additions and 3 deletions

View file

@ -97,6 +97,9 @@ func TestDetails_NoCopyright(t *testing.T) {
func TestNewDetails(t *testing.T) {
t.Run("add to photo", func(t *testing.T) {
p := NewPhoto()
assert.Equal(t, TitleUnknown, p.PhotoTitle)
d := NewDetails(p)
p.Details = &d
d.Subject = "Foo Bar"

View file

@ -92,6 +92,7 @@ type Photo struct {
// NewPhoto creates a photo entity.
func NewPhoto() Photo {
return Photo{
PhotoTitle: TitleUnknown,
PhotoType: TypeImage,
PhotoCountry: UnknownCountry.ID,
CameraID: UnknownCamera.ID,

View file

@ -84,6 +84,7 @@ func (imp *Import) Start(opt ImportOptions) fs.Done {
}()
}
filesImported := 0
indexOpt := IndexOptionsAll()
ignore := fs.NewIgnoreList(fs.IgnoreFile, true, false)
@ -132,6 +133,8 @@ func (imp *Import) Start(opt ImportOptions) fs.Done {
return result
}
done[fileName] = fs.Found
if !fs.IsMedia(fileName) {
return nil
}
@ -142,6 +145,11 @@ func (imp *Import) Start(opt ImportOptions) fs.Done {
return nil
}
if mf.FileSize() == 0 {
log.Infof("import: skipped empty file %s", txt.Quote(mf.BaseName()))
return nil
}
related, err := mf.RelatedFiles(imp.conf.Settings().Index.Sequences)
if err != nil {
@ -153,11 +161,12 @@ func (imp *Import) Start(opt ImportOptions) fs.Done {
var files MediaFiles
for _, f := range related.Files {
if done[f.FileName()].Processed() {
if f.FileSize() == 0 || done[f.FileName()].Processed() {
continue
}
files = append(files, f)
filesImported++
done[f.FileName()] = fs.Processed
}
@ -216,7 +225,7 @@ func (imp *Import) Start(opt ImportOptions) fs.Done {
log.Error(err.Error())
}
if len(done) > 0 {
if filesImported > 0 {
if err := entity.UpdatePhotoCounts(); err != nil {
log.Errorf("import: %s", err)
}

View file

@ -151,6 +151,11 @@ func (ind *Index) Start(opt IndexOptions) fs.Done {
return nil
}
if mf.FileSize() == 0 {
log.Infof("index: skipped empty file %s", txt.Quote(mf.BaseName()))
return nil
}
if ind.files.Indexed(relName, entity.RootOriginals, mf.modTime, opt.Rescan) {
return nil
}
@ -170,7 +175,7 @@ func (ind *Index) Start(opt IndexOptions) fs.Done {
continue
}
if ind.files.Indexed(f.RootRelName(), f.Root(), f.ModTime(), opt.Rescan) {
if f.FileSize() == 0 || ind.files.Indexed(f.RootRelName(), f.Root(), f.ModTime(), opt.Rescan) {
done[f.FileName()] = fs.Found
continue
}