Debian Codegraph @

tools/dir_walker.go

raw symbols SCIP
1 package toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/
2
3 import (
4 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
5 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
6
7 "github.com/git-lfs/git-lfs/v3/errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/"
8 "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/"
9 )
10
11 var (
12 errInvalidDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/errInvalidDir. = errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("invalid directory"))
13 errNotDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/errNotDir. = errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("not a directory"))
14 )
15
16 type DirWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker# struct {
17 parentPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#parentPath. string
18 pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path. string
19 configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#config. repositoryPermissionFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#
20 }
21
22 // The parentPath parameter is assumed to be a valid path to a directory
23 // in the filesystem.
24 //
25 // The filePath parameter must be a relative file path as provided by Git,
26 // with only the "/" character as a separator and no empty or "." or ".."
27 // path segments. Absolute paths are not supported.
28 func NewDirWalkerForFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewDirWalkerForFile().(parentPath string, filePath string, config repositoryPermissionFetcherscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/repositoryPermissionFetcher#) *DirWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker# {
29 var path string
30 i := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.LastIndexBytescip-go gomod github.com/golang/go/src go1.25.0 strings/LastIndexByte().(filePath, '/')
31 if i >= 0 {
32 path = filePath[0:i]
33 }
34
35 return &DirWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#{
36 parentPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#parentPath.: parentPath,
37 pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path.: path,
38 configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#config.: config,
39 }
40 }
41
42 // walk() checks each directory in a relative path, starting from the
43 // initial parent path, and optionally creates any missing directories
44 // in the path.
45 //
46 // If an existing file or something else other than a directory conflicts
47 // with a directory in the path, walk() returns an error.
48 //
49 // If the create option is false, walk() returns ErrNotExist when a
50 // directory is not found.
51 //
52 // Note that for performance reasons and to be consistent with Git's
53 // implementation, walk() does not guard against TOCTOU (time-of-check/
54 // time-of-use) races, as the methods of the os.Root type do.
55 func (w *DirWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#) walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#walk().(create bool) error {
56 currentPath := w.parentPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#parentPath.
57
58 n := len(w.pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path.)
59 for n > 0 {
60 currentDir := w.pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path.
61 nextDirIndex := n
62 i := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.IndexBytescip-go gomod github.com/golang/go/src go1.25.0 strings/IndexByte().(w.pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path., '/')
63 if i >= 0 {
64 currentDir = w.pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path.[0:i]
65 nextDirIndex = i + 1
66 }
67
68 // These should never occur in Git paths.
69 if currentDir == "" || currentDir == "." || currentDir == ".." {
70 return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Joinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Join().(errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("invalid directory %q in path: %q", currentDir, w.pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path.)), errInvalidDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/errInvalidDir.)
71 }
72
73 if currentPath == "" {
74 currentPath = currentDir
75 } else {
76 currentPath += "/" + currentDir
77 }
78
79 stat, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Lstatscip-go gomod github.com/golang/go/src go1.25.0 os/Lstat().(currentPath)
80 if err != nil {
81 if !osscip-go gomod github.com/golang/go/src go1.25.0 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/IsNotExist().(err) || !create {
82 return err
83 }
84
85 err = Mkdirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/Mkdir().(currentPath, w.configscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#config.)
86 if err != nil {
87 return err
88 }
89 } else if !stat.Modescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#Mode().().IsDirscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileMode#IsDir().() {
90 return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Joinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Join().(errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Newscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("not a directory: %q", currentPath)), errNotDirscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/errNotDir.)
91 }
92
93 w.parentPathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#parentPath. = currentPath
94 w.pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path. = w.pathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#path.[nextDirIndex:]
95 n -= nextDirIndex
96 }
97
98 return nil
99 }
100
101 func (w *DirWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#) Walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#Walk().() error {
102 return w.walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#walk().(false)
103 }
104
105 func (w *DirWalkerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#) WalkAndCreatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#WalkAndCreate().() error {
106 return w.walkscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/DirWalker#walk().(true)
107 }