Local storage ensures its directories exist
This commit is contained in:
parent
74fd90c850
commit
a045104016
@ -14,6 +14,17 @@ type LocalStorage struct {
|
|||||||
tmpSubdir string
|
tmpSubdir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ensureDirExists(dir string) error {
|
||||||
|
_, err := os.Lstat(dir)
|
||||||
|
if err != nil {
|
||||||
|
fi, err := os.Lstat(path.Dir(dir))
|
||||||
|
if err != nil { return err }
|
||||||
|
err = os.Mkdir(dir, fi.Mode().Perm())
|
||||||
|
if err != nil { return err }
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func NewLocalStorage(config *conf.ConfigFile) (*LocalStorage, error) {
|
func NewLocalStorage(config *conf.ConfigFile) (*LocalStorage, error) {
|
||||||
storageDir, err := config.GetString("storage", "dir")
|
storageDir, err := config.GetString("storage", "dir")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -23,6 +34,13 @@ func NewLocalStorage(config *conf.ConfigFile) (*LocalStorage, error) {
|
|||||||
ls := new(LocalStorage)
|
ls := new(LocalStorage)
|
||||||
ls.storageDir = storageDir
|
ls.storageDir = storageDir
|
||||||
ls.tmpSubdir = path.Join(storageDir, ".asink-tmpdir")
|
ls.tmpSubdir = path.Join(storageDir, ".asink-tmpdir")
|
||||||
|
|
||||||
|
//make sure the base directory and tmp subdir exist
|
||||||
|
err = ensureDirExists(ls.storageDir)
|
||||||
|
if err != nil { return nil, err}
|
||||||
|
err = ensureDirExists(ls.tmpSubdir)
|
||||||
|
if err != nil { return nil, err}
|
||||||
|
|
||||||
return ls, nil
|
return ls, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user