| 1 | package fsscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/ |
| 2 | |
| 3 | import ( |
| 4 | "osscip-go gomod github.com/golang/go/src go1.21 os/" |
| 5 | "syscallscip-go gomod github.com/golang/go/src go1.21 syscall/" |
| 6 | "timescip-go gomod github.com/golang/go/src go1.21 time/" |
| 7 | ) |
| 8 | |
| 9 | // MkdirAll is forked os.MkdirAll |
| 10 | func MkdirAllscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/MkdirAll().(path string, perm osscip-go gomod github.com/golang/go/src go1.21 os/.FileModescip-go gomod github.com/golang/go/src go1.21 os/FileMode#, user 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#) ([]string, error) { |
| 11 | // Fast path: if we can tell whether path is a directory or file, stop with success or error. |
| 12 | dir, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Statscip-go gomod github.com/golang/go/src go1.21 os/Stat().(path) |
| 13 | if err == nil { |
| 14 | if dir.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 15 | return nil, nil |
| 16 | } |
| 17 | return nil, &osscip-go gomod github.com/golang/go/src go1.21 os/.PathErrorscip-go gomod github.com/golang/go/src go1.21 os/PathError#{Opscip-go gomod github.com/golang/go/src go1.21 `io/fs`/PathError#Op.: "mkdir", Pathscip-go gomod github.com/golang/go/src go1.21 `io/fs`/PathError#Path.: path, Errscip-go gomod github.com/golang/go/src go1.21 `io/fs`/PathError#Err.: syscallscip-go gomod github.com/golang/go/src go1.21 syscall/.ENOTDIRscip-go gomod github.com/golang/go/src go1.21 syscall/ENOTDIR.} |
| 18 | } |
| 19 | |
| 20 | // Slow path: make sure parent exists and then call Mkdir for path. |
| 21 | i := len(path) |
| 22 | for i > 0 && osscip-go gomod github.com/golang/go/src go1.21 os/.IsPathSeparatorscip-go gomod github.com/golang/go/src go1.21 os/IsPathSeparator().(path[i-1]) { // Skip trailing path separator. |
| 23 | i-- |
| 24 | } |
| 25 | |
| 26 | j := i |
| 27 | for j > 0 && !osscip-go gomod github.com/golang/go/src go1.21 os/.IsPathSeparatorscip-go gomod github.com/golang/go/src go1.21 os/IsPathSeparator().(path[j-1]) { // Scan backward over element. |
| 28 | j-- |
| 29 | } |
| 30 | |
| 31 | var createdDirs []string |
| 32 | |
| 33 | if j > 1 { |
| 34 | // Create parent. |
| 35 | createdDirs, err = MkdirAllscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/MkdirAll().(fixRootDirectoryscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/fixRootDirectory().(path[:j-1]), perm, user, tm) |
| 36 | if err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | dir, err1 := osscip-go gomod github.com/golang/go/src go1.21 os/.Lstatscip-go gomod github.com/golang/go/src go1.21 os/Lstat().(path) |
| 42 | if err1 == nil && dir.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 43 | return createdDirs, nil |
| 44 | } |
| 45 | |
| 46 | // Parent now exists; invoke Mkdir and use its result. |
| 47 | err = osscip-go gomod github.com/golang/go/src go1.21 os/.Mkdirscip-go gomod github.com/golang/go/src go1.21 os/Mkdir().(path, perm) |
| 48 | if err != nil { |
| 49 | // Handle arguments like "foo/." by |
| 50 | // double-checking that directory doesn't exist. |
| 51 | dir, err1 := osscip-go gomod github.com/golang/go/src go1.21 os/.Lstatscip-go gomod github.com/golang/go/src go1.21 os/Lstat().(path) |
| 52 | if err1 == nil && dir.IsDirscip-go gomod github.com/golang/go/src go1.21 `io/fs`/FileInfo#IsDir().() { |
| 53 | return createdDirs, nil |
| 54 | } |
| 55 | return nil, err |
| 56 | } |
| 57 | createdDirs = append(createdDirs, path) |
| 58 | |
| 59 | if err := Chownscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Chown().(path, nil, user); err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | |
| 63 | if err := Utimesscip-go gomod github.com/tonistiigi/fsutil . `github.com/tonistiigi/fsutil/copy`/Utimes().(path, tm); err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | |
| 67 | return createdDirs, nil |
| 68 | } |