From 6b4d97675510888fc13a938d9d201567316df90b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 17 Nov 2015 17:13:02 -0800 Subject: [PATCH] rm: Do not try to remove the '.' --- rm-main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rm-main.go b/rm-main.go index 002d1a8b..dbeb160f 100644 --- a/rm-main.go +++ b/rm-main.go @@ -164,15 +164,14 @@ func rmAll(url string, isIncomplete bool) { if entry.Type.IsDir() { // Add separator at the end to remove all its contents. - url := entry.URL.String() - u := client.NewURL(url) - url = url + string(u.Separator) + url := entry.URL + url.Path = strings.TrimSuffix(entry.URL.Path, string(entry.URL.Separator)) + string(entry.URL.Separator) // Recursively remove contents of this directory. - rmAll(url, isIncomplete) + rmAll(url.String(), isIncomplete) } // Regular type. - err := rm(entry.URL.String(), isIncomplete) + err = rm(entry.URL.String(), isIncomplete) if err != nil { errorIf(err.Trace(entry.URL.String()), "Unable to remove ‘"+entry.URL.String()+"’.") continue @@ -208,9 +207,9 @@ func mainRm(ctx *cli.Context) { } if err == nil && content.Type.IsDir() { - /* Determine whether to remove the top folder or only its - contents. If the URL does not end with a separator, then - include the top folder as well, otherwise not. */ + // Determine whether to remove the top folder or only its + // contents. If the URL does not end with a separator, then + // include the top folder as well, otherwise not. u := client.NewURL(url) if !strings.HasSuffix(url, string(u.Separator)) { // Add separator at the end to remove all its contents. @@ -221,7 +220,8 @@ func mainRm(ctx *cli.Context) { } // Remove contents of this folder. rmAll(url, isIncomplete) - if removeTopFolder { + // url will be '.' for arguments which will be just '...' + if removeTopFolder && url != "." && url != ".." { // Remove top folder as well. err := rm(url, isIncomplete) if err != nil {