| 1 | package fsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.21 context/" |
| 5 | "osscip-go gomod github.com/golang/go/src go1.21 os/" |
| 6 | "pathscip-go gomod github.com/golang/go/src go1.21 path/" |
| 7 | "path/filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/" |
| 8 | "runtimescip-go gomod github.com/golang/go/src go1.21 runtime/" |
| 9 | "slicesscip-go gomod github.com/golang/go/src go1.21 slices/" |
| 10 | "stringsscip-go gomod github.com/golang/go/src go1.21 strings/" |
| 11 | "syncscip-go gomod github.com/golang/go/src go1.21 sync/" |
| 12 | "timescip-go gomod github.com/golang/go/src go1.21 time/" |
| 13 | |
| 14 | "github.com/containerd/continuity/fsscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/" |
| 15 | "github.com/moby/patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/" |
| 16 | "github.com/pkg/errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/" |
| 17 | modescip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/ "github.com/tonistiigi/dchapes-modescip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/" |
| 18 | "github.com/tonistiigi/fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/" |
| 19 | ) |
| 20 | |
| 21 | const defaultDirectoryModescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/defaultDirectoryMode. = 0755 |
| 22 | |
| 23 | var bufferPoolscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/bufferPool. = &syncscip-go gomod github.com/golang/go/src go1.21 sync/.Poolscip-go gomod github.com/golang/go/src go1.21 sync/Pool#{ |
| 24 | Newscip-go gomod github.com/golang/go/src go1.21 sync/Pool#New.: func() interface{} { |
| 25 | buffer := make([]byte, 32*1024) |
| 26 | return &buffer |
| 27 | }, |
| 28 | } |
| 29 | |
| 30 | func rootPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/rootPath().(root, p string, followLinks bool) (string, error) { |
| 31 | p = filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().("/", p) |
| 32 | if p == "/" { |
| 33 | return root, nil |
| 34 | } |
| 35 | if followLinks { |
| 36 | return fsscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/.RootPathscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/RootPath().(root, p) |
| 37 | } |
| 38 | d, f := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Splitscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Split().(p) |
| 39 | ppath, err := fsscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/.RootPathscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/RootPath().(root, d) |
| 40 | if err != nil { |
| 41 | return "", err |
| 42 | } |
| 43 | return filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(ppath, f), nil |
| 44 | } |
| 45 | |
| 46 | func ResolveWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/ResolveWildcards().(root, src string, followLinks bool) ([]string, error) { |
| 47 | d1, d2 := splitWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/splitWildcards().(src) |
| 48 | if d2 != "" { |
| 49 | p, err := rootPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/rootPath().(root, d1, followLinks) |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | matches, err := resolveWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/resolveWildcards().(p, d2) |
| 54 | if err != nil { |
| 55 | return nil, err |
| 56 | } |
| 57 | for i, m := range matches { |
| 58 | p, err := relscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/rel().(root, m) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | matches[i] = p |
| 63 | } |
| 64 | return matches, nil |
| 65 | } |
| 66 | return []string{d1}, nil |
| 67 | } |
| 68 | |
| 69 | // Copy copies files using `cp -a` semantics. |
| 70 | // Copy is likely unsafe to be used in non-containerized environments. |
| 71 | func Copyscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Copy().(ctx contextscip-go gomod github.com/golang/go/src go1.21 context/.Contextscip-go gomod github.com/golang/go/src go1.21 context/Context#, srcRoot, src, dstRoot, dst string, opts ...Optscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Opt#) error { |
| 72 | var ci CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo# |
| 73 | for _, o := range opts { |
| 74 | o(&ci) |
| 75 | } |
| 76 | ensureDstPath := dst |
| 77 | if d, f := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Splitscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Split().(dst); f != "" && f != "." { |
| 78 | ensureDstPath = d |
| 79 | } |
| 80 | if ensureDstPath != "" { |
| 81 | ensureDstPath, err := fsscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/.RootPathscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/RootPath().(dstRoot, ensureDstPath) |
| 82 | if err != nil { |
| 83 | return err |
| 84 | } |
| 85 | perm := defaultDirectoryModescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/defaultDirectoryMode. |
| 86 | if ci.Modescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Mode. != nil { |
| 87 | perm = *ci.Modescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Mode. |
| 88 | } |
| 89 | if createdDirs, err := MkdirAllscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/MkdirAll().(ensureDstPath, osscip-go gomod github.com/golang/go/src go1.21 os/.FileModescip-go gomod github.com/golang/go/src go1.21 os/FileMode#(perm), ci.Chownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Chown., ci.Utimescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Utime.); err != nil { |
| 90 | return err |
| 91 | } else { |
| 92 | defer fixCreatedParentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/fixCreatedParentDirs().(createdDirs, ci.Utimescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Utime.) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | var modeSet *modescip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/.Setscip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/Set# |
| 97 | if ci.ModeStrscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ModeStr. != "" { |
| 98 | ms, err := modescip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/.ParseWithUmaskscip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/ParseWithUmask().(ci.ModeStrscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ModeStr., 0) |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | modeSet = &ms |
| 103 | } |
| 104 | |
| 105 | dst, err := fsscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/.RootPathscip-go gomod github.com/containerd/continuity v0.4.1 `github.com/containerd/continuity/fs`/RootPath().(dstRoot, filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Clean().(dst)) |
| 106 | if err != nil { |
| 107 | return err |
| 108 | } |
| 109 | |
| 110 | c, err := newCopierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/newCopier().(dstRoot, ci.Chownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Chown., ci.Utimescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Utime., ci.Modescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Mode., modeSet, ci.XAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#XAttrErrorHandler., ci.IncludePatternsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#IncludePatterns., ci.ExcludePatternsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ExcludePatterns., ci.AlwaysReplaceExistingDestPathsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#AlwaysReplaceExistingDestPaths., ci.ChangeFuncscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ChangeFunc.) |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | c.testHookLstatscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#testHookLstat. = ci.testHookLstatscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#testHookLstat. |
| 115 | srcs := []string{src} |
| 116 | |
| 117 | if ci.AllowWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#AllowWildcards. { |
| 118 | matches, err := ResolveWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/ResolveWildcards().(srcRoot, src, ci.FollowLinksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#FollowLinks.) |
| 119 | if err != nil { |
| 120 | return err |
| 121 | } |
| 122 | if len(matches) == 0 { |
| 123 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Errorfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Errorf().("no matches found: %s", src) |
| 124 | } |
| 125 | srcs = matches |
| 126 | } |
| 127 | |
| 128 | for _, src := range srcs { |
| 129 | srcFollowed, err := rootPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/rootPath().(srcRoot, src, ci.FollowLinksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#FollowLinks.) |
| 130 | if err != nil { |
| 131 | return err |
| 132 | } |
| 133 | dst, createdDirs, err := c.prepareTargetDirscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#prepareTargetDir().(srcFollowed, src, dst, ci.CopyDirContentsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#CopyDirContents.) |
| 134 | if err != nil { |
| 135 | return err |
| 136 | } |
| 137 | defer fixCreatedParentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/fixCreatedParentDirs().(createdDirs, ci.Utimescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Utime.) |
| 138 | if err := c.copyscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#copy().(ctx, srcFollowed, "", dst, false, patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#{}, patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#{}); err != nil { |
| 139 | return err |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return nil |
| 144 | } |
| 145 | |
| 146 | func (c *copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#) prepareTargetDirscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#prepareTargetDir().(srcFollowed, src, destPath string, copyDirContents bool) (string, []string, error) { |
| 147 | fiSrc, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Lstatscip-go gomod github.com/golang/go/src go1.21 os/Lstat().(srcFollowed) |
| 148 | if err != nil { |
| 149 | return "", nil, err |
| 150 | } |
| 151 | |
| 152 | fiDest, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Statscip-go gomod github.com/golang/go/src go1.21 os/Stat().(destPath) |
| 153 | if err != nil { |
| 154 | if !osscip-go gomod github.com/golang/go/src go1.21 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.21 os/IsNotExist().(err) { |
| 155 | return "", nil, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to lstat destination path") |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | if (!copyDirContents && fiSrc.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() && fiDest != nil) || (!fiSrc.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() && fiDest != nil && fiDest.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().()) { |
| 160 | destPath = filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(destPath, filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Base().(src)) |
| 161 | } |
| 162 | |
| 163 | target := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Dir().(destPath) |
| 164 | |
| 165 | if copyDirContents && fiSrc.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() && fiDest == nil { |
| 166 | target = destPath |
| 167 | } |
| 168 | var createdDirs []string |
| 169 | mode := defaultDirectoryModescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/defaultDirectoryMode. |
| 170 | if c.modescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#mode. != nil { |
| 171 | mode = *c.modescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#mode. |
| 172 | } |
| 173 | if dirs, err := MkdirAllscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/MkdirAll().(target, osscip-go gomod github.com/golang/go/src go1.21 os/.FileModescip-go gomod github.com/golang/go/src go1.21 os/FileMode#(mode), c.chownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#chown., c.utimescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#utime.); err != nil { |
| 174 | return "", nil, err |
| 175 | } else { |
| 176 | createdDirs = dirs |
| 177 | } |
| 178 | |
| 179 | return destPath, createdDirs, nil |
| 180 | } |
| 181 | |
| 182 | type Userscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User# struct { |
| 183 | UIDscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#UID., GIDscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#GID. int |
| 184 | SIDscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#SID. string |
| 185 | } |
| 186 | |
| 187 | type Chownerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Chowner# func(*Userscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#) (*Userscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#, error) |
| 188 | |
| 189 | type XAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/XAttrErrorHandler# func(dst, src, xattrKey string, err error) error |
| 190 | |
| 191 | type CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo# struct { |
| 192 | Chownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Chown. Chownerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Chowner# |
| 193 | Utimescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Utime. *timescip-go gomod github.com/golang/go/src go1.21 time/.Timescip-go gomod github.com/golang/go/src go1.21 time/Time# |
| 194 | AllowWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#AllowWildcards. bool |
| 195 | Modescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Mode. *int |
| 196 | // ModeStr is mode in non-octal format. Overrides Mode if non-empty. |
| 197 | ModeStrscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ModeStr. string |
| 198 | XAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#XAttrErrorHandler. XAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/XAttrErrorHandler# |
| 199 | CopyDirContentsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#CopyDirContents. bool |
| 200 | FollowLinksscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#FollowLinks. bool |
| 201 | // Include only files/dirs matching at least one of these patterns |
| 202 | IncludePatternsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#IncludePatterns. []string |
| 203 | // Exclude files/dir matching any of these patterns (even if they match an include pattern) |
| 204 | ExcludePatternsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ExcludePatterns. []string |
| 205 | // If true, any source path that overwrite existing destination paths will always replace |
| 206 | // the existing destination path, even if they are of different types (e.g. a directory will |
| 207 | // replace any existing symlink or file) |
| 208 | AlwaysReplaceExistingDestPathsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#AlwaysReplaceExistingDestPaths. bool |
| 209 | ChangeFuncscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ChangeFunc. fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/.ChangeFuncscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/ChangeFunc# |
| 210 | |
| 211 | // testHookLstat is called before each os.Lstat if non-nil (for testing only) |
| 212 | testHookLstatscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#testHookLstat. func(path string) |
| 213 | } |
| 214 | |
| 215 | type Optscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Opt# func(*CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) |
| 216 | |
| 217 | func WithCopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/WithCopyInfo().(ci CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) func(*CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 218 | return func(c *CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 219 | *c = ci |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | func WithChownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/WithChown().(uid, gid int) Optscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Opt# { |
| 224 | return func(ci *CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 225 | ci.Chownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#Chown. = func(*Userscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#) (*Userscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#, error) { |
| 226 | return &Userscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#{UIDscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#UID.: uid, GIDscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/User#GID.: gid}, nil |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | func AllowWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/AllowWildcards().(ci *CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 232 | ci.AllowWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#AllowWildcards. = true |
| 233 | } |
| 234 | |
| 235 | func WithXAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/WithXAttrErrorHandler().(h XAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/XAttrErrorHandler#) Optscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Opt# { |
| 236 | return func(ci *CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 237 | ci.XAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#XAttrErrorHandler. = h |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func AllowXAttrErrorsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/AllowXAttrErrors().(ci *CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 242 | h := func(string, string, string, error) error { |
| 243 | return nil |
| 244 | } |
| 245 | WithXAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/WithXAttrErrorHandler().(h)(ci) |
| 246 | } |
| 247 | |
| 248 | func WithIncludePatternscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/WithIncludePattern().(includePattern string) Optscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Opt# { |
| 249 | return func(ci *CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 250 | ci.IncludePatternsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#IncludePatterns. = append(ci.IncludePatternsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#IncludePatterns., includePattern) |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | func WithExcludePatternscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/WithExcludePattern().(excludePattern string) Optscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Opt# { |
| 255 | return func(ci *CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 256 | ci.ExcludePatternsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ExcludePatterns. = append(ci.ExcludePatternsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ExcludePatterns., excludePattern) |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | func WithChangeNotifierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/WithChangeNotifier().(fn fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/.ChangeFuncscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/ChangeFunc#) Optscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Opt# { |
| 261 | return func(ci *CopyInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#) { |
| 262 | ci.ChangeFuncscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/CopyInfo#ChangeFunc. = fn |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | type copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier# struct { |
| 267 | chownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#chown. Chownerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Chowner# |
| 268 | utimescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#utime. *timescip-go gomod github.com/golang/go/src go1.21 time/.Timescip-go gomod github.com/golang/go/src go1.21 time/Time# |
| 269 | modescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#mode. *int |
| 270 | modeSetscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#modeSet. *modescip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/.Setscip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/Set# |
| 271 | inodesscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#inodes. map[uint64]string |
| 272 | xattrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#xattrErrorHandler. XAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/XAttrErrorHandler# |
| 273 | includePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#includePatternMatcher. *patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.PatternMatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/PatternMatcher# |
| 274 | excludePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#excludePatternMatcher. *patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.PatternMatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/PatternMatcher# |
| 275 | parentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#parentDirs. []parentDirscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir# |
| 276 | changefnscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#changefn. fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/.ChangeFuncscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/ChangeFunc# |
| 277 | rootscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#root. string |
| 278 | alwaysReplaceExistingDestPathsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#alwaysReplaceExistingDestPaths. bool |
| 279 | testHookLstatscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#testHookLstat. func(string) |
| 280 | } |
| 281 | |
| 282 | type parentDirscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir# struct { |
| 283 | srcPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#srcPath. string |
| 284 | dstPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#dstPath. string |
| 285 | copiedscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#copied. bool |
| 286 | } |
| 287 | |
| 288 | func newCopierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/newCopier().(root string, chown Chownerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Chowner#, tm *timescip-go gomod github.com/golang/go/src go1.21 time/.Timescip-go gomod github.com/golang/go/src go1.21 time/Time#, mode *int, modeSet *modescip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/.Setscip-go gomod github.com/tonistiigi/dchapes-mode 73d941a28323 `github.com/tonistiigi/dchapes-mode`/Set#, xeh XAttrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/XAttrErrorHandler#, includePatterns, excludePatterns []string, alwaysReplaceExistingDestPaths bool, changeFunc fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/.ChangeFuncscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/ChangeFunc#) (*copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#, error) { |
| 289 | if xeh == nil { |
| 290 | xeh = func(dst, src, key string, err error) error { |
| 291 | return err |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | var includePatternMatcher *patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.PatternMatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/PatternMatcher# |
| 296 | if len(includePatterns) != 0 { |
| 297 | var err error |
| 298 | includePatternMatcher, err = patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.Newscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/New().(includePatterns) |
| 299 | if err != nil { |
| 300 | return nil, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "invalid includepatterns: %s", includePatterns) |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | var excludePatternMatcher *patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.PatternMatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/PatternMatcher# |
| 305 | if len(excludePatterns) != 0 { |
| 306 | var err error |
| 307 | excludePatternMatcher, err = patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.Newscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/New().(excludePatterns) |
| 308 | if err != nil { |
| 309 | return nil, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "invalid excludepatterns: %s", excludePatterns) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | return &copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#{ |
| 314 | rootscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#root.: root, |
| 315 | inodesscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#inodes.: map[uint64]string{}, |
| 316 | chownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#chown.: chown, |
| 317 | utimescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#utime.: tm, |
| 318 | xattrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#xattrErrorHandler.: xeh, |
| 319 | modescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#mode.: mode, |
| 320 | modeSetscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#modeSet.: modeSet, |
| 321 | includePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#includePatternMatcher.: includePatternMatcher, |
| 322 | excludePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#excludePatternMatcher.: excludePatternMatcher, |
| 323 | changefnscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#changefn.: changeFunc, |
| 324 | alwaysReplaceExistingDestPathsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#alwaysReplaceExistingDestPaths.: alwaysReplaceExistingDestPaths, |
| 325 | testHookLstatscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#testHookLstat.: nil, |
| 326 | }, nil |
| 327 | } |
| 328 | |
| 329 | // dest is always clean |
| 330 | func (c *copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#) copyscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#copy().(ctx contextscip-go gomod github.com/golang/go/src go1.21 context/.Contextscip-go gomod github.com/golang/go/src go1.21 context/Context#, src, srcComponents, target string, overwriteTargetMetadata bool, parentIncludeMatchInfo, parentExcludeMatchInfo patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#) error { |
| 331 | select { |
| 332 | case <-ctx.Donescip-go gomod github.com/golang/go/src go1.21 context/Context#Done().(): |
| 333 | return ctx.Errscip-go gomod github.com/golang/go/src go1.21 context/Context#Err().() |
| 334 | default: |
| 335 | } |
| 336 | |
| 337 | // Check exclude patterns BEFORE calling os.Lstat to avoid permission errors |
| 338 | // on inaccessible files/directories (e.g., protected Windows system folders) |
| 339 | include := true |
| 340 | excluded := false |
| 341 | var ( |
| 342 | includeMatchInfo patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo# |
| 343 | excludeMatchInfo patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo# |
| 344 | ) |
| 345 | if srcComponents != "" { |
| 346 | matchesIncludePattern := false |
| 347 | matchesExcludePattern := false |
| 348 | var err error |
| 349 | matchesIncludePattern, includeMatchInfo, err = c.includescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#include().(srcComponents, parentIncludeMatchInfo) |
| 350 | if err != nil { |
| 351 | return err |
| 352 | } |
| 353 | include = matchesIncludePattern |
| 354 | |
| 355 | matchesExcludePattern, excludeMatchInfo, err = c.excludescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#exclude().(srcComponents, parentExcludeMatchInfo) |
| 356 | if err != nil { |
| 357 | return err |
| 358 | } |
| 359 | if matchesExcludePattern { |
| 360 | include = false |
| 361 | excluded = true |
| 362 | } |
| 363 | |
| 364 | // Optimization: Skip os.Lstat() for excluded paths when safe to do so. |
| 365 | // We can skip Lstat if: |
| 366 | // 1. The path is explicitly excluded |
| 367 | // 2. There are no include patterns (no need to check children) |
| 368 | // 3. There are no negation patterns in excludes (no exceptions to exclusions) |
| 369 | // |
| 370 | // This prevents "Access is denied" errors on Windows protected folders |
| 371 | // like "System Volume Information" and "WcSandboxState". |
| 372 | canSkip := !include && c.includePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#includePatternMatcher. == nil && |
| 373 | (c.excludePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#excludePatternMatcher. == nil || !c.excludePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#excludePatternMatcher..Exclusionsscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/PatternMatcher#Exclusions().()) |
| 374 | if canSkip { |
| 375 | return nil |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | if c.testHookLstatscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#testHookLstat. != nil { |
| 380 | c.testHookLstatscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#testHookLstat.(src) |
| 381 | } |
| 382 | fi, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Lstatscip-go gomod github.com/golang/go/src go1.21 os/Lstat().(src) |
| 383 | if err != nil { |
| 384 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to stat %s", src) |
| 385 | } |
| 386 | |
| 387 | // After Lstat, if this item is excluded and is NOT a directory, skip it |
| 388 | if !include && !fi.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 389 | return nil |
| 390 | } |
| 391 | |
| 392 | targetFi, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Lstatscip-go gomod github.com/golang/go/src go1.21 os/Lstat().(target) |
| 393 | if err != nil && !osscip-go gomod github.com/golang/go/src go1.21 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.21 os/IsNotExist().(err) { |
| 394 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to stat %s", target) |
| 395 | } |
| 396 | |
| 397 | if include { |
| 398 | if err := c.removeTargetIfNeededscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#removeTargetIfNeeded().(target, fi, targetFi); err != nil { |
| 399 | return err |
| 400 | } |
| 401 | |
| 402 | if err := c.createParentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#createParentDirs().(src, overwriteTargetMetadata); err != nil { |
| 403 | return err |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | if !fi.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 408 | if !include { |
| 409 | return nil |
| 410 | } |
| 411 | |
| 412 | if err := ensureEmptyFileTargetscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/ensureEmptyFileTarget().(target); err != nil { |
| 413 | return err |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | copyFileInfo := include |
| 418 | restoreFileTimestamp := false |
| 419 | notify := true |
| 420 | |
| 421 | switch { |
| 422 | case fi.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().(): |
| 423 | if created, err := c.copyDirectoryscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#copyDirectory().( |
| 424 | ctx, src, srcComponents, target, fi, overwriteTargetMetadata, |
| 425 | include, excluded, includeMatchInfo, excludeMatchInfo, |
| 426 | ); err != nil { |
| 427 | return err |
| 428 | } else if !overwriteTargetMetadata { |
| 429 | // if we aren't supposed to overwrite existing target metadata, |
| 430 | // then we only need to copy the new file info if we newly created |
| 431 | // it, or restore the previous file timestamp if not |
| 432 | copyFileInfo = created |
| 433 | restoreFileTimestamp = !created |
| 434 | } |
| 435 | notify = false |
| 436 | case (fi.Modescip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#Mode().() & osscip-go gomod github.com/golang/go/src go1.21 os/.ModeTypescip-go gomod github.com/golang/go/src go1.21 os/ModeType.) == 0: |
| 437 | link, err := getLinkSourcescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/getLinkSource().(target, fi, c.inodesscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#inodes.) |
| 438 | if err != nil { |
| 439 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to get hardlink") |
| 440 | } |
| 441 | if link != "" { |
| 442 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.Linkscip-go gomod github.com/golang/go/src go1.21 os/Link().(link, target); err != nil { |
| 443 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to create hard link") |
| 444 | } |
| 445 | } else if err := copyFilescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copyFile().(src, target); err != nil { |
| 446 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to copy files") |
| 447 | } |
| 448 | case (fi.Modescip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#Mode().() & osscip-go gomod github.com/golang/go/src go1.21 os/.ModeSymlinkscip-go gomod github.com/golang/go/src go1.21 os/ModeSymlink.) == osscip-go gomod github.com/golang/go/src go1.21 os/.ModeSymlinkscip-go gomod github.com/golang/go/src go1.21 os/ModeSymlink.: |
| 449 | link, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Readlinkscip-go gomod github.com/golang/go/src go1.21 os/Readlink().(src) |
| 450 | if err != nil { |
| 451 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to read link: %s", src) |
| 452 | } |
| 453 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.Symlinkscip-go gomod github.com/golang/go/src go1.21 os/Symlink().(link, target); err != nil { |
| 454 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to create symlink: %s", target) |
| 455 | } |
| 456 | case (fi.Modescip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#Mode().() & osscip-go gomod github.com/golang/go/src go1.21 os/.ModeDevicescip-go gomod github.com/golang/go/src go1.21 os/ModeDevice.) == osscip-go gomod github.com/golang/go/src go1.21 os/.ModeDevicescip-go gomod github.com/golang/go/src go1.21 os/ModeDevice., |
| 457 | (fi.Modescip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#Mode().() & osscip-go gomod github.com/golang/go/src go1.21 os/.ModeNamedPipescip-go gomod github.com/golang/go/src go1.21 os/ModeNamedPipe.) == osscip-go gomod github.com/golang/go/src go1.21 os/.ModeNamedPipescip-go gomod github.com/golang/go/src go1.21 os/ModeNamedPipe., |
| 458 | (fi.Modescip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#Mode().() & osscip-go gomod github.com/golang/go/src go1.21 os/.ModeSocketscip-go gomod github.com/golang/go/src go1.21 os/ModeSocket.) == osscip-go gomod github.com/golang/go/src go1.21 os/.ModeSocketscip-go gomod github.com/golang/go/src go1.21 os/ModeSocket.: |
| 459 | if err := copyDevicescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copyDevice().(target, fi); err != nil { |
| 460 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to create device") |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | if copyFileInfo { |
| 465 | if err := c.copyFileInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#copyFileInfo().(fi, src, target); err != nil { |
| 466 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to copy file info") |
| 467 | } |
| 468 | |
| 469 | if err := copyXAttrsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copyXAttrs().(target, src, c.xattrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#xattrErrorHandler.); err != nil { |
| 470 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to copy xattrs") |
| 471 | } |
| 472 | } else if restoreFileTimestamp && targetFi != nil { |
| 473 | if err := c.copyFileTimestampscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#copyFileTimestamp().(fi, target); err != nil { |
| 474 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to restore file timestamp") |
| 475 | } |
| 476 | } |
| 477 | if notify { |
| 478 | if err := c.notifyChangescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#notifyChange().(target, fi); err != nil { |
| 479 | return err |
| 480 | } |
| 481 | } |
| 482 | return nil |
| 483 | } |
| 484 | |
| 485 | func (c *copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#) notifyChangescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#notifyChange().(target string, fi osscip-go gomod github.com/golang/go/src go1.21 os/.FileInfoscip-go gomod github.com/golang/go/src go1.21 os/FileInfo#) error { |
| 486 | if c.changefnscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#changefn. != nil { |
| 487 | if err := c.changefnscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#changefn.(fsutilscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/.ChangeKindAddscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil`/ChangeKindAdd., pathscip-go gomod github.com/golang/go/src go1.21 path/.Cleanscip-go gomod github.com/golang/go/src go1.21 path/Clean().(stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21 strings/TrimPrefix().(target, c.rootscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#root.)), fi, nil); err != nil { |
| 488 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to notify file change") |
| 489 | } |
| 490 | } |
| 491 | return nil |
| 492 | } |
| 493 | |
| 494 | func (c *copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#) includescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#include().(path string, parentIncludeMatchInfo patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#) (bool, patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#, error) { |
| 495 | if c.includePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#includePatternMatcher. == nil { |
| 496 | return true, patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#{}, nil |
| 497 | } |
| 498 | |
| 499 | m, matchInfo, err := c.includePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#includePatternMatcher..MatchesUsingParentResultsscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/PatternMatcher#MatchesUsingParentResults().(path, parentIncludeMatchInfo) |
| 500 | if err != nil { |
| 501 | return false, matchInfo, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to match includepatterns") |
| 502 | } |
| 503 | return m, matchInfo, nil |
| 504 | } |
| 505 | |
| 506 | func (c *copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#) excludescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#exclude().(path string, parentExcludeMatchInfo patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#) (bool, patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#, error) { |
| 507 | if c.excludePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#excludePatternMatcher. == nil { |
| 508 | return false, patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#{}, nil |
| 509 | } |
| 510 | |
| 511 | m, matchInfo, err := c.excludePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#excludePatternMatcher..MatchesUsingParentResultsscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/PatternMatcher#MatchesUsingParentResults().(path, parentExcludeMatchInfo) |
| 512 | if err != nil { |
| 513 | return false, matchInfo, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to match excludepatterns") |
| 514 | } |
| 515 | return m, matchInfo, nil |
| 516 | } |
| 517 | |
| 518 | func (c *copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#) removeTargetIfNeededscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#removeTargetIfNeeded().(target string, srcFi, targetFi osscip-go gomod github.com/golang/go/src go1.21 os/.FileInfoscip-go gomod github.com/golang/go/src go1.21 os/FileInfo#) error { |
| 519 | if !c.alwaysReplaceExistingDestPathsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#alwaysReplaceExistingDestPaths. { |
| 520 | return nil |
| 521 | } |
| 522 | if targetFi == nil { |
| 523 | // already doesn't exist |
| 524 | return nil |
| 525 | } |
| 526 | if srcFi.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() && targetFi.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 527 | // directories are merged, not replaced |
| 528 | return nil |
| 529 | } |
| 530 | return osscip-go gomod github.com/golang/go/src go1.21 os/.RemoveAllscip-go gomod github.com/golang/go/src go1.21 os/RemoveAll().(target) |
| 531 | } |
| 532 | |
| 533 | // Delayed creation of parent directories when a file or dir matches an include |
| 534 | // pattern. |
| 535 | func (c *copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#) createParentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#createParentDirs().(src string, overwriteTargetMetadata bool) error { |
| 536 | for i, parentDir := range c.parentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#parentDirs. { |
| 537 | if parentDir.copiedscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#copied. { |
| 538 | continue |
| 539 | } |
| 540 | |
| 541 | fi, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Statscip-go gomod github.com/golang/go/src go1.21 os/Stat().(parentDir.srcPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#srcPath.) |
| 542 | if err != nil { |
| 543 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to stat %s", src) |
| 544 | } |
| 545 | if !fi.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 546 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Errorfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Errorf().("%s is not a directory", parentDir.srcPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#srcPath.) |
| 547 | } |
| 548 | |
| 549 | created, err := copyDirectoryOnlyscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copyDirectoryOnly().(parentDir.dstPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#dstPath., fi, overwriteTargetMetadata) |
| 550 | if err != nil { |
| 551 | return err |
| 552 | } |
| 553 | if created { |
| 554 | if err := c.copyFileInfoscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#copyFileInfo().(fi, parentDir.srcPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#srcPath., parentDir.dstPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#dstPath.); err != nil { |
| 555 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to copy file info") |
| 556 | } |
| 557 | |
| 558 | if err := copyXAttrsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copyXAttrs().(parentDir.dstPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#dstPath., parentDir.srcPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#srcPath., c.xattrErrorHandlerscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#xattrErrorHandler.); err != nil { |
| 559 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to copy xattrs") |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | c.parentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#parentDirs.[i].copiedscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#copied. = true |
| 564 | } |
| 565 | return nil |
| 566 | } |
| 567 | |
| 568 | func (c *copierscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#) copyDirectoryscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#copyDirectory().( |
| 569 | ctx contextscip-go gomod github.com/golang/go/src go1.21 context/.Contextscip-go gomod github.com/golang/go/src go1.21 context/Context#, |
| 570 | src string, |
| 571 | srcComponents string, |
| 572 | dst string, |
| 573 | stat osscip-go gomod github.com/golang/go/src go1.21 os/.FileInfoscip-go gomod github.com/golang/go/src go1.21 os/FileInfo#, |
| 574 | overwriteTargetMetadata bool, |
| 575 | include bool, |
| 576 | excluded bool, |
| 577 | includeMatchInfo patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#, |
| 578 | excludeMatchInfo patternmatcherscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/.MatchInfoscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/MatchInfo#, |
| 579 | ) (bool, error) { |
| 580 | if !stat.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 581 | return false, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Errorfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Errorf().("source is not directory") |
| 582 | } |
| 583 | |
| 584 | created := false |
| 585 | |
| 586 | parentDir := parentDirscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#{ |
| 587 | srcPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#srcPath.: src, |
| 588 | dstPathscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#dstPath.: dst, |
| 589 | } |
| 590 | |
| 591 | // If this directory passed include/exclude matching directly, go ahead |
| 592 | // and create the directory. Otherwise, delay to handle include |
| 593 | // patterns like a/*/c where we do not want to create a/b until we |
| 594 | // encounter a/b/c. |
| 595 | if include { |
| 596 | var err error |
| 597 | created, err = copyDirectoryOnlyscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copyDirectoryOnly().(dst, stat, overwriteTargetMetadata) |
| 598 | if err != nil { |
| 599 | return created, err |
| 600 | } |
| 601 | if created || overwriteTargetMetadata { |
| 602 | if err := c.notifyChangescip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#notifyChange().(dst, stat); err != nil { |
| 603 | return created, err |
| 604 | } |
| 605 | } |
| 606 | parentDir.copiedscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/parentDir#copied. = true |
| 607 | } |
| 608 | |
| 609 | c.parentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#parentDirs. = append(c.parentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#parentDirs., parentDir) |
| 610 | |
| 611 | defer func() { |
| 612 | c.parentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#parentDirs. = c.parentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#parentDirs.[:len(c.parentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#parentDirs.)-1] |
| 613 | }() |
| 614 | |
| 615 | // Skip reading directory contents if explicitly excluded AND no negation patterns exist. |
| 616 | // If negation patterns exist (e.g., "!bar/baz"), we must traverse excluded directories |
| 617 | // to find children that might be un-excluded by the negation. |
| 618 | if excluded && (c.excludePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#excludePatternMatcher. == nil || !c.excludePatternMatcherscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#excludePatternMatcher..Exclusionsscip-go gomod github.com/moby/patternmatcher v0.5.0 `github.com/moby/patternmatcher`/PatternMatcher#Exclusions().()) { |
| 619 | return false, nil |
| 620 | } |
| 621 | |
| 622 | fis, err := osscip-go gomod github.com/golang/go/src go1.21 os/.ReadDirscip-go gomod github.com/golang/go/src go1.21 os/ReadDir().(src) |
| 623 | if err != nil { |
| 624 | return false, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to read %s", src) |
| 625 | } |
| 626 | |
| 627 | for _, fi := range fis { |
| 628 | if err := c.copyscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copier#copy().( |
| 629 | ctx, |
| 630 | filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(src, fi.Namescip-go gomod github.com/golang/go/src go1.21 `io/fs`/DirEntry#Name().()), filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(srcComponents, fi.Namescip-go gomod github.com/golang/go/src go1.21 `io/fs`/DirEntry#Name().()), |
| 631 | filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(dst, fi.Namescip-go gomod github.com/golang/go/src go1.21 `io/fs`/DirEntry#Name().()), |
| 632 | true, includeMatchInfo, excludeMatchInfo, |
| 633 | ); err != nil { |
| 634 | return false, err |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | return created, nil |
| 639 | } |
| 640 | |
| 641 | func copyDirectoryOnlyscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/copyDirectoryOnly().(dst string, stat osscip-go gomod github.com/golang/go/src go1.21 os/.FileInfoscip-go gomod github.com/golang/go/src go1.21 os/FileInfo#, overwriteTargetMetadata bool) (bool, error) { |
| 642 | if st, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Lstatscip-go gomod github.com/golang/go/src go1.21 os/Lstat().(dst); err != nil { |
| 643 | if !osscip-go gomod github.com/golang/go/src go1.21 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.21 os/IsNotExist().(err) { |
| 644 | return false, err |
| 645 | } |
| 646 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.Mkdirscip-go gomod github.com/golang/go/src go1.21 os/Mkdir().(dst, stat.Modescip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#Mode().()); err != nil { |
| 647 | return false, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to mkdir %s", dst) |
| 648 | } |
| 649 | return true, nil |
| 650 | } else if !st.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 651 | return false, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Errorfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Errorf().("cannot copy to non-directory: %s", dst) |
| 652 | } else if overwriteTargetMetadata { |
| 653 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.Chmodscip-go gomod github.com/golang/go/src go1.21 os/Chmod().(dst, stat.Modescip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#Mode().()); err != nil { |
| 654 | return false, errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrapf().(err, "failed to chmod on %s", dst) |
| 655 | } |
| 656 | } |
| 657 | return false, nil |
| 658 | } |
| 659 | |
| 660 | func ensureEmptyFileTargetscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/ensureEmptyFileTarget().(dst string) error { |
| 661 | fi, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Lstatscip-go gomod github.com/golang/go/src go1.21 os/Lstat().(dst) |
| 662 | if err != nil { |
| 663 | if osscip-go gomod github.com/golang/go/src go1.21 os/.IsNotExistscip-go gomod github.com/golang/go/src go1.21 os/IsNotExist().(err) { |
| 664 | return nil |
| 665 | } |
| 666 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Wrapscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Wrap().(err, "failed to lstat file target") |
| 667 | } |
| 668 | if fi.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 669 | return errorsscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/.Errorfscip-go gomod github.com/pkg/errors v0.9.1 `github.com/pkg/errors`/Errorf().("cannot replace to directory %s with file", dst) |
| 670 | } |
| 671 | return osscip-go gomod github.com/golang/go/src go1.21 os/.Removescip-go gomod github.com/golang/go/src go1.21 os/Remove().(dst) |
| 672 | } |
| 673 | |
| 674 | func containsWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/containsWildcards().(name string) bool { |
| 675 | isWindows := runtimescip-go gomod github.com/golang/go/src go1.21 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.21 runtime/GOOS. == "windows" |
| 676 | for i := 0; i < len(name); i++ { |
| 677 | ch := name[i] |
| 678 | if ch == '\\' && !isWindows { |
| 679 | i++ |
| 680 | } else if ch == '*' || ch == '?' || ch == '[' { |
| 681 | return true |
| 682 | } |
| 683 | } |
| 684 | return false |
| 685 | } |
| 686 | |
| 687 | func splitWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/splitWildcards().(p string) (d1, d2 string) { |
| 688 | parts := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Splitscip-go gomod github.com/golang/go/src go1.21 strings/Split().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(p), string(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Separator.)) |
| 689 | var p1, p2 []string |
| 690 | var found bool |
| 691 | for _, p := range parts { |
| 692 | if !found && containsWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/containsWildcards().(p) { |
| 693 | found = true |
| 694 | } |
| 695 | if p == "" { |
| 696 | p = "/" |
| 697 | } |
| 698 | if !found { |
| 699 | p1 = append(p1, p) |
| 700 | } else { |
| 701 | p2 = append(p2, p) |
| 702 | } |
| 703 | } |
| 704 | return filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(p1...), filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(p2...) |
| 705 | } |
| 706 | |
| 707 | func resolveWildcardsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/resolveWildcards().(basePath, comp string) ([]string, error) { |
| 708 | var out []string |
| 709 | err := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Walkscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Walk().(basePath, func(path string, info osscip-go gomod github.com/golang/go/src go1.21 os/.FileInfoscip-go gomod github.com/golang/go/src go1.21 os/FileInfo#, err error) error { |
| 710 | if err != nil { |
| 711 | return err |
| 712 | } |
| 713 | rel, err := relscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/rel().(basePath, path) |
| 714 | if err != nil { |
| 715 | return err |
| 716 | } |
| 717 | if rel == "." { |
| 718 | return nil |
| 719 | } |
| 720 | if match, _ := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Matchscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Match().(comp, rel); !match { |
| 721 | return nil |
| 722 | } |
| 723 | out = append(out, path) |
| 724 | if info.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 725 | return filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.SkipDirscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/SkipDir. |
| 726 | } |
| 727 | return nil |
| 728 | }) |
| 729 | if err != nil { |
| 730 | return nil, err |
| 731 | } |
| 732 | return out, nil |
| 733 | } |
| 734 | |
| 735 | // rel makes a path relative to base path. Same as `filepath.Rel` but can also |
| 736 | // handle UUID paths in windows. |
| 737 | func relscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/rel().(basepath, targpath string) (string, error) { |
| 738 | // filepath.Rel can't handle UUID paths in windows |
| 739 | if runtimescip-go gomod github.com/golang/go/src go1.21 runtime/.GOOSscip-go gomod github.com/golang/go/src go1.21 runtime/GOOS. == "windows" { |
| 740 | pfx := basepath + `\` |
| 741 | if stringsscip-go gomod github.com/golang/go/src go1.21 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.21 strings/HasPrefix().(targpath, pfx) { |
| 742 | p := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21 strings/TrimPrefix().(targpath, pfx) |
| 743 | if p == "" { |
| 744 | p = "." |
| 745 | } |
| 746 | return p, nil |
| 747 | } |
| 748 | } |
| 749 | return filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Relscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Rel().(basepath, targpath) |
| 750 | } |
| 751 | |
| 752 | func fixCreatedParentDirsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/fixCreatedParentDirs().(dirs []string, tm *timescip-go gomod github.com/golang/go/src go1.21 time/.Timescip-go gomod github.com/golang/go/src go1.21 time/Time#) error { |
| 753 | slicesscip-go gomod github.com/golang/go/src go1.21 slices/.Reversescip-go gomod github.com/golang/go/src go1.21 slices/Reverse().(dirs) |
| 754 | for _, d := range dirs { |
| 755 | if tm != nil { |
| 756 | if err := Utimesscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Utimes().(d, tm); err != nil { |
| 757 | return err |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | return nil |
| 762 | } |