main.go 1020 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (C) 2018 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. // Commmand stfindignored lists ignored files under a given folder root.
  7. package main
  8. import (
  9. "flag"
  10. "fmt"
  11. "os"
  12. "github.com/syncthing/syncthing/lib/fs"
  13. "github.com/syncthing/syncthing/lib/ignore"
  14. )
  15. func main() {
  16. flag.Parse()
  17. root := flag.Arg(0)
  18. if root == "" {
  19. root = "."
  20. }
  21. vfs := fs.NewWalkFilesystem(fs.NewFilesystem(fs.FilesystemTypeBasic, root))
  22. ign := ignore.New(vfs)
  23. if err := ign.Load(".stignore"); err != nil {
  24. fmt.Fprintf(os.Stderr, "Fatal: loading ignores: %v\n", err)
  25. os.Exit(1)
  26. }
  27. vfs.Walk(".", func(path string, info fs.FileInfo, err error) error {
  28. if err != nil {
  29. fmt.Fprintf(os.Stderr, "Warning: %s: %v\n", path, err)
  30. return fs.SkipDir
  31. }
  32. if ign.Match(path).IsIgnored() {
  33. fmt.Println(path)
  34. }
  35. return nil
  36. })
  37. }