mirror of
https://github.com/rclone/rclone.git
synced 2024-11-08 09:35:26 +01:00
f78cd1e043
- Change rclone/fs interfaces to accept context.Context - Update interface implementations to use context.Context - Change top level usage to propagate context to lover level functions Context propagation is needed for stopping transfers and passing other request-scoped values.
39 lines
1017 B
Go
39 lines
1017 B
Go
package deletefile
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ncw/rclone/cmd"
|
|
"github.com/ncw/rclone/fs/operations"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func init() {
|
|
cmd.Root.AddCommand(commandDefintion)
|
|
}
|
|
|
|
var commandDefintion = &cobra.Command{
|
|
Use: "deletefile remote:path",
|
|
Short: `Remove a single file from remote.`,
|
|
Long: `
|
|
Remove a single file from remote. Unlike ` + "`" + `delete` + "`" + ` it cannot be used to
|
|
remove a directory and it doesn't obey include/exclude filters - if the specified file exists,
|
|
it will always be removed.
|
|
`,
|
|
Run: func(command *cobra.Command, args []string) {
|
|
cmd.CheckArgs(1, 1, command, args)
|
|
fs, fileName := cmd.NewFsFile(args[0])
|
|
cmd.Run(true, false, command, func() error {
|
|
if fileName == "" {
|
|
return errors.Errorf("%s is a directory or doesn't exist", args[0])
|
|
}
|
|
fileObj, err := fs.NewObject(context.Background(), fileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return operations.DeleteFile(context.Background(), fileObj)
|
|
})
|
|
},
|
|
}
|