lib, gui: Default ignores for new folders (fixes #7428) (#7530)

This commit is contained in:
Simon Frei
2022-01-13 23:38:21 +01:00
committed by GitHub
parent 40bb52fdd8
commit 21d04b895a
17 changed files with 718 additions and 218 deletions
+36
View File
@@ -7,8 +7,12 @@
package cli
import (
"bufio"
"fmt"
"path/filepath"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/fs"
"github.com/urfave/cli"
)
@@ -38,6 +42,12 @@ var operationCommand = cli.Command{
ArgsUsage: "[folder id]",
Action: expects(1, foldersOverride),
},
{
Name: "default-ignores",
Usage: "Set the default ignores (config) from a file",
ArgsUsage: "path",
Action: expects(1, setDefaultIgnores),
},
},
}
@@ -74,3 +84,29 @@ func foldersOverride(c *cli.Context) error {
}
return fmt.Errorf("Folder " + rid + " not found")
}
func setDefaultIgnores(c *cli.Context) error {
client, err := getClientFactory(c).getClient()
if err != nil {
return err
}
dir, file := filepath.Split(c.Args()[0])
filesystem := fs.NewFilesystem(fs.FilesystemTypeBasic, dir)
fd, err := filesystem.Open(file)
if err != nil {
return err
}
scanner := bufio.NewScanner(fd)
var lines []string
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
fd.Close()
if err := scanner.Err(); err != nil {
return err
}
_, err = client.PutJSON("config/defaults/ignores", config.Ignores{Lines: lines})
return err
}