2022-08-28 13:21:57 +02:00
|
|
|
// Package deletefile provides the deletefile command.
|
2018-06-09 18:22:25 +02:00
|
|
|
package deletefile
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
2021-11-04 11:12:57 +01:00
|
|
|
"fmt"
|
2019-06-17 10:34:30 +02:00
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/cmd"
|
2023-03-03 10:49:05 +01:00
|
|
|
"github.com/rclone/rclone/fs"
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2018-06-09 18:22:25 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-10-11 17:58:11 +02:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2018-06-09 18:22:25 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 17:58:11 +02:00
|
|
|
var commandDefinition = &cobra.Command{
|
2018-06-09 18:22:25 +02:00
|
|
|
Use: "deletefile remote:path",
|
2018-06-17 17:58:37 +02:00
|
|
|
Short: `Remove a single file from remote.`,
|
2024-08-12 18:17:46 +02:00
|
|
|
Long: `Remove a single file from remote. Unlike ` + "`" + `delete` + "`" + ` it cannot be used to
|
2018-06-09 18:22:25 +02:00
|
|
|
remove a directory and it doesn't obey include/exclude filters - if the specified file exists,
|
|
|
|
it will always be removed.
|
|
|
|
`,
|
2022-11-26 23:40:49 +01:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.42",
|
2023-07-10 19:34:10 +02:00
|
|
|
"groups": "Important",
|
2022-11-26 23:40:49 +01:00
|
|
|
},
|
2018-06-09 18:22:25 +02:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
2023-03-03 10:49:05 +01:00
|
|
|
f, fileName := cmd.NewFsFile(args[0])
|
2018-06-09 18:22:25 +02:00
|
|
|
cmd.Run(true, false, command, func() error {
|
|
|
|
if fileName == "" {
|
2023-03-03 10:49:05 +01:00
|
|
|
return fmt.Errorf("%s is a directory or doesn't exist: %w", args[0], fs.ErrorObjectNotFound)
|
2018-06-09 18:22:25 +02:00
|
|
|
}
|
2023-03-03 10:49:05 +01:00
|
|
|
fileObj, err := f.NewObject(context.Background(), fileName)
|
2018-06-09 18:22:25 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-17 10:34:30 +02:00
|
|
|
return operations.DeleteFile(context.Background(), fileObj)
|
2018-06-09 18:22:25 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|