@@ -17,8 +17,6 @@ import (
17
17
const TRASH_DIR_PERMISSIONS = 0755
18
18
19
19
func RmPatch (arguments []string , config models.Config ) {
20
- silent := util .InArray (arguments , cli .SILENT_CLA )
21
- dryRun := util .InArray (arguments , cli .DRY_RUN_CLA )
22
20
shouldNotify := util .InArray (arguments , cli .NOTIFICATION_CLA )
23
21
24
22
requestingHelp := util .InArray (arguments , cli .HELP_CLA )
@@ -35,19 +33,6 @@ func RmPatch(arguments []string, config models.Config) {
35
33
}
36
34
37
35
filePaths := extractFilePaths (actionedArgs )
38
-
39
- // a debug statement is useful for scripts, it provides explicit feedback
40
- // and prints exactly what files were backed up / moved to the trash can
41
- // after deletion
42
- debugStatement := strings .Join (filePaths , " " )
43
- if ! silent {
44
- fmt .Println (debugStatement )
45
- }
46
-
47
- if dryRun {
48
- return
49
- }
50
-
51
36
deletePaths (filePaths , config , arguments )
52
37
53
38
if shouldNotify {
@@ -118,6 +103,7 @@ func deletePaths(paths []string, config models.Config, arguments []string) {
118
103
bypassProtected := util .InArray (arguments , cli .BYPASS_PROTECTED_CLA )
119
104
overwrite := util .InArray (arguments , cli .OVERWRITE_CLA )
120
105
silent := util .InArray (arguments , cli .SILENT_CLA )
106
+ dryRun := util .InArray (arguments , cli .DRY_RUN_CLA )
121
107
122
108
hasInteraciveCla := util .InArray (arguments , cli .INTERACTIVE_CLA )
123
109
hasGroupInteractiveCla := util .InArray (arguments , cli .INTERACTIVE_GROUP_CLA )
@@ -134,7 +120,13 @@ func deletePaths(paths []string, config models.Config, arguments []string) {
134
120
hasVerboseCla = util .InArray (arguments , cli .VERBOSE_SHORT_CLA )
135
121
}
136
122
123
+ removedFiles := []string {}
137
124
for _ , path := range paths {
125
+ if ! util .PathExists (path ) {
126
+ fmt .Println ("2rm: Cannot remove '" + path + "': No such file or directory" )
127
+ continue
128
+ }
129
+
138
130
if isInteractive {
139
131
fmt .Println ("Are you sure you want to delete" , path , "? (y/n)" )
140
132
var response string
@@ -175,21 +167,38 @@ func deletePaths(paths []string, config models.Config, arguments []string) {
175
167
// e.g. Who deleted this file? When was it deleted?
176
168
// if we hard deleted the file, we would lose this information
177
169
isConfigOverwrite := config .ShouldOverwrite (absolutePath )
178
- if overwrite || isConfigOverwrite {
170
+ if overwrite || isConfigOverwrite && ! dryRun {
179
171
overwriteFile (absolutePath )
180
172
}
181
173
182
174
shouldHardDelete := isTmp || forceHardDelete || isConfigHardDelete && ! isConfigSoftDelete && ! forceSoftDelete
183
175
184
- deletePath (absolutePath , shouldHardDelete , config )
176
+ deletePath (absolutePath , shouldHardDelete , dryRun , config )
185
177
186
178
if hasVerboseCla && ! silent {
187
179
fmt .Printf ("removed '%s'\n " , path )
188
180
}
181
+
182
+ removedFiles = append (removedFiles , path )
183
+ }
184
+
185
+ for _ , path := range removedFiles {
186
+ fmt .Print (path )
189
187
}
188
+ // do an empty print line last so that when the shell returns to a
189
+ // prompt the prompt will be on its own line
190
+ fmt .Println ()
190
191
}
191
192
192
- func deletePath (path string , hard bool , config models.Config ) {
193
+ func deletePath (path string , hard bool , dryRun bool , config models.Config ) {
194
+ // I break out during dry runs at the last possible point so that dry
195
+ // runs are as close to real runs as possible
196
+ // all the same debug information, deletion prompts and errors will be
197
+ // shown during dry runs
198
+ if dryRun {
199
+ return
200
+ }
201
+
193
202
if hard {
194
203
hardDelete (path )
195
204
} else {
0 commit comments