diff --git a/bucketfs/bitbucket_filesystem.go b/bucketfs/bitbucket_filesystem.go index 7145113..713ea2e 100644 --- a/bucketfs/bitbucket_filesystem.go +++ b/bucketfs/bitbucket_filesystem.go @@ -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 { @@ -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) { diff --git a/dummy.go b/dummy.go index 674eee8..81a140e 100644 --- a/dummy.go +++ b/dummy.go @@ -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 @@ -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 diff --git a/filesystem.go b/filesystem.go index c3f2f9d..736b122 100644 --- a/filesystem.go +++ b/filesystem.go @@ -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 diff --git a/memfs/memfs.go b/memfs/memfs.go index bcf3b65..c54e6d9 100644 --- a/memfs/memfs.go +++ b/memfs/memfs.go @@ -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, @@ -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 { diff --git a/mountfs/mountfs.go b/mountfs/mountfs.go index 402885f..2bcd52b 100644 --- a/mountfs/mountfs.go +++ b/mountfs/mountfs.go @@ -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 { @@ -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())) diff --git a/os.go b/os.go index 4382510..82c016a 100644 --- a/os.go +++ b/os.go @@ -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) diff --git a/prefixfs/prefixfs.go b/prefixfs/prefixfs.go index a4c0725..d37dd8f 100644 --- a/prefixfs/prefixfs.go +++ b/prefixfs/prefixfs.go @@ -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} } @@ -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)) @@ -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))