diff options
author | Jakob Borg <jakob@nym.se> | 2014-04-24 10:27:43 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-04-24 10:27:43 +0200 |
commit | 0c4e6ae7de058ecd998dc6a1a5d6210f2dc35f29 (patch) | |
tree | e0df73f9edacb096b0780b7ebcf95e216688a796 /cmd | |
parent | 65ec129dfb50895057a7f2cd69bb159e68f44a70 (diff) |
Safety: don't start if repo dir is missing (ref #154)
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/syncthing/main.go | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 9777ee3a0f..d84b626a9a 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -161,12 +161,14 @@ func main() { } else { infoln("No config file; starting with empty defaults") name, _ := os.Hostname() + defaultRepo := filepath.Join(getHomeDir(), "Sync") + ensureDir(defaultRepo, 0755) cfg, err = readConfigXML(nil, myID) cfg.Repositories = []RepositoryConfiguration{ { ID: "default", - Directory: filepath.Join(getHomeDir(), "Sync"), + Directory: defaultRepo, Nodes: []NodeConfiguration{{NodeID: myID}}, }, } @@ -219,10 +221,9 @@ func main() { m := NewModel(cfg.Options.MaxChangeKbps * 1000) - for i := range cfg.Repositories { - dir := expandTilde(cfg.Repositories[i].Directory) - ensureDir(dir, -1) - m.AddRepo(cfg.Repositories[i].ID, dir, cfg.Repositories[i].Nodes) + for _, repo := range cfg.Repositories { + dir := expandTilde(repo.Directory) + m.AddRepo(repo.ID, dir, repo.Nodes) } // GUI @@ -257,6 +258,25 @@ func main() { infoln("Populating repository index") m.LoadIndexes(confDir) + + for _, repo := range cfg.Repositories { + dir := 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. + + if files, _, _ := m.LocalSize(repo.ID); files > 0 { + if fi, err := os.Stat(dir); err != nil || !fi.IsDir() { + warnf("Configured repository %q has index but directory %q is missing; not starting.", repo.ID, repo.Directory) + fatalf("Ensure that directory is present or remove repository from configuration.") + } + } + + // Ensure that repository directories exist for newly configured repositories. + ensureDir(dir, -1) + } + m.ScanRepos() m.SaveIndexes(confDir) |