Don't FATAL if a repo dir cannot be created (fixes #443)

This commit is contained in:
Jakob Borg 2014-07-27 14:31:15 +02:00
parent 3b65a58f59
commit 135e29a3bb
1 changed files with 18 additions and 9 deletions

View File

@ -308,20 +308,29 @@ nextRepo:
repo.Directory = expandTilde(repo.Directory)
// Safety check. If the cached index contains files but the repository
// doesn't exist, we have a problem. We would assume that all files
// have been deleted which might not be the case, so abort instead.
id := fmt.Sprintf("%x", sha1.Sum([]byte(repo.Directory)))
idxFile := filepath.Join(confDir, id+".idx.gz")
if _, err := os.Stat(idxFile); err == nil {
if fi, err := os.Stat(repo.Directory); err != nil || !fi.IsDir() {
fi, err := os.Stat(repo.Directory)
if m.LocalVersion(repo.ID) > 0 {
// Safety check. If the cached index contains files but the
// repository doesn't exist, we have a problem. We would assume
// that all files have been deleted which might not be the case,
// so mark it as invalid instead.
if err != nil || !fi.IsDir() {
cfg.Repositories[i].Invalid = "repo directory missing"
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)
}