Restore: Find album backups in originals folder as well

This commit is contained in:
Michael Mayer 2021-02-21 15:48:46 +01:00
parent d8d5ff86ba
commit 32ef03083d
3 changed files with 25 additions and 1 deletions

View file

@ -363,3 +363,8 @@ func (c *Config) SqliteBin() string {
func (c *Config) AlbumsPath() string {
return filepath.Join(c.StoragePath(), "albums")
}
// OriginalsAlbumsPath returns the optional album YAML backup folder inside originals.
func (c *Config) OriginalsAlbumsPath() string {
return filepath.Join(c.OriginalsPath(), "albums")
}

View file

@ -91,6 +91,18 @@ func TestConfig_TestdataPath(t *testing.T) {
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/testdata", c.TestdataPath())
}
func TestConfig_AlbumsPath(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/albums", c.AlbumsPath())
}
func TestConfig_OriginalsAlbumsPath(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/originals/albums", c.OriginalsAlbumsPath())
}
func TestConfig_CreateDirectories(t *testing.T) {
testConfigMutex.Lock()
defer testConfigMutex.Unlock()

View file

@ -61,6 +61,11 @@ func RestoreAlbums(force bool) (count int, result error) {
albums, err := filepath.Glob(regexp.QuoteMeta(c.AlbumsPath()) + "/**/*.yml")
if oAlbums, oErr := filepath.Glob(regexp.QuoteMeta(c.OriginalsAlbumsPath()) + "/**/*.yml"); oErr == nil {
err = nil
albums = append(albums, oAlbums...)
}
if err != nil {
return count, err
}
@ -73,8 +78,10 @@ func RestoreAlbums(force bool) (count int, result error) {
a := entity.Album{}
if err := a.LoadFromYaml(fileName); err != nil {
log.Errorf("album: %s (load yaml)", err)
log.Errorf("restore: %s in %s", err, txt.Quote(filepath.Base(fileName)))
result = err
} else if len(a.Photos) == 0 && a.AlbumFilter == "" {
log.Debugf("restore: skipping %s", txt.Quote(filepath.Base(fileName)))
} else if err := a.Create(); err != nil {
log.Warnf("%s: %s already exists", a.AlbumType, txt.Quote(a.AlbumTitle))
} else {