mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Merge pull request #2200 from combineads/add_fs_rm
weed shell: fs.rm remove file or directory
This commit is contained in:
commit
3138805b33
67
weed/shell/command_fs_rm.go
Normal file
67
weed/shell/command_fs_rm.go
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
package shell
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Commands = append(Commands, &commandFsRm{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type commandFsRm struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *commandFsRm) Name() string {
|
||||||
|
return "fs.rm"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *commandFsRm) Help() string {
|
||||||
|
return `remove a file or a folder, recursively delete all files and folders
|
||||||
|
|
||||||
|
fs.rm <entry1>
|
||||||
|
|
||||||
|
fs.rm /dir/file_name
|
||||||
|
fs.rm /dir
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *commandFsRm) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
||||||
|
|
||||||
|
if len(args) != 1 {
|
||||||
|
return fmt.Errorf("need to have arguments")
|
||||||
|
}
|
||||||
|
|
||||||
|
targetPath, err := commandEnv.parseUrl(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
targetDir, targetName := util.FullPath(targetPath).DirAndName()
|
||||||
|
|
||||||
|
return commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
|
request := &filer_pb.DeleteEntryRequest{
|
||||||
|
Directory: targetDir,
|
||||||
|
Name: targetName,
|
||||||
|
IgnoreRecursiveError: true,
|
||||||
|
IsDeleteData: true,
|
||||||
|
IsRecursive: true,
|
||||||
|
IsFromOtherCluster: false,
|
||||||
|
Signatures: nil,
|
||||||
|
}
|
||||||
|
_, err = client.DeleteEntry(context.Background(), request)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
fmt.Fprintf(writer, "remove: %s\n", targetPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue