Fix path errors with JsonDB
This commit is contained in:
parent
4cc50e86c9
commit
98dc41aa0a
|
@ -164,10 +164,11 @@ func (db *DB) ListAll(path string) ([]string, error) {
|
||||||
func (db *DB) makePath(path string) error {
|
func (db *DB) makePath(path string) error {
|
||||||
parts := strings.Split(path, string(filepath.Separator))
|
parts := strings.Split(path, string(filepath.Separator))
|
||||||
parts = parts[:len(parts)-1] // pop off the filename
|
parts = parts[:len(parts)-1] // pop off the filename
|
||||||
directory, err := filepath.Abs(filepath.Join(parts...))
|
var directory string
|
||||||
if err != nil {
|
if path[0] == '/' {
|
||||||
log.Error("[JsonDB] Couldn't get abs path to %s", path)
|
directory = "/" + filepath.Join(parts...)
|
||||||
return err
|
} else {
|
||||||
|
directory = filepath.Join(parts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(directory); err != nil {
|
if _, err := os.Stat(directory); err != nil {
|
||||||
|
@ -240,5 +241,9 @@ func (db *DB) writeJSON(path string, v interface{}) error {
|
||||||
|
|
||||||
// toPath translates a document name into a filesystem path.
|
// toPath translates a document name into a filesystem path.
|
||||||
func (db *DB) toPath(document string) string {
|
func (db *DB) toPath(document string) string {
|
||||||
return filepath.Join(db.Root, document+".json")
|
path, err := filepath.Abs(filepath.Join(db.Root, document+".json"))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("[JsonDB] toPath error: %s", err)
|
||||||
|
}
|
||||||
|
return path
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user