main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. // Command 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/automaxprocs"
  13. "github.com/syncthing/syncthing/lib/fs"
  14. "github.com/syncthing/syncthing/lib/ignore"
  15. )
  16. func main() {
  17. flag.Parse()
  18. root := flag.Arg(0)
  19. if root == "" {
  20. root = "."
  21. }
  22. vfs := fs.NewWalkFilesystem(fs.NewFilesystem(fs.FilesystemTypeBasic, root))
  23. ign := ignore.New(vfs)
  24. if err := ign.Load(".stignore"); err != nil {
  25. fmt.Fprintf(os.Stderr, "Fatal: loading ignores: %v\n", err)
  26. os.Exit(1)
  27. }
  28. vfs.Walk(".", func(path string, info fs.FileInfo, err error) error {
  29. if err != nil {
  30. fmt.Fprintf(os.Stderr, "Warning: %s: %v\n", path, err)
  31. return fs.SkipDir
  32. }
  33. if ign.Match(path).IsIgnored() {
  34. fmt.Println(path)
  35. }
  36. return nil
  37. })
  38. }