Index: Reduce log level for empty files from error to warning #2257

This commit is contained in:
Michael Mayer 2022-04-18 17:21:31 +02:00
parent b75b4a89a0
commit f33f06933f
7 changed files with 25 additions and 6 deletions

View file

@ -8,8 +8,6 @@ import (
"runtime/debug"
"sync"
"github.com/photoprism/photoprism/pkg/media"
"github.com/karrick/godirwalk"
"github.com/photoprism/photoprism/internal/classify"
@ -21,6 +19,7 @@ import (
"github.com/photoprism/photoprism/internal/nsfw"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/fs"
"github.com/photoprism/photoprism/pkg/media"
)
// Index represents an indexer that indexes files in the originals directory.
@ -185,7 +184,7 @@ func (ind *Index) Start(o IndexOptions) fs.Done {
// Check if file exists and is not empty.
if err != nil {
log.Errorf("index: %s", err)
log.Warnf("index: %s", err)
return nil
}

View file

@ -336,7 +336,6 @@ func (m *MediaFile) RelatedFiles(stripSequence bool) (result RelatedFiles, err e
f, fileErr := NewMediaFile(fileName)
if fileErr != nil {
log.Warn(fileErr)
continue
}

View file

@ -24,7 +24,7 @@ func (m *MediaFile) HasSidecarJson() bool {
func (m *MediaFile) SidecarJsonName() string {
jsonName := m.fileName + ".json"
if fs.FileExists(jsonName) {
if fs.FileExistsNotEmpty(jsonName) {
return jsonName
}

View file

@ -48,6 +48,7 @@ func TestNewFileInfos(t *testing.T) {
}
expected := map[string]FileInfo{
"empty.jpg": {Abs: PathSeparator + "empty.jpg", Size: 0, Dir: false},
"test.jpg": {Abs: PathSeparator + "test.jpg", Size: 10990, Dir: false},
"CATYELLOW.jpg": {Abs: PathSeparator + "CATYELLOW.jpg", Size: 70790, Dir: false},
"directory": {Abs: PathSeparator + "directory", Size: 4096, Dir: true},
@ -57,7 +58,6 @@ func TestNewFileInfos(t *testing.T) {
for _, file := range result {
assert.NotEmpty(t, file.Name)
assert.NotEmpty(t, file.Abs)
assert.NotEmpty(t, file.Size)
assert.False(t, file.Date.IsZero())
if info, ok := expected[file.Name]; ok {

View file

@ -58,6 +58,17 @@ func FileExists(fileName string) bool {
return err == nil && !info.IsDir()
}
// FileExistsNotEmpty returns true if file exists, is not a directory, and not empty.
func FileExistsNotEmpty(fileName string) bool {
if fileName == "" {
return false
}
info, err := os.Stat(fileName)
return err == nil && !info.IsDir() && info.Size() > 0
}
// PathExists tests if a path exists, and is a directory or symlink.
func PathExists(path string) bool {
if path == "" {

View file

@ -23,10 +23,20 @@ func TestMain(m *testing.M) {
func TestFileExists(t *testing.T) {
assert.True(t, FileExists("./testdata/test.jpg"))
assert.True(t, FileExists("./testdata/test.jpg"))
assert.True(t, FileExists("./testdata/empty.jpg"))
assert.False(t, FileExists("./foo.jpg"))
assert.False(t, FileExists(""))
}
func TestFileExistsNotEmpty(t *testing.T) {
assert.True(t, FileExistsNotEmpty("./testdata/test.jpg"))
assert.True(t, FileExistsNotEmpty("./testdata/test.jpg"))
assert.False(t, FileExistsNotEmpty("./testdata/empty.jpg"))
assert.False(t, FileExistsNotEmpty("./foo.jpg"))
assert.False(t, FileExistsNotEmpty(""))
}
func TestPathExists(t *testing.T) {
assert.True(t, PathExists("./testdata"))
assert.False(t, PathExists("./testdata/test.jpg"))

0
pkg/fs/testdata/empty.jpg vendored Normal file
View file