| 1 | //go:build !js |
| 2 | |
| 3 | /* |
| 4 | Copyright 2022 The Flux authors. |
| 5 | |
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | you may not use this file except in compliance with the License. |
| 8 | You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, software |
| 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | See the License for the specific language governing permissions and |
| 16 | limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | package osfsscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/ |
| 20 | |
| 21 | import ( |
| 22 | "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/" |
| 23 | gofsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/ "io/fsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/" |
| 24 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 25 | "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/" |
| 26 | |
| 27 | "github.com/go-git/go-billy/v6scip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/" |
| 28 | "github.com/go-git/go-billy/v6/utilscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/" |
| 29 | ) |
| 30 | |
| 31 | // BoundOS is a fs implementation based on the OS filesystem which relies on |
| 32 | // Go's [os.Root]. A new [os.Root] is opened and closed for each filesystem |
| 33 | // operation to avoid holding a directory handle open. |
| 34 | // |
| 35 | // For better performance, prefer [RootOS] via [FromRoot] with a |
| 36 | // caller-managed [os.Root]. |
| 37 | // |
| 38 | // Behaviours of note: |
| 39 | // 1. Read and write operations can only be directed to files which descend |
| 40 | // from the base dir. |
| 41 | // 2. Symlink targets are stored verbatim and not rewritten, so they may |
| 42 | // point outside the base dir or to non-existent paths. [BoundOS.Readlink] |
| 43 | // returns the stored target with path separators normalised to forward |
| 44 | // slashes (see [filepath.ToSlash]). |
| 45 | // 3. Operations leading to escapes to outside the [os.Root] location result |
| 46 | // in [ErrPathEscapesParent]. |
| 47 | type BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS# struct { |
| 48 | baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir. string |
| 49 | mmapscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#mmap. bool |
| 50 | } |
| 51 | |
| 52 | func newBoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/newBoundOS().(d string) *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS# { |
| 53 | if d == "" { |
| 54 | d = string(osscip-go gomod github.com/golang/go/src go1.25.0 os/.PathSeparatorscip-go gomod github.com/golang/go/src go1.25.0 os/PathSeparator.) |
| 55 | } |
| 56 | d = hostPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/hostPath().(d) |
| 57 | return &BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#{baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir.: d} |
| 58 | } |
| 59 | |
| 60 | // clone returns a new [BoundOS] rooted at d that carries over fs's |
| 61 | // configurable behaviour (currently just the [WithMmap] flag). Used |
| 62 | // to construct sub-filesystems via [BoundOS.Chroot] without silently |
| 63 | // dropping caller-supplied options. |
| 64 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) clonescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#clone().(d string) *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS# { |
| 65 | if d == "" { |
| 66 | d = string(osscip-go gomod github.com/golang/go/src go1.25.0 os/.PathSeparatorscip-go gomod github.com/golang/go/src go1.25.0 os/PathSeparator.) |
| 67 | } |
| 68 | return &BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#{baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir.: hostPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/hostPath().(d), mmapscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#mmap.: fs.mmapscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#mmap.} |
| 69 | } |
| 70 | |
| 71 | // rootFS opens a temporary [RootOS] and returns a cleanup function that |
| 72 | // closes the underlying [os.Root]. |
| 73 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) rootFSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFS().() (*RootOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#, func(), error) { |
| 74 | return fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().("", false) |
| 75 | } |
| 76 | |
| 77 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name string, createBase bool) (*RootOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#, func(), error) { |
| 78 | rootPath := fs.operationRootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#operationRoot().(name) |
| 79 | r, err := openRootAtscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/openRootAt().(rootPath, createBase) |
| 80 | if err != nil { |
| 81 | return nil, func() {}, err |
| 82 | } |
| 83 | return &RootOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#{rootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#root.: r, mmapscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#mmap.: fs.mmapscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#mmap.}, func() { r.Closescip-go gomod github.com/golang/go/src go1.25.0 os/Root#Close().() }, nil |
| 84 | } |
| 85 | |
| 86 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Capabilitiesscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Capabilities().() billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Capabilityscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Capability# { |
| 87 | return boundCapabilitiesscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/boundCapabilities().() |
| 88 | } |
| 89 | |
| 90 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Createscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Create().(name string) (billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Filescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/File#, error) { |
| 91 | return fs.OpenFilescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#OpenFile().(name, osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_RDWRscip-go gomod github.com/golang/go/src go1.25.0 os/O_RDWR.|osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_CREATEscip-go gomod github.com/golang/go/src go1.25.0 os/O_CREATE.|osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_TRUNCscip-go gomod github.com/golang/go/src go1.25.0 os/O_TRUNC., defaultCreateModescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/defaultCreateMode.) |
| 92 | } |
| 93 | |
| 94 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) OpenFilescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#OpenFile().(name string, flag int, perm gofsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.FileModescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileMode#) (billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Filescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/File#, error) { |
| 95 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name, flag&osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_CREATEscip-go gomod github.com/golang/go/src go1.25.0 os/O_CREATE. != 0) |
| 96 | if err != nil { |
| 97 | return nil, err |
| 98 | } |
| 99 | defer cleanup() |
| 100 | return rfs.OpenFilescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#OpenFile().(name, flag, perm) |
| 101 | } |
| 102 | |
| 103 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) ReadDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#ReadDir().(name string) ([]gofsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.DirEntryscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/DirEntry#, error) { |
| 104 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name, false) |
| 105 | if err != nil { |
| 106 | return nil, err |
| 107 | } |
| 108 | defer cleanup() |
| 109 | return rfs.ReadDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#ReadDir().(name) |
| 110 | } |
| 111 | |
| 112 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Renamescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Rename().(from, to string) error { |
| 113 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(from, false) |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | defer cleanup() |
| 118 | return rfs.Renamescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#Rename().(from, to) |
| 119 | } |
| 120 | |
| 121 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) MkdirAllscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#MkdirAll().(name string, perm gofsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.FileModescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileMode#) error { |
| 122 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name, true) |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | defer cleanup() |
| 127 | return rfs.MkdirAllscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#MkdirAll().(name, perm) |
| 128 | } |
| 129 | |
| 130 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Openscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Open().(name string) (billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Filescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/File#, error) { |
| 131 | return fs.OpenFilescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#OpenFile().(name, osscip-go gomod github.com/golang/go/src go1.25.0 os/.O_RDONLYscip-go gomod github.com/golang/go/src go1.25.0 os/O_RDONLY., 0) |
| 132 | } |
| 133 | |
| 134 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Statscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Stat().(name string) (osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo#, error) { |
| 135 | if fs.isBaseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#isBaseDir().(name) { |
| 136 | return fs.baseInfoscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseInfo().(false) |
| 137 | } |
| 138 | |
| 139 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name, false) |
| 140 | if err != nil { |
| 141 | return nil, err |
| 142 | } |
| 143 | defer cleanup() |
| 144 | return rfs.Statscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#Stat().(name) |
| 145 | } |
| 146 | |
| 147 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Removescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Remove().(name string) error { |
| 148 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name, false) |
| 149 | if err != nil { |
| 150 | return err |
| 151 | } |
| 152 | defer cleanup() |
| 153 | return rfs.Removescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#Remove().(name) |
| 154 | } |
| 155 | |
| 156 | // TempFile creates a temporary file. If dir is empty, the file |
| 157 | // will be created within a .tmp dir. |
| 158 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) TempFilescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#TempFile().(dir, prefix string) (billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Filescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/File#, error) { |
| 159 | return utilscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/.TempFilescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/TempFile().(fs, dir, prefix) |
| 160 | } |
| 161 | |
| 162 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Joinscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Join().(elem ...string) string { |
| 163 | return filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(elem...) |
| 164 | } |
| 165 | |
| 166 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) RemoveAllscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#RemoveAll().(name string) error { |
| 167 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name, false) |
| 168 | if err != nil { |
| 169 | return err |
| 170 | } |
| 171 | defer cleanup() |
| 172 | return rfs.RemoveAllscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#RemoveAll().(name) |
| 173 | } |
| 174 | |
| 175 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Symlinkscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Symlink().(oldname, newname string) error { |
| 176 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(newname, true) |
| 177 | if err != nil { |
| 178 | return err |
| 179 | } |
| 180 | defer cleanup() |
| 181 | return rfs.Symlinkscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#Symlink().(oldname, newname) |
| 182 | } |
| 183 | |
| 184 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Lstatscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Lstat().(name string) (osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo#, error) { |
| 185 | if fs.isBaseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#isBaseDir().(name) { |
| 186 | return fs.baseInfoscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseInfo().(true) |
| 187 | } |
| 188 | |
| 189 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name, false) |
| 190 | if err != nil { |
| 191 | return nil, err |
| 192 | } |
| 193 | defer cleanup() |
| 194 | return rfs.Lstatscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#Lstat().(name) |
| 195 | } |
| 196 | |
| 197 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Readlinkscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Readlink().(name string) (string, error) { |
| 198 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(name, false) |
| 199 | if err != nil { |
| 200 | return "", err |
| 201 | } |
| 202 | defer cleanup() |
| 203 | return rfs.Readlinkscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#Readlink().(name) |
| 204 | } |
| 205 | |
| 206 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Chmodscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Chmod().(path string, mode gofsscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/.FileModescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileMode#) error { |
| 207 | rfs, cleanup, err := fs.rootFSWithCreatescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFSWithCreate().(path, false) |
| 208 | if err != nil { |
| 209 | return err |
| 210 | } |
| 211 | defer cleanup() |
| 212 | return rfs.Chmodscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#Chmod().(path, mode) |
| 213 | } |
| 214 | |
| 215 | // Chroot returns a new [BoundOS] filesystem, with the base dir set to the |
| 216 | // result of joining the provided path with the underlying base dir. |
| 217 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Chrootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Chroot().(path string) (billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Filesystemscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Filesystem#, error) { |
| 218 | if hostPath, ok := fs.hostAbsolutePathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#hostAbsolutePath().(path); ok { |
| 219 | return fs.clonescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#clone().(hostPath), nil |
| 220 | } |
| 221 | |
| 222 | rfs, cleanup, err := fs.rootFSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#rootFS().() |
| 223 | if err != nil { |
| 224 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, osscip-go gomod github.com/golang/go/src go1.25.0 os/.ErrNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/ErrNotExist.) { |
| 225 | return fs.clonescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#clone().(fs.chrootPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#chrootPath().(path)), nil |
| 226 | } |
| 227 | return nil, err |
| 228 | } |
| 229 | defer cleanup() |
| 230 | |
| 231 | rel := rfs.toRelativescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#toRelative().(path) |
| 232 | if rel == "" { |
| 233 | rel = "." |
| 234 | } |
| 235 | childRoot, err := rfs.rootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/RootOS#root..OpenRootscip-go gomod github.com/golang/go/src go1.25.0 os/Root#OpenRoot().(rel) |
| 236 | if err != nil { |
| 237 | if errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, osscip-go gomod github.com/golang/go/src go1.25.0 os/.ErrNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/ErrNotExist.) { |
| 238 | return fs.clonescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#clone().(fs.chrootPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#chrootPath().(path)), nil |
| 239 | } |
| 240 | return nil, err |
| 241 | } |
| 242 | defer childRoot.Closescip-go gomod github.com/golang/go/src go1.25.0 os/Root#Close().() |
| 243 | |
| 244 | return fs.clonescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#clone().(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Clean().(childRoot.Namescip-go gomod github.com/golang/go/src go1.25.0 os/Root#Name().())), nil |
| 245 | } |
| 246 | |
| 247 | // Root returns the current base dir of the billy.Filesystem. |
| 248 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) Rootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#Root().() string { |
| 249 | return fs.baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir. |
| 250 | } |
| 251 | |
| 252 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) isBaseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#isBaseDir().(name string) bool { |
| 253 | if name == "" { |
| 254 | return true |
| 255 | } |
| 256 | |
| 257 | name = hostPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/hostPath().(name) |
| 258 | if filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.IsAbsscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/IsAbs().(name) { |
| 259 | if rel, ok := relativeInsideBasescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/relativeInsideBase().(fs.baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir., name); ok { |
| 260 | return cleanUnderRootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/cleanUnderRoot().(rel) == "" |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | return cleanUnderRootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/cleanUnderRoot().(name) == "" |
| 265 | } |
| 266 | |
| 267 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) chrootPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#chrootPath().(path string) string { |
| 268 | if hostPath, ok := fs.hostAbsolutePathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#hostAbsolutePath().(path); ok { |
| 269 | return filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Clean().(hostPath) |
| 270 | } |
| 271 | |
| 272 | path = hostPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/hostPath().(path) |
| 273 | if filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.IsAbsscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/IsAbs().(path) { |
| 274 | if rel, ok := relativeInsideBasescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/relativeInsideBase().(fs.baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir., path); ok { |
| 275 | return filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Clean().(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(fs.baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir., rel)) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | return filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Clean().(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(fs.baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir., cleanUnderRootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/cleanUnderRoot().(path))) |
| 280 | } |
| 281 | |
| 282 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) hostAbsolutePathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#hostAbsolutePath().(path string) (string, bool) { |
| 283 | if fs.baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir. != string(osscip-go gomod github.com/golang/go/src go1.25.0 os/.PathSeparatorscip-go gomod github.com/golang/go/src go1.25.0 os/PathSeparator.) { |
| 284 | return "", false |
| 285 | } |
| 286 | |
| 287 | path = hostPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/hostPath().(path) |
| 288 | if filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.VolumeNamescip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/VolumeName().(path) != "" && filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.IsAbsscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/IsAbs().(path) { |
| 289 | return path, true |
| 290 | } |
| 291 | |
| 292 | return "", false |
| 293 | } |
| 294 | |
| 295 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) operationRootscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#operationRoot().(path string) string { |
| 296 | if hostPath, ok := fs.hostAbsolutePathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#hostAbsolutePath().(path); ok { |
| 297 | vol := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.VolumeNamescip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/VolumeName().(hostPath) |
| 298 | if vol != "" { |
| 299 | return vol + string(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Separator.) |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | return fs.baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir. |
| 304 | } |
| 305 | |
| 306 | func (fs *BoundOSscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#) baseInfoscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseInfo().(lstat bool) (osscip-go gomod github.com/golang/go/src go1.25.0 os/.FileInfoscip-go gomod github.com/golang/go/src go1.25.0 os/FileInfo#, error) { |
| 307 | base := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Clean().(fs.baseDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/BoundOS#baseDir.) |
| 308 | parent := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Dir().(base) |
| 309 | name := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Base().(base) |
| 310 | |
| 311 | if parent == base { |
| 312 | root, err := openRootAtscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/openRootAt().(base, false) |
| 313 | if err != nil { |
| 314 | return nil, err |
| 315 | } |
| 316 | defer root.Closescip-go gomod github.com/golang/go/src go1.25.0 os/Root#Close().() |
| 317 | if lstat { |
| 318 | return root.Lstatscip-go gomod github.com/golang/go/src go1.25.0 os/Root#Lstat().(".") |
| 319 | } |
| 320 | return root.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Root#Stat().(".") |
| 321 | } |
| 322 | |
| 323 | root, err := openRootAtscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/openRootAt().(parent, false) |
| 324 | if err != nil { |
| 325 | return nil, err |
| 326 | } |
| 327 | defer root.Closescip-go gomod github.com/golang/go/src go1.25.0 os/Root#Close().() |
| 328 | if lstat { |
| 329 | return root.Lstatscip-go gomod github.com/golang/go/src go1.25.0 os/Root#Lstat().(name) |
| 330 | } |
| 331 | return root.Statscip-go gomod github.com/golang/go/src go1.25.0 os/Root#Stat().(name) |
| 332 | } |
| 333 | |
| 334 | func openRootAtscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/openRootAt().(path string, create bool) (*osscip-go gomod github.com/golang/go/src go1.25.0 os/.Rootscip-go gomod github.com/golang/go/src go1.25.0 os/Root#, error) { |
| 335 | path = filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Clean().(path) |
| 336 | root, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.OpenRootscip-go gomod github.com/golang/go/src go1.25.0 os/OpenRoot().(path) |
| 337 | if err == nil || !create || !errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, osscip-go gomod github.com/golang/go/src go1.25.0 os/.ErrNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/ErrNotExist.) { |
| 338 | return root, err |
| 339 | } |
| 340 | |
| 341 | ancestor, rel, err := openExistingAncestorscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/openExistingAncestor().(path) |
| 342 | if err != nil { |
| 343 | return nil, err |
| 344 | } |
| 345 | defer ancestor.Closescip-go gomod github.com/golang/go/src go1.25.0 os/Root#Close().() |
| 346 | |
| 347 | if rel != "." { |
| 348 | if err := ancestor.MkdirAllscip-go gomod github.com/golang/go/src go1.25.0 os/Root#MkdirAll().(rel, defaultDirectoryModescip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/defaultDirectoryMode.); err != nil { |
| 349 | return nil, err |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | return osscip-go gomod github.com/golang/go/src go1.25.0 os/.OpenRootscip-go gomod github.com/golang/go/src go1.25.0 os/OpenRoot().(path) |
| 354 | } |
| 355 | |
| 356 | func openExistingAncestorscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/osfs`/openExistingAncestor().(path string) (*osscip-go gomod github.com/golang/go/src go1.25.0 os/.Rootscip-go gomod github.com/golang/go/src go1.25.0 os/Root#, string, error) { |
| 357 | path = filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Clean().(path) |
| 358 | ancestorPath := path |
| 359 | |
| 360 | for { |
| 361 | root, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.OpenRootscip-go gomod github.com/golang/go/src go1.25.0 os/OpenRoot().(ancestorPath) |
| 362 | if err == nil { |
| 363 | rel, relErr := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Relscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Rel().(ancestorPath, path) |
| 364 | if relErr != nil { |
| 365 | root.Closescip-go gomod github.com/golang/go/src go1.25.0 os/Root#Close().() |
| 366 | return nil, "", relErr |
| 367 | } |
| 368 | return root, rel, nil |
| 369 | } |
| 370 | if !errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Isscip-go gomod github.com/golang/go/src go1.25.0 errors/Is().(err, osscip-go gomod github.com/golang/go/src go1.25.0 os/.ErrNotExistscip-go gomod github.com/golang/go/src go1.25.0 os/ErrNotExist.) { |
| 371 | return nil, "", err |
| 372 | } |
| 373 | |
| 374 | parent := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Dirscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Dir().(ancestorPath) |
| 375 | if parent == ancestorPath { |
| 376 | return nil, "", err |
| 377 | } |
| 378 | ancestorPath = parent |
| 379 | } |
| 380 | } |