Improve storage path auto-configuration #66
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
1d8e7f1ad3
commit
4684f66298
|
@ -211,20 +211,38 @@ func (c *Config) CachePath() string {
|
||||||
return fs.Abs(c.params.CachePath)
|
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 {
|
func (c *Config) StoragePath() string {
|
||||||
if c.params.StoragePath == "" {
|
if c.params.StoragePath == "" {
|
||||||
if usr, _ := user.Current(); usr.HomeDir != "" {
|
const dirName = "storage"
|
||||||
p := filepath.Join(usr.HomeDir, fs.HiddenPath, "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
|
return p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.ReadOnly() {
|
// Fallback directory in case nothing else works.
|
||||||
return filepath.Join(c.OriginalsPath(), fs.HiddenPath, "storage")
|
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)
|
return fs.Abs(c.params.StoragePath)
|
||||||
|
|
|
@ -119,13 +119,13 @@ var GlobalFlags = []cli.Flag{
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "assets-path",
|
Name: "assets-path",
|
||||||
Usage: "assets `PATH` for static files",
|
Usage: "assets `PATH` for static files like templates and TensorFlow models",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "PHOTOPRISM_ASSETS_PATH",
|
EnvVar: "PHOTOPRISM_ASSETS_PATH",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "storage-path",
|
Name: "storage-path",
|
||||||
Usage: "storage `PATH` for generated files",
|
Usage: "storage `PATH` for generated files like cache and index",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "PHOTOPRISM_STORAGE_PATH",
|
EnvVar: "PHOTOPRISM_STORAGE_PATH",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user