|
|
|
@@ -34,26 +34,36 @@ var rmCmd = cli.Command{
|
|
|
|
|
mc {{.Name}} - {{.Usage}}
|
|
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
|
mc {{.Name}} TARGET
|
|
|
|
|
mc {{.Name}} TARGET [incomplete] [force]
|
|
|
|
|
|
|
|
|
|
incomplete - remove incomplete uploads
|
|
|
|
|
force - force recursive remove
|
|
|
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
1. Remove a file on Cloud storage
|
|
|
|
|
$ mc {{.Name}} https://s3.amazonaws.com/jazz-songs/louis/file01.mp3
|
|
|
|
|
|
|
|
|
|
2. Remove a folder recursively on Cloud storage
|
|
|
|
|
$ mc {{.Name}} force https://s3.amazonaws.com/jazz-songs/louis/...
|
|
|
|
|
$ mc {{.Name}} https://s3.amazonaws.com/jazz-songs/louis/... force
|
|
|
|
|
|
|
|
|
|
3. Remove a bucket on Minio cloud storage
|
|
|
|
|
$ mc {{.Name}} https://play.minio.io:9000/mongodb-backup
|
|
|
|
|
|
|
|
|
|
4. Remove a bucket on Cloud storage recursively
|
|
|
|
|
$ mc {{.Name}} force https://s3.amazonaws.com/jazz-songs/...
|
|
|
|
|
$ mc {{.Name}} https://s3.amazonaws.com/jazz-songs/... force
|
|
|
|
|
|
|
|
|
|
5. Remove a file on local filesystem:
|
|
|
|
|
$ mc {{.Name}} march/expenses.doc
|
|
|
|
|
|
|
|
|
|
6. Remove a file named "force" on local filesystem:
|
|
|
|
|
$ mc {{.Name}} force force
|
|
|
|
|
|
|
|
|
|
7. Remove incomplete upload of a file on Cloud storage:
|
|
|
|
|
$ mc {{.Name}} https://s3.amazonaws.com/jazz-songs/louis/file01.mp3 incomplete
|
|
|
|
|
|
|
|
|
|
2. Remove incomplete uploads of folder recursively on Cloud storage
|
|
|
|
|
$ mc {{.Name}} force https://s3.amazonaws.com/jazz-songs/louis/... incomplete force
|
|
|
|
|
|
|
|
|
|
`,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -106,11 +116,6 @@ func rm(url string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func rmAll(url string) {
|
|
|
|
|
clnt, err := url2Client(url)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errorIf(err.Trace(), "Unable to get client object for "+url)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
urlPartial1 := url2Dir(url)
|
|
|
|
|
out, err := rmList(url)
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -127,10 +132,35 @@ func rmAll(url string) {
|
|
|
|
|
err = newclnt.Remove()
|
|
|
|
|
errorIf(err, "Unable to remove : "+urlFull)
|
|
|
|
|
}
|
|
|
|
|
_, err = clnt.Stat()
|
|
|
|
|
if err == nil {
|
|
|
|
|
err = clnt.Remove()
|
|
|
|
|
errorIf(err, "Unable to remove : "+clnt.URL().String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func rmIncompleteUpload(url string) {
|
|
|
|
|
clnt, err := url2Client(url)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errorIf(err.Trace(), "Unable to get client object for "+url)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
err = clnt.RemoveIncompleteUpload()
|
|
|
|
|
errorIf(err.Trace(), "Unable to remove "+url)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func rmAllIncompleteUploads(url string) {
|
|
|
|
|
clnt, err := url2Client(url)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errorIf(err.Trace(), "Unable to get client object for "+url)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
urlPartial1 := url2Dir(url)
|
|
|
|
|
ch := clnt.List(true, true)
|
|
|
|
|
for entry := range ch {
|
|
|
|
|
urlFull := urlPartial1 + entry.Content.Name
|
|
|
|
|
newclnt, e := url2Client(urlFull)
|
|
|
|
|
if e != nil {
|
|
|
|
|
errorIf(e, "Unable to create client object : "+urlFull)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
err = newclnt.RemoveIncompleteUpload()
|
|
|
|
|
errorIf(err, "Unable to remove : "+urlFull)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -138,15 +168,20 @@ func checkRmSyntax(ctx *cli.Context) {
|
|
|
|
|
args, err := args2URLs(ctx.Args())
|
|
|
|
|
fatalIf(err.Trace(), "args2URL failed")
|
|
|
|
|
var force bool
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
|
length := len(args)
|
|
|
|
|
if length == 0 {
|
|
|
|
|
cli.ShowCommandHelpAndExit(ctx, "rm", 1) // last argument is exit code.
|
|
|
|
|
}
|
|
|
|
|
if len(args) == 1 && args[0] == "force" {
|
|
|
|
|
cli.ShowCommandHelpAndExit(ctx, "rm", 1)
|
|
|
|
|
}
|
|
|
|
|
if args[0] == "force" {
|
|
|
|
|
if args[length-1] == "force" {
|
|
|
|
|
force = true
|
|
|
|
|
args = args[1:]
|
|
|
|
|
args = args[:length-1]
|
|
|
|
|
length--
|
|
|
|
|
}
|
|
|
|
|
if args[length-1] == "incomplete" {
|
|
|
|
|
args = args[:length-1]
|
|
|
|
|
}
|
|
|
|
|
// If input validation fails then provide context sensitive help without displaying generic help message.
|
|
|
|
|
// The context sensitive help is shown per argument instead of all arguments to keep the help display
|
|
|
|
@@ -154,11 +189,11 @@ func checkRmSyntax(ctx *cli.Context) {
|
|
|
|
|
for _, arg := range args {
|
|
|
|
|
url := client.NewURL(arg)
|
|
|
|
|
if strings.HasSuffix(arg, string(url.Separator)) {
|
|
|
|
|
helpStr := "Usage : mc rm force " + arg + recursiveSeparator
|
|
|
|
|
helpStr := "Usage : mc rm " + arg + recursiveSeparator + " force"
|
|
|
|
|
fatalIf(errDummy().Trace(), helpStr)
|
|
|
|
|
}
|
|
|
|
|
if isURLRecursive(arg) && !force {
|
|
|
|
|
helpStr := "Usage : mc rm force " + arg
|
|
|
|
|
helpStr := "Usage : mc rm " + arg + " force"
|
|
|
|
|
fatalIf(errDummy().Trace(), helpStr)
|
|
|
|
|
}
|
|
|
|
|
if url.Type == client.Filesystem {
|
|
|
|
@@ -167,7 +202,7 @@ func checkRmSyntax(ctx *cli.Context) {
|
|
|
|
|
isRecursive := isURLRecursive(arg)
|
|
|
|
|
path := stripRecursiveURL(arg)
|
|
|
|
|
if isRecursive && (strings.HasSuffix(path, string(url.Separator)) == false) {
|
|
|
|
|
helpStr := "Usage : mc rm force " + path + string(url.Separator) + recursiveSeparator
|
|
|
|
|
helpStr := "Usage : mc rm " + path + string(url.Separator) + recursiveSeparator + " force"
|
|
|
|
|
fatalIf(errDummy().Trace(), helpStr)
|
|
|
|
|
}
|
|
|
|
|
_, content, err := url2Stat(path)
|
|
|
|
@@ -175,7 +210,7 @@ func checkRmSyntax(ctx *cli.Context) {
|
|
|
|
|
fatalIf(err.Trace(), "url2stat error on "+arg)
|
|
|
|
|
}
|
|
|
|
|
if content.Type&os.ModeDir != 0 && !isRecursive {
|
|
|
|
|
helpStr := "Usage : mc rm force " + arg + string(url.Separator) + recursiveSeparator
|
|
|
|
|
helpStr := "Usage : mc rm " + arg + string(url.Separator) + recursiveSeparator + " force"
|
|
|
|
|
fatalIf(errDummy().Trace(), helpStr)
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
@@ -187,15 +222,34 @@ func mainRm(ctx *cli.Context) {
|
|
|
|
|
checkRmSyntax(ctx)
|
|
|
|
|
args, err := args2URLs(ctx.Args())
|
|
|
|
|
fatalIf(err.Trace(), "args2URL failed")
|
|
|
|
|
if args[0] == "force" {
|
|
|
|
|
args = args[1:]
|
|
|
|
|
var incomplete bool
|
|
|
|
|
length := len(args)
|
|
|
|
|
|
|
|
|
|
if args[length-1] == "force" {
|
|
|
|
|
args = args[:length-1]
|
|
|
|
|
length--
|
|
|
|
|
}
|
|
|
|
|
for _, arg := range args {
|
|
|
|
|
if isURLRecursive(arg) {
|
|
|
|
|
url := stripRecursiveURL(arg)
|
|
|
|
|
rmAll(url)
|
|
|
|
|
} else {
|
|
|
|
|
rm(arg)
|
|
|
|
|
if args[length-1] == "incomplete" {
|
|
|
|
|
args = args[:length-1]
|
|
|
|
|
incomplete = true
|
|
|
|
|
}
|
|
|
|
|
if incomplete {
|
|
|
|
|
for _, arg := range args {
|
|
|
|
|
if isURLRecursive(arg) {
|
|
|
|
|
url := stripRecursiveURL(arg)
|
|
|
|
|
rmAllIncompleteUploads(url)
|
|
|
|
|
} else {
|
|
|
|
|
rmIncompleteUpload(arg)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for _, arg := range args {
|
|
|
|
|
if isURLRecursive(arg) {
|
|
|
|
|
url := stripRecursiveURL(arg)
|
|
|
|
|
rmAll(url)
|
|
|
|
|
} else {
|
|
|
|
|
rm(arg)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|