Skip to content
Open
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
17 changes: 2 additions & 15 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"io"
"io/fs"
"time"
)

var (
Expand Down Expand Up @@ -132,24 +131,12 @@ type Symlink interface {
Readlink(link string) (string, error)
}

// Change abstract the FileInfo change related operations in a storage-agnostic
// Chmod abstract the FileInfo change related operations in a storage-agnostic
// interface as an extension to the Basic interface
type Change interface {
type Chmod interface {
// Chmod changes the mode of the named file to mode. If the file is a
// symbolic link, it changes the mode of the link's target.
Chmod(name string, mode fs.FileMode) error
// Lchown changes the numeric uid and gid of the named file. If the file is
// a symbolic link, it changes the uid and gid of the link itself.
Lchown(name string, uid, gid int) error
// Chown changes the numeric uid and gid of the named file. If the file is a
// symbolic link, it changes the uid and gid of the link's target.
Chown(name string, uid, gid int) error
// Chtimes changes the access and modification times of the named file,
// similar to the Unix utime() or utimes() functions.
//
// The underlying filesystem may truncate or round the values to a less
// precise time unit.
Chtimes(name string, atime time.Time, mtime time.Time) error
}

// Chroot abstract the chroot related operations in a storage-agnostic interface
Expand Down
9 changes: 9 additions & 0 deletions helper/chroot/chroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ func (fs *ChrootHelper) Readlink(link string) (string, error) {
return string(os.PathSeparator) + target, nil
}

func (fs *ChrootHelper) Chmod(path string, mode fs.FileMode) error {
fullpath, err := fs.underlyingPath(path)
if err != nil {
return err
}

return fs.underlying.(billy.Chmod).Chmod(fullpath, mode)
}

func (fs *ChrootHelper) Chroot(path string) (billy.Filesystem, error) {
fullpath, err := fs.underlyingPath(path)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions memfs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func (fs *Memory) Remove(filename string) error {
return fs.s.Remove(filename)
}

func (fs *Memory) Chmod(path string, mode gofs.FileMode) error {
return fs.s.Chmod(path, mode)
}

// Falls back to Go's filepath.Join, which works differently depending on the
// OS where the code is being executed.
func (fs *Memory) Join(elem ...string) string {
Expand Down
12 changes: 12 additions & 0 deletions memfs/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ func (s *storage) Remove(path string) error {
return nil
}

func (s *storage) Chmod(path string, mode fs.FileMode) error {
path = clean(path)

f, has := s.Get(path)
if !has {
return os.ErrNotExist
}

f.mode = mode
return nil
}

func clean(path string) string {
return filepath.Clean(filepath.FromSlash(path))
}
8 changes: 8 additions & 0 deletions osfs/os_bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ func (fs *BoundOS) Readlink(link string) (string, error) {
return os.Readlink(link)
}

func (fs *BoundOS) Chmod(path string, mode fs.FileMode) error {
abspath, err := fs.abs(path)
if err != nil {
return err
}
return os.Chmod(abspath, mode)
}

// Chroot returns a new BoundOS filesystem, with the base dir set to the
// result of joining the provided path with the underlying base dir.
func (fs *BoundOS) Chroot(path string) (billy.Filesystem, error) {
Expand Down
4 changes: 4 additions & 0 deletions osfs/os_chroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (fs *ChrootOS) Remove(filename string) error {
return os.Remove(filename)
}

func (fs *ChrootOS) Chmod(path string, mode fs.FileMode) error {
return os.Chmod(path, mode)
}

func (fs *ChrootOS) TempFile(dir, prefix string) (billy.File, error) {
if err := fs.createDir(dir + string(os.PathSeparator)); err != nil {
return nil, err
Expand Down