diff --git a/internal/config/filenames.go b/internal/config/filenames.go index 2bd5a8da0..0fe0b74f3 100644 --- a/internal/config/filenames.go +++ b/internal/config/filenames.go @@ -211,20 +211,38 @@ func (c *Config) CachePath() string { return fs.Abs(c.params.CachePath) } -// StoragePath returns the path for generated files. +// StoragePath returns the path for generated files like cache and index. func (c *Config) StoragePath() string { if c.params.StoragePath == "" { - if usr, _ := user.Current(); usr.HomeDir != "" { - p := filepath.Join(usr.HomeDir, fs.HiddenPath, "storage") + const dirName = "storage" - if fs.PathExists(p) { + // Default directories. + originalsDir := fs.Abs(filepath.Join(c.OriginalsPath(), fs.HiddenPath, dirName)) + storageDir := fs.Abs(dirName) + + // Find existing directories. + if fs.PathExists(originalsDir) && !c.ReadOnly() { + return originalsDir + } else if fs.PathExists(storageDir) && c.ReadOnly() { + return storageDir + } + + // Use .photoprism in home directory? + if usr, _ := user.Current(); usr.HomeDir != "" { + p := fs.Abs(filepath.Join(usr.HomeDir, fs.HiddenPath, dirName)) + + if fs.PathExists(p) || c.ReadOnly() { return p } } - if !c.ReadOnly() { - return filepath.Join(c.OriginalsPath(), fs.HiddenPath, "storage") + // Fallback directory in case nothing else works. + if c.ReadOnly() { + return fs.Abs(filepath.Join(fs.HiddenPath, dirName)) } + + // Store cache and index in "originals/.photoprism/storage". + return originalsDir } return fs.Abs(c.params.StoragePath) diff --git a/internal/config/flags.go b/internal/config/flags.go index ee23e9071..745513bfa 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -119,13 +119,13 @@ var GlobalFlags = []cli.Flag{ }, cli.StringFlag{ Name: "assets-path", - Usage: "assets `PATH` for static files", + Usage: "assets `PATH` for static files like templates and TensorFlow models", Value: "", EnvVar: "PHOTOPRISM_ASSETS_PATH", }, cli.StringFlag{ Name: "storage-path", - Usage: "storage `PATH` for generated files", + Usage: "storage `PATH` for generated files like cache and index", Value: "", EnvVar: "PHOTOPRISM_STORAGE_PATH", },