Skip to content

Commit

Permalink
Resolves GH-3 enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord of Scripts committed Sep 19, 2024
1 parent 02791d4 commit 6e267ec
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bucketfs/bitbucket_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func (bfs *BitBucketFS) Remove(name string) error {
return bfs.executePath("Remove", name)
}

func (bfs *BitBucketFS) RemoveAll(path string) error {
return vfs.RemoveAll(bfs, path)
}

// Rename renames oldPath to newPath
// Errors: os.LinkError
func (bfs *BitBucketFS) Rename(oldPath, newPath string) error {
Expand Down Expand Up @@ -248,6 +252,10 @@ func (bfs *BitBucketFS) Mkdir(name string, perm os.FileMode) error {
return errx
}

func (bfs *BitBucketFS) MkdirAll(path string, perm os.FileMode) error {
return vfs.MkdirAll(bfs, path, perm)
}

// Open opens the file.
// Errors: fs.PathError
func (bfs *BitBucketFS) Open(name string) (vfs.File, error) {
Expand Down
8 changes: 8 additions & 0 deletions dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (fs DummyFS) Remove(name string) error {
return fs.err
}

func (fs DummyFS) RemoveAll(path string) error {
return fs.err
}

// Rename returns dummy error
func (fs DummyFS) Rename(oldpath, newpath string) error {
return fs.err
Expand All @@ -46,6 +50,10 @@ func (fs DummyFS) Mkdir(name string, perm os.FileMode) error {
return fs.err
}

func (fs DummyFS) MkdirAll(path string, perm os.FileMode) error {
return fs.err
}

// Symlink returns dummy error
func (fs DummyFS) Symlink(oldname, newname string) error {
return fs.err
Expand Down
3 changes: 2 additions & 1 deletion filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ type Filesystem interface {
OpenFile(name string, flag int, perm os.FileMode) (File, error)
Remove(name string) error

// RemoveAll(path string) error
RemoveAll(path string) error
Rename(oldpath, newpath string) error

Mkdir(name string, perm os.FileMode) error
MkdirAll(path string, perm os.FileMode) error

Symlink(oldname, newname string) error

Expand Down
8 changes: 8 additions & 0 deletions memfs/memfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (fs *MemFS) Mkdir(name string, perm os.FileMode) error {
return nil
}

func (fs *MemFS) MkdirAll(path string, perm os.FileMode) error {
return vfs.MkdirAll(fs, path, perm)
}

func (fs *MemFS) Symlink(oldname, newname string) error {
file, err := fs.OpenFile(
newname,
Expand Down Expand Up @@ -359,6 +363,10 @@ func (fs *MemFS) Remove(name string) error {
return nil
}

func (fs *MemFS) RemoveAll(path string) error {
return vfs.RemoveAll(fs, path)
}

// Rename renames (moves) a file.
// Handles to the oldpath persist but might return oldpath if Name() is called.
func (fs *MemFS) Rename(oldpath, newpath string) error {
Expand Down
10 changes: 10 additions & 0 deletions mountfs/mountfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func (fs MountFS) Remove(name string) error {
return mount.Remove(innerPath)
}

func (fs MountFS) RemoveAll(path string) error {
mount, innerPath := findMount(path, fs.mounts, fs.rootFS, string(fs.PathSeparator()))
return mount.RemoveAll(innerPath)
}

// Rename renames a file.
// Renames across filesystems are not allowed.
func (fs MountFS) Rename(oldpath, newpath string) error {
Expand All @@ -128,6 +133,11 @@ func (fs MountFS) Mkdir(name string, perm os.FileMode) error {
return mount.Mkdir(innerPath, perm)
}

func (fs MountFS) MkdirAll(path string, perm os.FileMode) error {
mount, innerPath := findMount(path, fs.mounts, fs.rootFS, string(fs.PathSeparator()))
return mount.MkdirAll(innerPath, perm)
}

// Symlink creates a symlink
func (fs MountFS) Symlink(oldname, newname string) error {
oldMount, oldInnerName := findMount(oldname, fs.mounts, fs.rootFS, string(fs.PathSeparator()))
Expand Down
4 changes: 4 additions & 0 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (fs OsFS) Mkdir(name string, perm os.FileMode) error {
return os.Mkdir(name, perm)
}

func (fs OsFS) MkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}

// Symlink wraps os.Symlink
func (fs OsFS) Symlink(oldname, newname string) error {
return os.Symlink(oldname, newname)
Expand Down
9 changes: 9 additions & 0 deletions prefixfs/prefixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type FS struct {
}

// Create returns a file system that prefixes all paths and forwards to root.
// Note: This is equivalent to the os.DirFS(prefix) call.
func Create(root vfs.Filesystem, prefix string) *FS {
return &FS{Filesystem: root, Prefix: prefix}
}
Expand All @@ -37,6 +38,10 @@ func (fs *FS) Remove(name string) error {
return fs.Filesystem.Remove(fs.PrefixPath(name))
}

func (fs *FS) RemoveAll(path string) error {
return fs.Filesystem.RemoveAll(fs.PrefixPath(path))
}

// Rename implements vfs.Filesystem.
func (fs *FS) Rename(oldpath, newpath string) error {
return fs.Filesystem.Rename(fs.PrefixPath(oldpath), fs.PrefixPath(newpath))
Expand All @@ -47,6 +52,10 @@ func (fs *FS) Mkdir(name string, perm os.FileMode) error {
return fs.Filesystem.Mkdir(fs.PrefixPath(name), perm)
}

func (fs *FS) MkdirAll(path string, perm os.FileMode) error {
return fs.Filesystem.MkdirAll(fs.PrefixPath(path), perm)
}

// Symlink implements vfs.Filesystem.
func (fs *FS) Symlink(oldname, newname string) error {
return fs.Filesystem.Symlink(fs.PrefixPath(oldname), fs.PrefixPath(newname))
Expand Down

0 comments on commit 6e267ec

Please sign in to comment.