From cecc409a718ec2cc0bd1da53192a93429b7e6f11 Mon Sep 17 00:00:00 2001 From: Krishna Srinivas Date: Wed, 18 Nov 2015 22:25:27 -0800 Subject: [PATCH] Do a stat on files for non-recursive rm before removing to detect non-existing files --- rm-main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rm-main.go b/rm-main.go index f607205b..882cac53 100644 --- a/rm-main.go +++ b/rm-main.go @@ -115,6 +115,16 @@ func checkRmSyntax(ctx *cli.Context) { cli.ShowCommandHelpAndExit(ctx, "rm", exitCode) } + if !isRecursive { + URLs, err := args2URLs(ctx.Args()) + fatalIf(err.Trace(ctx.Args()...), "Unable to parse arguments.") + for _, url := range URLs { + if _, _, err := url2Stat(url); err != nil { + fatalIf(err.Trace(url), "Unable to stat.") + } + } + } + if isRecursive && !isForce { fatalIf(errDummy().Trace(), "Recursive removal requires --force option. Please review carefully before performing this *DANGEROUS* operation.")