Backend: Improve startup error messages #194

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-01-21 13:59:41 +01:00
parent a50d1b5d07
commit 5fd454b856
2 changed files with 26 additions and 16 deletions

View file

@ -5,11 +5,12 @@ import (
"github.com/photoprism/photoprism/internal/commands" "github.com/photoprism/photoprism/internal/commands"
"github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/internal/config"
log "github.com/sirupsen/logrus" "github.com/photoprism/photoprism/internal/event"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
var version = "development" var version = "development"
var log = event.Log
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()

View file

@ -1,6 +1,7 @@
package config package config
import ( import (
"fmt"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -26,50 +27,58 @@ func findExecutable(configBin, defaultBin string) (result string) {
return result return result
} }
// CreateDirectories creates all the folders that photoprism needs. These are: // CreateDirectories creates directories for storing photos, metadata and cache files.
// OriginalsPath
// ThumbnailsPath
// ImportPath
// ExportPath
func (c *Config) CreateDirectories() error { func (c *Config) CreateDirectories() error {
createError := func(path string, err error) (result error) {
if fs.FileExists(path) {
result = fmt.Errorf("\"%s\" is a file, not a directory: please check your configuration", path)
} else {
result = fmt.Errorf("can't create \"%s\": please check configuration and permissions", path)
}
log.Debug(err)
return result
}
if err := os.MkdirAll(c.OriginalsPath(), os.ModePerm); err != nil { if err := os.MkdirAll(c.OriginalsPath(), os.ModePerm); err != nil {
return err return createError(c.OriginalsPath(), err)
} }
if err := os.MkdirAll(c.ImportPath(), os.ModePerm); err != nil { if err := os.MkdirAll(c.ImportPath(), os.ModePerm); err != nil {
return err return createError(c.ImportPath(), err)
} }
if err := os.MkdirAll(c.ExportPath(), os.ModePerm); err != nil { if err := os.MkdirAll(c.ExportPath(), os.ModePerm); err != nil {
return err return createError(c.ExportPath(), err)
} }
if err := os.MkdirAll(c.ThumbnailsPath(), os.ModePerm); err != nil { if err := os.MkdirAll(c.ThumbnailsPath(), os.ModePerm); err != nil {
return err return createError(c.ThumbnailsPath(), err)
} }
if err := os.MkdirAll(c.ResourcesPath(), os.ModePerm); err != nil { if err := os.MkdirAll(c.ResourcesPath(), os.ModePerm); err != nil {
return err return createError(c.ResourcesPath(), err)
} }
if err := os.MkdirAll(c.SqlServerPath(), os.ModePerm); err != nil { if err := os.MkdirAll(c.SqlServerPath(), os.ModePerm); err != nil {
return err return createError(c.SqlServerPath(), err)
} }
if err := os.MkdirAll(c.TensorFlowModelPath(), os.ModePerm); err != nil { if err := os.MkdirAll(c.TensorFlowModelPath(), os.ModePerm); err != nil {
return err return createError(c.TensorFlowModelPath(), err)
} }
if err := os.MkdirAll(c.HttpStaticBuildPath(), os.ModePerm); err != nil { if err := os.MkdirAll(c.HttpStaticBuildPath(), os.ModePerm); err != nil {
return err return createError(c.HttpStaticBuildPath(), err)
} }
if err := os.MkdirAll(filepath.Dir(c.PIDFilename()), os.ModePerm); err != nil { if err := os.MkdirAll(filepath.Dir(c.PIDFilename()), os.ModePerm); err != nil {
return err return createError(filepath.Dir(c.PIDFilename()), err)
} }
if err := os.MkdirAll(filepath.Dir(c.LogFilename()), os.ModePerm); err != nil { if err := os.MkdirAll(filepath.Dir(c.LogFilename()), os.ModePerm); err != nil {
return err return createError(filepath.Dir(c.LogFilename()), err)
} }
return nil return nil