diff options
author | Jakob Borg <jakob@nym.se> | 2014-04-03 22:10:51 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-04-03 22:10:51 +0200 |
commit | d30a286f38ebc2a84dc0c82e89247a5ab89fc7b1 (patch) | |
tree | 77a6beaf1b9ab05e2320621194b7a51ccb18a9e5 | |
parent | 15699a39cf8528b0ef3b970cb38adf64e99522d5 (diff) |
Command line flag and REST command to reset and resync (fixes #85)
Still needs implemention in GUI
-rw-r--r-- | cmd/syncthing/gui.go | 8 | ||||
-rw-r--r-- | cmd/syncthing/main.go | 26 |
2 files changed, 33 insertions, 1 deletions
diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index a9e7399932..4ca6285ae9 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -38,6 +38,7 @@ func startGUI(addr string, m *Model) { router.Post("/rest/config", restPostConfig) router.Post("/rest/restart", restPostRestart) + router.Post("/rest/reset", restPostReset) router.Post("/rest/error", restPostError) go func() { @@ -112,7 +113,12 @@ func restGetConfigInSync(w http.ResponseWriter) { } func restPostRestart(req *http.Request) { - restart() + go restart() +} + +func restPostReset(req *http.Request) { + resetRepositories() + go restart() } type guiFile scanner.File diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index da152295ca..445dc3ac00 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -59,8 +59,10 @@ const ( ) func main() { + var reset bool var showVersion bool flag.StringVar(&confDir, "home", getDefaultConfDir(), "Set configuration directory") + flag.BoolVar(&reset, "reset", false, "Prepare to resync from cluster") flag.BoolVar(&showVersion, "version", false, "Show version") flag.Usage = usageFor(flag.CommandLine, usage, extraUsage) flag.Parse() @@ -163,6 +165,11 @@ func main() { infof("Edit %s to taste or use the GUI\n", cfgFile) } + if reset { + resetRepositories() + os.Exit(0) + } + if profiler := os.Getenv("STPROFILER"); len(profiler) > 0 { go func() { dlog.Println("Starting profiler on", profiler) @@ -260,6 +267,25 @@ func main() { select {} } +func resetRepositories() { + suffix := fmt.Sprintf(".syncthing-reset-%d", time.Now().UnixNano()) + for _, repo := range cfg.Repositories { + if _, err := os.Stat(repo.Directory); err == nil { + infof("Reset: Moving %s -> %s", repo.Directory, repo.Directory+suffix) + os.Rename(repo.Directory, repo.Directory+suffix) + } + } + + pat := filepath.Join(confDir, "*.idx.gz") + idxs, err := filepath.Glob(pat) + if err == nil { + for _, idx := range idxs { + infof("Reset: Removing %s", idx) + os.Remove(idx) + } + } +} + func restart() { infoln("Restarting") if os.Getenv("SMF_FMRI") != "" || os.Getenv("STNORESTART") != "" { |