|
@@ -0,0 +1,161 @@
|
|
|
+package amntfs
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "github.com/spf13/afero"
|
|
|
+ "os"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+func (fs *AMNTFS) Create(name string) (afero.File, error) {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return nil, NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ file, err := f.GetFs().Create(r)
|
|
|
+ if err != nil {
|
|
|
+ return nil, NewAMNTFSChildFsError(f, err)
|
|
|
+ }
|
|
|
+ return file, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Mkdir(name string, perm os.FileMode) error {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return f.GetFs().Mkdir(r, perm)
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) MkdirAll(path string, perm os.FileMode) error {
|
|
|
+ f, r := fs.getMountEntity(path)
|
|
|
+ if f == nil {
|
|
|
+ return NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", path),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return f.GetFs().MkdirAll(r, perm)
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Open(name string) (afero.File, error) {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return nil, NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ file, err := f.GetFs().Open(r)
|
|
|
+ if err != nil {
|
|
|
+ return nil, NewAMNTFSChildFsError(f, err)
|
|
|
+ }
|
|
|
+ return file, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return nil, NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ file, err := f.GetFs().OpenFile(r, flag, perm)
|
|
|
+ if err != nil {
|
|
|
+ return nil, NewAMNTFSChildFsError(f, err)
|
|
|
+ }
|
|
|
+ return file, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Remove(name string) error {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return f.GetFs().Remove(r)
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) RemoveAll(path string) error {
|
|
|
+ f, r := fs.getMountEntity(path)
|
|
|
+ if f == nil {
|
|
|
+ return NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", path),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return f.GetFs().RemoveAll(r)
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Rename(oldname, newname string) error {
|
|
|
+ oldF, oldR := fs.getMountEntity(oldname)
|
|
|
+ newF, newR := fs.getMountEntity(newname)
|
|
|
+ if oldF == nil || newF == nil {
|
|
|
+ return NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' or '%' not belonging to any mounted fs", oldname, newname),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if oldF != newF {
|
|
|
+ return errors.New("rename across different file systems is not supported")
|
|
|
+ }
|
|
|
+ return oldF.GetFs().Rename(oldR, newR)
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Stat(name string) (os.FileInfo, error) {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return nil, NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return f.GetFs().Stat(r)
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Name() string {
|
|
|
+ return "AMNTFS"
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Chmod(name string, mode os.FileMode) error {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return f.GetFs().Chmod(r, mode)
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Chown(name string, uid, gid int) error {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return f.GetFs().Chown(r, uid, gid)
|
|
|
+}
|
|
|
+
|
|
|
+func (fs *AMNTFS) Chtimes(name string, atime time.Time, mtime time.Time) error {
|
|
|
+ f, r := fs.getMountEntity(name)
|
|
|
+ if f == nil {
|
|
|
+ return NewAMNTFSError(
|
|
|
+ ErrNoAvailableMountPointForThisPath,
|
|
|
+ fmt.Errorf("path '%' not belonging to any mounted fs", name),
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return f.GetFs().Chtimes(r, atime, mtime)
|
|
|
+}
|