Skip to content

Commit 8a66ca2

Browse files
authored
Merge pull request #95 from babarot/babarot/forbidden-paths
Make forbidden paths configurable
2 parents da44e9f + c225f37 commit 8a66ca2

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ core:
169169

170170
home_fallback: true # If true, fallbacks to home trash when external trash fails
171171

172+
forbidden_paths: # List of paths that cannot be moved to trash for safety
173+
- "$HOME/.local/share/Trash"
174+
- "$HOME/.trash"
175+
- "$XDG_DATA_HOME/Trash"
176+
- "/tmp/Trash"
177+
- "/var/tmp/Trash"
178+
- "$HOME/.gomi"
179+
- "/"
180+
- "/etc"
181+
- "/usr"
182+
- "/var"
183+
- "/bin"
184+
- "/sbin"
185+
- "/lib"
186+
- "/lib64"
187+
172188
restore:
173189
confirm: false # If true, prompts for confirmation before restoring (yes/no)
174190
verbose: true # If true, displays detailed restoration information

internal/cli/put.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,6 @@ import (
1313
"golang.org/x/sync/errgroup"
1414
)
1515

16-
// List of forbidden paths that cannot be moved to trash
17-
var forbiddenPaths = []string{
18-
// Default trash-related paths
19-
"$HOME/.local/share/Trash",
20-
"$HOME/.trash",
21-
"$XDG_DATA_HOME/Trash",
22-
"/tmp/Trash",
23-
"/var/tmp/Trash",
24-
25-
// gomi dir
26-
"$HOME/.gomi",
27-
28-
// Critical system directories
29-
"/",
30-
"/etc",
31-
"/usr",
32-
"/var",
33-
"/bin",
34-
"/sbin",
35-
"/lib",
36-
"/lib64",
37-
}
38-
3916
// Put moves files to trash
4017
func (c *CLI) Put(args []string) error {
4118
slog.Debug("cli.put started")
@@ -80,7 +57,7 @@ func (c *CLI) processFile(arg string, failed *syncStringSlice) error {
8057
}
8158

8259
// Check for forbidden paths
83-
if isForbiddenPath(expandedPath) {
60+
if c.isForbiddenPath(expandedPath) {
8461
failed.Append(arg)
8562
return fmt.Errorf("refusing to remove forbidden path: %q", arg)
8663
}
@@ -161,10 +138,10 @@ func expandPath(path string) (string, error) {
161138
}
162139

163140
// isForbiddenPath checks if the given path is in the forbidden paths list
164-
func isForbiddenPath(path string) bool {
141+
func (c *CLI) isForbiddenPath(path string) bool {
165142
path = filepath.Clean(path)
166143

167-
for _, forbiddenPath := range forbiddenPaths {
144+
for _, forbiddenPath := range c.config.Core.Trash.ForbiddenPaths {
168145
// Expand forbidden path with environment variables
169146
expandedForbiddenPath := os.ExpandEnv(forbiddenPath)
170147
expandedForbiddenPath = filepath.Clean(expandedForbiddenPath)

internal/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type TrashConfig struct {
5151

5252
// GomiDir specifies the trash directory for legacy mode
5353
GomiDir string `yaml:"gomi_dir" validate:"omitempty,validDirPath"`
54+
55+
// List of forbidden paths that cannot be moved to trash
56+
ForbiddenPaths []string `yaml:"forbidden_paths"`
5457
}
5558

5659
// RestoreConfig defines settings for file restoration behavior

internal/config/defaults.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ func NewDefaultConfig() *Config {
1616
Strategy: "auto",
1717
HomeFallback: true,
1818
GomiDir: filepath.Join(homedir, ".gomi"),
19+
ForbiddenPaths: []string{
20+
// Default trash-related paths
21+
"$HOME/.local/share/Trash",
22+
"$HOME/.trash",
23+
"$XDG_DATA_HOME/Trash",
24+
"/tmp/Trash",
25+
"/var/tmp/Trash",
26+
// gomi dir
27+
"$HOME/.gomi",
28+
// Critical system directories
29+
"/",
30+
"/etc",
31+
"/usr",
32+
"/var",
33+
"/bin",
34+
"/sbin",
35+
"/lib",
36+
"/lib64",
37+
},
1938
},
2039
Restore: RestoreConfig{
2140
Confirm: true,

0 commit comments

Comments
 (0)