Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.21.x,1.22.x,1.23.x]
go-version: [1.24.x, oldstable, stable]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
11 changes: 10 additions & 1 deletion helper/polyfill/polyfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Polyfill struct {
c capabilities
}

type capabilities struct{ tempfile, dir, symlink, chroot bool }
type capabilities struct{ tempfile, dir, symlink, chroot, chmod bool }

// New creates a new filesystem wrapping up 'fs' the intercepts all the calls
// made and errors if fs doesn't implement any of the billy interfaces.
Expand All @@ -28,6 +28,7 @@ func New(fs billy.Basic) billy.Filesystem {
_, h.c.dir = h.Basic.(billy.Dir)
_, h.c.symlink = h.Basic.(billy.Symlink)
_, h.c.chroot = h.Basic.(billy.Chroot)
_, h.c.chmod = h.Basic.(billy.Chmod)
return h
}

Expand Down Expand Up @@ -87,6 +88,14 @@ func (h *Polyfill) Chroot(path string) (billy.Filesystem, error) {
return h.Basic.(billy.Chroot).Chroot(path)
}

func (h *Polyfill) Chmod(path string, mode os.FileMode) error {
if !h.c.chmod {
return billy.ErrNotSupported
}

return h.Basic.(billy.Chmod).Chmod(path, mode)
}

func (h *Polyfill) Root() string {
if !h.c.chroot {
return string(filepath.Separator)
Expand Down
8 changes: 8 additions & 0 deletions helper/polyfill/polyfill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ func (s *PolyfillSuite) TestChroot(c *C) {
c.Assert(err, Equals, billy.ErrNotSupported)
}

func (s *PolyfillSuite) TestChmod(c *C) {
ch, ok := s.Helper.(billy.Chmod)
c.Assert(ok, Equals, true)

err := ch.Chmod("", 0o444)
c.Assert(err, Equals, billy.ErrNotSupported)
}

func (s *PolyfillSuite) TestRoot(c *C) {
c.Assert(s.Helper.Root(), Equals, string(filepath.Separator))
}
Expand Down
8 changes: 8 additions & 0 deletions osfs/os_bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ func (fs *BoundOS) TempFile(dir, prefix string) (billy.File, error) {
if err != nil {
return nil, err
}

_, err = os.Stat(dir)
if err != nil && os.IsNotExist(err) {
err = os.MkdirAll(dir, defaultDirectoryMode)
if err != nil {
return nil, err
}
}
}

return tempFile(dir, prefix)
Expand Down
18 changes: 10 additions & 8 deletions osfs/os_bound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ func TestTempFile(t *testing.T) {
g.Expect(f.Close()).ToNot(gomega.HaveOccurred())

f, err = fs.TempFile("/above/cwd", "prefix")
g.Expect(err).To(gomega.HaveOccurred())
g.Expect(err.Error()).To(gomega.ContainSubstring(fmt.Sprint(dir, filepath.FromSlash("/above/cwd/prefix"))))
g.Expect(f).To(gomega.BeNil())
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(f).ToNot(gomega.BeNil())
g.Expect(f.Name()).To(gomega.HavePrefix(filepath.Join(dir, "/above/cwd", "prefix")))
g.Expect(f.Close()).ToNot(gomega.HaveOccurred())

tempDir := os.TempDir()
// For windows, volume name must be removed.
Expand All @@ -258,9 +259,10 @@ func TestTempFile(t *testing.T) {
}

f, err = fs.TempFile(tempDir, "prefix")
g.Expect(err).To(gomega.HaveOccurred())
g.Expect(err.Error()).To(gomega.ContainSubstring(filepath.Join(dir, tempDir, "prefix")))
g.Expect(f).To(gomega.BeNil())
g.Expect(err).ToNot(gomega.HaveOccurred())
g.Expect(f).ToNot(gomega.BeNil())
g.Expect(f.Name()).To(gomega.HavePrefix(filepath.Join(dir, tempDir, "prefix")))
g.Expect(f.Close()).ToNot(gomega.HaveOccurred())
}

func TestChroot(t *testing.T) {
Expand Down Expand Up @@ -1105,10 +1107,10 @@ func TestReadDir(t *testing.T) {
g.Expect(dirs).To(gomega.BeNil())
}

func TestInsideBaseDirEval(t*testing.T) {
func TestInsideBaseDirEval(t *testing.T) {
g := gomega.NewWithT(t)
fs := BoundOS{baseDir: "/"}
b, err := fs.insideBaseDirEval("a")
b, err := fs.insideBaseDirEval("a")
g.Expect(b).To(gomega.BeTrue())
g.Expect(err).To(gomega.BeNil())
}
Expand Down
Loading