123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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)
- }
|