forked from twpayne/chezmoi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmanaged.go
47 lines (42 loc) · 941 Bytes
/
unmanaged.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cmd
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/spf13/cobra"
vfs "github.com/twpayne/go-vfs"
)
var unmanagedCmd = &cobra.Command{
Use: "unmanaged",
Args: cobra.NoArgs,
Short: "List the unmanaged files in the destination directory",
RunE: makeRunE(config.runUnmanagedCmd),
}
func init() {
rootCmd.AddCommand(unmanagedCmd)
}
func (c *Config) runUnmanagedCmd(fs vfs.FS, args []string) error {
ts, err := c.getTargetState(fs)
if err != nil {
return err
}
return vfs.Walk(fs, c.DestDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if path == c.DestDir {
return nil
}
entry, _ := ts.Get(path)
managed := entry != nil
ignored := ts.TargetIgnore.Match(strings.TrimPrefix(path, c.DestDir+"/"))
if !managed && !ignored {
fmt.Println(path)
}
if info.IsDir() && (!managed || ignored) {
return filepath.SkipDir
}
return nil
})
}