Skip to content

Commit

Permalink
Restore: Find album backups in originals folder as well
Browse files Browse the repository at this point in the history
  • Loading branch information
lastzero committed Feb 21, 2021
1 parent d8d5ff8 commit 32ef030
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/config/fs.go
Expand Up @@ -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")
}
12 changes: 12 additions & 0 deletions internal/config/fs_test.go
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion internal/photoprism/albums.go
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down

0 comments on commit 32ef030

Please sign in to comment.