-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the new BoundOS osfs type, which works as a pass-through filesystem for files descending from base dir. For backwards compatibility the previous behaviour is still the default and is now represented by the ChrootOS type. Signed-off-by: Paulo Gomes <pjbgf@linux.com>
- Loading branch information
Showing
13 changed files
with
1,662 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= | ||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= | ||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= | ||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | ||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= | ||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= | ||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= | ||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= | ||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= | ||
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= | ||
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= | ||
github.com/pjbgf/filepath-securejoin v0.0.0-20230821001828-0ca74e6d4bf8 h1:nqjCeQ2TVnccihhBoVBd0p+70hCFT4yqJKhfc8l1D50= | ||
github.com/pjbgf/filepath-securejoin v0.0.0-20230821001828-0ca74e6d4bf8/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= | ||
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= | ||
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= | ||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= | ||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= | ||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= | ||
golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,144 +1,66 @@ | ||
//go:build !js | ||
// +build !js | ||
|
||
// Package osfs provides a billy filesystem for the OS. | ||
package osfs // import "github.com/go-git/go-billy/v5/osfs" | ||
package osfs | ||
|
||
import ( | ||
"io/ioutil" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
|
||
"github.com/go-git/go-billy/v5" | ||
"github.com/go-git/go-billy/v5/helper/chroot" | ||
) | ||
|
||
const ( | ||
defaultDirectoryMode = 0755 | ||
defaultCreateMode = 0666 | ||
defaultDirectoryMode = 0o755 | ||
defaultCreateMode = 0o666 | ||
) | ||
|
||
// Default Filesystem representing the root of the os filesystem. | ||
var Default = &OS{} | ||
|
||
// OS is a filesystem based on the os filesystem. | ||
type OS struct{} | ||
|
||
// New returns a new OS filesystem. | ||
func New(baseDir string) billy.Filesystem { | ||
return chroot.New(Default, baseDir) | ||
} | ||
func New(baseDir string, opts ...Option) billy.Filesystem { | ||
o := &options{} | ||
for _, opt := range opts { | ||
opt(o) | ||
} | ||
|
||
func (fs *OS) Create(filename string) (billy.File, error) { | ||
return fs.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, defaultCreateMode) | ||
return o.Type.New(baseDir) | ||
} | ||
|
||
func (fs *OS) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error) { | ||
if flag&os.O_CREATE != 0 { | ||
if err := fs.createDir(filename); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
f, err := os.OpenFile(filename, flag, perm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &file{File: f}, err | ||
// file is a wrapper for an os.File which adds support for file locking. | ||
type file struct { | ||
*os.File | ||
m sync.Mutex | ||
} | ||
|
||
func (fs *OS) createDir(fullpath string) error { | ||
dir := filepath.Dir(fullpath) | ||
if dir != "." { | ||
if err := os.MkdirAll(dir, defaultDirectoryMode); err != nil { | ||
return err | ||
} | ||
func (t Type) New(baseDir string) billy.Filesystem { | ||
if t == BoundOSFS { | ||
return newBoundOS(baseDir) | ||
} | ||
|
||
return nil | ||
return newChrootOS(baseDir) | ||
} | ||
|
||
func (fs *OS) ReadDir(path string) ([]os.FileInfo, error) { | ||
l, err := ioutil.ReadDir(path) | ||
func readDir(dir string) ([]os.FileInfo, error) { | ||
entries, err := os.ReadDir(dir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var s = make([]os.FileInfo, len(l)) | ||
for i, f := range l { | ||
s[i] = f | ||
} | ||
|
||
return s, nil | ||
} | ||
|
||
func (fs *OS) Rename(from, to string) error { | ||
if err := fs.createDir(to); err != nil { | ||
return err | ||
infos := make([]fs.FileInfo, 0, len(entries)) | ||
for _, entry := range entries { | ||
fi, err := entry.Info() | ||
if err != nil { | ||
return nil, err | ||
} | ||
infos = append(infos, fi) | ||
} | ||
|
||
return rename(from, to) | ||
} | ||
|
||
func (fs *OS) MkdirAll(path string, perm os.FileMode) error { | ||
return os.MkdirAll(path, defaultDirectoryMode) | ||
} | ||
|
||
func (fs *OS) Open(filename string) (billy.File, error) { | ||
return fs.OpenFile(filename, os.O_RDONLY, 0) | ||
return infos, nil | ||
} | ||
|
||
func (fs *OS) Stat(filename string) (os.FileInfo, error) { | ||
return os.Stat(filename) | ||
} | ||
|
||
func (fs *OS) Remove(filename string) error { | ||
return os.Remove(filename) | ||
} | ||
|
||
func (fs *OS) TempFile(dir, prefix string) (billy.File, error) { | ||
if err := fs.createDir(dir + string(os.PathSeparator)); err != nil { | ||
return nil, err | ||
} | ||
|
||
f, err := ioutil.TempFile(dir, prefix) | ||
func tempFile(dir, prefix string) (billy.File, error) { | ||
f, err := os.CreateTemp(dir, prefix) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &file{File: f}, nil | ||
} | ||
|
||
func (fs *OS) Join(elem ...string) string { | ||
return filepath.Join(elem...) | ||
} | ||
|
||
func (fs *OS) RemoveAll(path string) error { | ||
return os.RemoveAll(filepath.Clean(path)) | ||
} | ||
|
||
func (fs *OS) Lstat(filename string) (os.FileInfo, error) { | ||
return os.Lstat(filepath.Clean(filename)) | ||
} | ||
|
||
func (fs *OS) Symlink(target, link string) error { | ||
if err := fs.createDir(link); err != nil { | ||
return err | ||
} | ||
|
||
return os.Symlink(target, link) | ||
} | ||
|
||
func (fs *OS) Readlink(link string) (string, error) { | ||
return os.Readlink(link) | ||
} | ||
|
||
// Capabilities implements the Capable interface. | ||
func (fs *OS) Capabilities() billy.Capability { | ||
return billy.DefaultCapabilities | ||
} | ||
|
||
// file is a wrapper for an os.File which adds support for file locking. | ||
type file struct { | ||
*os.File | ||
m sync.Mutex | ||
} |
Oops, something went wrong.