mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
Need config available for -reset (fixes #1111)
This commit is contained in:
parent
d452b7593f
commit
0cc815d816
@ -846,6 +846,17 @@ func renewUPnP(port int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resetFolders() {
|
func resetFolders() {
|
||||||
|
confDir, err := osutil.ExpandTilde(confDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgFile := filepath.Join(confDir, "config.xml")
|
||||||
|
cfg, err := config.Load(cfgFile, myID)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
suffix := fmt.Sprintf(".syncthing-reset-%d", time.Now().UnixNano())
|
suffix := fmt.Sprintf(".syncthing-reset-%d", time.Now().UnixNano())
|
||||||
for _, folder := range cfg.Folders() {
|
for _, folder := range cfg.Folders() {
|
||||||
if _, err := os.Stat(folder.Path); err == nil {
|
if _, err := os.Stat(folder.Path); err == nil {
|
||||||
|
1
test/.gitignore
vendored
1
test/.gitignore
vendored
@ -16,3 +16,4 @@ csrftokens.txt
|
|||||||
s4d
|
s4d
|
||||||
http
|
http
|
||||||
index
|
index
|
||||||
|
*.syncthing-reset*
|
||||||
|
56
test/cli_test.go
Normal file
56
test/cli_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright (C) 2014 The Syncthing Authors.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU General Public License as published by the Free
|
||||||
|
// Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
// any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
// more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// +build integration
|
||||||
|
|
||||||
|
package integration_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCLIReset(t *testing.T) {
|
||||||
|
dirs := []string{"s1", "s12-1", "h1/index"}
|
||||||
|
|
||||||
|
// Create directories that reset will remove
|
||||||
|
|
||||||
|
for _, dir := range dirs {
|
||||||
|
err := os.Mkdir(dir, 0755)
|
||||||
|
if err != nil && !os.IsExist(err) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run reset to clean up
|
||||||
|
|
||||||
|
cmd := exec.Command("../bin/syncthing", "-home", "h1", "-reset")
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stdout
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that they're gone
|
||||||
|
|
||||||
|
for _, dir := range dirs {
|
||||||
|
_, err := os.Stat(dir)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("%s still exists", dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user