mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 18:41:59 -07:00
Don't FATAL if a repo dir cannot be created (fixes #443)
This commit is contained in:
parent
3b65a58f59
commit
135e29a3bb
@ -308,20 +308,29 @@ nextRepo:
|
|||||||
|
|
||||||
repo.Directory = expandTilde(repo.Directory)
|
repo.Directory = expandTilde(repo.Directory)
|
||||||
|
|
||||||
// Safety check. If the cached index contains files but the repository
|
fi, err := os.Stat(repo.Directory)
|
||||||
// doesn't exist, we have a problem. We would assume that all files
|
if m.LocalVersion(repo.ID) > 0 {
|
||||||
// have been deleted which might not be the case, so abort instead.
|
// Safety check. If the cached index contains files but the
|
||||||
|
// repository doesn't exist, we have a problem. We would assume
|
||||||
id := fmt.Sprintf("%x", sha1.Sum([]byte(repo.Directory)))
|
// that all files have been deleted which might not be the case,
|
||||||
idxFile := filepath.Join(confDir, id+".idx.gz")
|
// so mark it as invalid instead.
|
||||||
if _, err := os.Stat(idxFile); err == nil {
|
if err != nil || !fi.IsDir() {
|
||||||
if fi, err := os.Stat(repo.Directory); err != nil || !fi.IsDir() {
|
|
||||||
cfg.Repositories[i].Invalid = "repo directory missing"
|
cfg.Repositories[i].Invalid = "repo directory missing"
|
||||||
continue nextRepo
|
continue nextRepo
|
||||||
}
|
}
|
||||||
|
} else if os.IsNotExist(err) {
|
||||||
|
// If we don't have ny files in the index, and the directory does
|
||||||
|
// exist, try creating it.
|
||||||
|
err = os.MkdirAll(repo.Directory, 0700)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
// If there was another error or we could not create the
|
||||||
|
// directory, the repository is invalid.
|
||||||
|
cfg.Repositories[i].Invalid = err.Error()
|
||||||
|
continue nextRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureDir(repo.Directory, -1)
|
|
||||||
m.AddRepo(repo)
|
m.AddRepo(repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user