diff --git a/internal/photoprism/index.go b/internal/photoprism/index.go index d1b444e12..cb0331180 100644 --- a/internal/photoprism/index.go +++ b/internal/photoprism/index.go @@ -170,7 +170,7 @@ func (ind *Index) Start(opt IndexOptions) fs.Done { continue } - if f.FileName() != fileName && ind.files.Ignore(f.RelName(originalsPath), f.ModTime(), opt.Rescan) { + if f.FileName() != fileName && ind.files.Ignore(f.RootRelName(), f.ModTime(), opt.Rescan) { continue } diff --git a/internal/photoprism/mediafile.go b/internal/photoprism/mediafile.go index 70f400b59..b25236698 100644 --- a/internal/photoprism/mediafile.go +++ b/internal/photoprism/mediafile.go @@ -340,6 +340,8 @@ func (m *MediaFile) PathNameInfo() (fileRoot, fileBase, relativePath, relativeNa rootPath = Config().SidecarPath() case entity.RootImport: rootPath = Config().ImportPath() + case entity.RootExamples: + rootPath = Config().ExamplesPath() default: rootPath = Config().OriginalsPath() } @@ -366,6 +368,24 @@ func (m *MediaFile) SetFileName(fileName string) { m.fileName = fileName } +// RootRelName returns the relative filename and automatically detects the root path. +func (m *MediaFile) RootRelName() string { + var rootPath string + + switch m.Root() { + case entity.RootSidecar: + rootPath = Config().SidecarPath() + case entity.RootImport: + rootPath = Config().ImportPath() + case entity.RootExamples: + rootPath = Config().ExamplesPath() + default: + rootPath = Config().OriginalsPath() + } + + return m.RelName(rootPath) +} + // RelName returns the relative filename. func (m *MediaFile) RelName(directory string) string { return fs.RelName(m.fileName, directory) diff --git a/internal/photoprism/mediafile_test.go b/internal/photoprism/mediafile_test.go index 0be0f3673..f65431998 100644 --- a/internal/photoprism/mediafile_test.go +++ b/internal/photoprism/mediafile_test.go @@ -625,10 +625,26 @@ func TestMediaFile_SetFilename(t *testing.T) { assert.Equal(t, "turtle_brown_blue", mediaFile.fileName) } -func TestMediaFile_RelativeFilename(t *testing.T) { +func TestMediaFile_RootRelName(t *testing.T) { conf := config.TestConfig() mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/tree_white.jpg") + + if err != nil { + t.Fatal(err) + } + + t.Run("examples_path", func(t *testing.T) { + filename := mediaFile.RootRelName() + assert.Equal(t, "tree_white.jpg", filename) + }) +} + +func TestMediaFile_RelName(t *testing.T) { + conf := config.TestConfig() + + mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/tree_white.jpg") + if err != nil { t.Fatal(err) }