2022-02-13 09:34:19 +00:00
|
|
|
package mount
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/hanwen/go-fuse/v2/fuse"
|
|
|
|
"os"
|
2022-02-13 09:43:11 +00:00
|
|
|
"strings"
|
|
|
|
"syscall"
|
2022-02-13 09:34:19 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2022-02-13 12:22:02 +00:00
|
|
|
/** Create a directory
|
|
|
|
*
|
|
|
|
* Note that the mode argument may not have the type specification
|
|
|
|
* bits set, i.e. S_ISDIR(mode) can be false. To obtain the
|
|
|
|
* correct directory type bits use mode|S_IFDIR
|
|
|
|
* */
|
2022-02-13 09:34:19 +00:00
|
|
|
func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) {
|
|
|
|
|
2022-03-06 06:10:43 +00:00
|
|
|
if wfs.IsOverQuota {
|
2022-03-07 01:04:21 +00:00
|
|
|
return fuse.Status(syscall.ENOSPC)
|
2022-03-06 06:10:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 09:34:19 +00:00
|
|
|
if s := checkName(name); s != fuse.OK {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
newEntry := &filer_pb.Entry{
|
|
|
|
Name: name,
|
|
|
|
IsDirectory: true,
|
|
|
|
Attributes: &filer_pb.FuseAttributes{
|
|
|
|
Mtime: time.Now().Unix(),
|
|
|
|
Crtime: time.Now().Unix(),
|
|
|
|
FileMode: uint32(os.ModeDir) | in.Mode&^uint32(wfs.option.Umask),
|
|
|
|
Uid: in.Uid,
|
|
|
|
Gid: in.Gid,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-02-18 08:45:43 +00:00
|
|
|
dirFullPath, code := wfs.inodeToPath.GetPath(in.NodeId)
|
|
|
|
if code != fuse.OK {
|
|
|
|
return
|
|
|
|
}
|
2022-02-13 09:34:19 +00:00
|
|
|
|
|
|
|
entryFullPath := dirFullPath.Child(name)
|
|
|
|
|
|
|
|
err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
|
|
|
|
wfs.mapPbIdFromLocalToFiler(newEntry)
|
|
|
|
defer wfs.mapPbIdFromFilerToLocal(newEntry)
|
|
|
|
|
|
|
|
request := &filer_pb.CreateEntryRequest{
|
|
|
|
Directory: string(dirFullPath),
|
|
|
|
Entry: newEntry,
|
|
|
|
Signatures: []int32{wfs.signature},
|
|
|
|
}
|
|
|
|
|
|
|
|
glog.V(1).Infof("mkdir: %v", request)
|
|
|
|
if err := filer_pb.CreateEntry(client, request); err != nil {
|
|
|
|
glog.V(0).Infof("mkdir %s: %v", entryFullPath, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
|
|
|
|
return fmt.Errorf("local mkdir dir %s: %v", entryFullPath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2022-02-16 16:45:07 +00:00
|
|
|
glog.V(3).Infof("mkdir %s: %v", entryFullPath, err)
|
2022-02-13 09:34:19 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
|
2022-03-14 07:03:29 +00:00
|
|
|
inode := wfs.inodeToPath.Lookup(entryFullPath, newEntry.Attributes.Crtime, true, false, 0, true)
|
2022-02-13 09:34:19 +00:00
|
|
|
|
|
|
|
wfs.outputPbEntry(out, inode, newEntry)
|
|
|
|
|
|
|
|
return fuse.OK
|
|
|
|
|
|
|
|
}
|
2022-02-13 09:43:11 +00:00
|
|
|
|
2022-02-13 12:22:02 +00:00
|
|
|
/** Remove a directory */
|
2022-02-13 09:43:11 +00:00
|
|
|
func (wfs *WFS) Rmdir(cancel <-chan struct{}, header *fuse.InHeader, name string) (code fuse.Status) {
|
|
|
|
|
|
|
|
if name == "." {
|
|
|
|
return fuse.Status(syscall.EINVAL)
|
|
|
|
}
|
|
|
|
if name == ".." {
|
|
|
|
return fuse.Status(syscall.ENOTEMPTY)
|
|
|
|
}
|
|
|
|
|
2022-02-18 08:45:43 +00:00
|
|
|
dirFullPath, code := wfs.inodeToPath.GetPath(header.NodeId)
|
|
|
|
if code != fuse.OK {
|
|
|
|
return
|
|
|
|
}
|
2022-02-13 09:43:11 +00:00
|
|
|
entryFullPath := dirFullPath.Child(name)
|
|
|
|
|
|
|
|
glog.V(3).Infof("remove directory: %v", entryFullPath)
|
|
|
|
ignoreRecursiveErr := true // ignore recursion error since the OS should manage it
|
|
|
|
err := filer_pb.Remove(wfs, string(dirFullPath), name, true, true, ignoreRecursiveErr, false, []int32{wfs.signature})
|
|
|
|
if err != nil {
|
|
|
|
glog.V(0).Infof("remove %s: %v", entryFullPath, err)
|
|
|
|
if strings.Contains(err.Error(), filer.MsgFailDelNonEmptyFolder) {
|
|
|
|
return fuse.Status(syscall.ENOTEMPTY)
|
|
|
|
}
|
|
|
|
return fuse.ENOENT
|
|
|
|
}
|
|
|
|
|
|
|
|
wfs.metaCache.DeleteEntry(context.Background(), entryFullPath)
|
2022-02-13 11:09:24 +00:00
|
|
|
wfs.inodeToPath.RemovePath(entryFullPath)
|
2022-02-13 09:43:11 +00:00
|
|
|
|
|
|
|
return fuse.OK
|
|
|
|
|
|
|
|
}
|