Skip to content

Commit d48db6c

Browse files
committed
Sync: Prevent downloads when read-only mode is enabled
Signed-off-by: Michael Mayer <michael@photoprism.app>
1 parent 163398b commit d48db6c

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

internal/workers/sync_download.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/dustin/go-humanize/english"
8+
79
"github.com/photoprism/photoprism/internal/entity"
810
"github.com/photoprism/photoprism/internal/event"
911
"github.com/photoprism/photoprism/internal/get"
1012
"github.com/photoprism/photoprism/internal/mutex"
1113
"github.com/photoprism/photoprism/internal/photoprism"
1214
"github.com/photoprism/photoprism/internal/query"
1315
"github.com/photoprism/photoprism/internal/remote/webdav"
16+
"github.com/photoprism/photoprism/pkg/clean"
1417
"github.com/photoprism/photoprism/pkg/fs"
1518
)
1619

@@ -68,12 +71,21 @@ func (w *Sync) download(a entity.Service) (complete bool, err error) {
6871
return false, err
6972
}
7073

71-
if len(relatedFiles) == 0 {
72-
log.Infof("sync: download complete for %s", a.AccName)
74+
// Check if files must and can be downloaded.
75+
if l := len(relatedFiles); l == 0 {
76+
log.Infof("sync: no files to download from %s", clean.Log(a.AccName))
7377
event.Publish("sync.downloaded", event.Data{"account": a})
7478
return true, nil
79+
} else if w.conf.ReadOnly() {
80+
err = fmt.Errorf("failed to download %s from %s because read-only mode is enabled",
81+
english.Plural(l, "file", "files"),
82+
clean.Log(a.AccName))
83+
log.Errorf("sync: %s", err)
84+
event.Publish("sync.downloaded", event.Data{"account": a, "error": err.Error()})
85+
return true, nil
7586
}
7687

88+
// Display log message.
7789
log.Infof("sync: downloading from %s", a.AccName)
7890

7991
client, err := webdav.NewClient(a.AccURL, a.AccUser, a.AccPass, webdav.Timeout(a.AccTimeout))

0 commit comments

Comments
 (0)