From 135e29a3bb61c248fd71bcc717865d69c131e1d6 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 27 Jul 2014 14:31:15 +0200 Subject: [PATCH] Don't FATAL if a repo dir cannot be created (fixes #443) --- cmd/syncthing/main.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index b66b1f6d..8d61b6fb 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -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) }