mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
commit
070eced2f6
@ -573,26 +573,26 @@ func (s *apiSvc) postSystemRestart(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *apiSvc) postSystemReset(w http.ResponseWriter, r *http.Request) {
|
||||
var qs = r.URL.Query()
|
||||
folder := qs.Get("folder")
|
||||
var err error
|
||||
if len(folder) == 0 {
|
||||
for folder := range cfg.Folders() {
|
||||
err = s.model.ResetFolder(folder)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
if len(folder) > 0 {
|
||||
if _, ok := cfg.Folders()[folder]; !ok {
|
||||
http.Error(w, "Invalid folder ID", 500)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
err = s.model.ResetFolder(folder)
|
||||
}
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
if len(folder) == 0 {
|
||||
// Reset all folders.
|
||||
for folder := range cfg.Folders() {
|
||||
s.model.ResetFolder(folder)
|
||||
}
|
||||
s.flushResponse(`{"ok": "resetting database"}`, w)
|
||||
} else {
|
||||
// Reset a specific folder, assuming it's supposed to exist.
|
||||
s.model.ResetFolder(folder)
|
||||
s.flushResponse(`{"ok": "resetting folder `+folder+`"}`, w)
|
||||
}
|
||||
|
||||
go restart()
|
||||
}
|
||||
|
||||
|
@ -1746,15 +1746,9 @@ func (m *Model) CheckFolderHealth(id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Model) ResetFolder(folder string) error {
|
||||
for _, f := range db.ListFolders(m.db) {
|
||||
if f == folder {
|
||||
l.Infof("Cleaning data for folder %q", folder)
|
||||
db.DropFolder(m.db, folder)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("Unknown folder %q", folder)
|
||||
func (m *Model) ResetFolder(folder string) {
|
||||
l.Infof("Cleaning data for folder %q", folder)
|
||||
db.DropFolder(m.db, folder)
|
||||
}
|
||||
|
||||
func (m *Model) String() string {
|
||||
|
@ -9,6 +9,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -67,17 +68,17 @@ func TestReset(t *testing.T) {
|
||||
|
||||
// Reset indexes of the default folder
|
||||
log.Println("Reset indexes of default folder")
|
||||
_, err = p.Post("/rest/system/reset?folder=default", nil)
|
||||
bs, err := p.Post("/rest/system/reset?folder=default", nil)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to reset indexes of the default folder:", err)
|
||||
t.Fatalf("Failed to reset indexes (default): %v (%s)", err, bytes.TrimSpace(bs))
|
||||
}
|
||||
|
||||
// Syncthing restarts on reset. But we set STNORESTART=1 for the tests. So
|
||||
// we wait for it to exit, then do a stop so the rc.Process is happy and
|
||||
// restart it again.
|
||||
time.Sleep(time.Second)
|
||||
checkedStop(t, p)
|
||||
p = startInstance(t, 1)
|
||||
defer checkedStop(t, p)
|
||||
|
||||
m, err = p.Model("default")
|
||||
if err != nil {
|
||||
@ -108,17 +109,14 @@ func TestReset(t *testing.T) {
|
||||
|
||||
// Reset all indexes
|
||||
log.Println("Reset DB...")
|
||||
_, err = p.Post("/rest/system/reset?folder=default", nil)
|
||||
bs, err = p.Post("/rest/system/reset", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to reset indexes", err)
|
||||
t.Fatalf("Failed to reset indexes (all): %v (%s)", err, bytes.TrimSpace(bs))
|
||||
}
|
||||
|
||||
// Syncthing restarts on reset. But we set STNORESTART=1 for the tests. So
|
||||
// we wait for it to exit, then do a stop so the rc.Process is happy and
|
||||
// restart it again.
|
||||
// we wait for it to exit, then restart it again.
|
||||
time.Sleep(time.Second)
|
||||
checkedStop(t, p)
|
||||
|
||||
p = startInstance(t, 1)
|
||||
defer checkedStop(t, p)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user