@@ -6,6 +6,7 @@ common.register('rm', _rm, {
6
6
'f' : 'force' ,
7
7
'r' : 'recursive' ,
8
8
'R' : 'recursive' ,
9
+ 'v' : 'verbose' ,
9
10
} ,
10
11
} ) ;
11
12
@@ -17,7 +18,7 @@ common.register('rm', _rm, {
17
18
//
18
19
// Licensed under the MIT License
19
20
// http://www.opensource.org/licenses/mit-license.php
20
- function rmdirSyncRecursive ( dir , force , fromSymlink ) {
21
+ function rmdirSyncRecursive ( dir , force , verbose , fromSymlink ) {
21
22
var files ;
22
23
23
24
files = fs . readdirSync ( dir ) ;
@@ -28,11 +29,14 @@ function rmdirSyncRecursive(dir, force, fromSymlink) {
28
29
var currFile = common . statNoFollowLinks ( file ) ;
29
30
30
31
if ( currFile . isDirectory ( ) ) { // Recursive function back to the beginning
31
- rmdirSyncRecursive ( file , force ) ;
32
+ rmdirSyncRecursive ( file , force , verbose ) ;
32
33
} else if ( force || isWriteable ( file ) ) {
33
34
// Assume it's a file - perhaps a try/catch belongs here?
34
35
try {
35
36
common . unlinkSync ( file ) ;
37
+ if ( verbose ) {
38
+ console . log ( "removed '" + file + "'" ) ;
39
+ }
36
40
} catch ( e ) {
37
41
/* istanbul ignore next */
38
42
common . error ( 'could not remove file (code ' + e . code + '): ' + file , {
@@ -59,6 +63,9 @@ function rmdirSyncRecursive(dir, force, fromSymlink) {
59
63
try {
60
64
result = fs . rmdirSync ( dir ) ;
61
65
if ( fs . existsSync ( dir ) ) throw { code : 'EAGAIN' } ;
66
+ if ( verbose ) {
67
+ console . log ( "removed directory'" + dir + "'" ) ;
68
+ }
62
69
break ;
63
70
} catch ( er ) {
64
71
/* istanbul ignore next */
@@ -98,6 +105,9 @@ function handleFile(file, options) {
98
105
if ( options . force || isWriteable ( file ) ) {
99
106
// -f was passed, or file is writable, so it can be removed
100
107
common . unlinkSync ( file ) ;
108
+ if ( options . verbose ) {
109
+ console . log ( "removed '" + file + "'" ) ;
110
+ }
101
111
} else {
102
112
common . error ( 'permission denied: ' + file , { continue : true } ) ;
103
113
}
@@ -106,43 +116,53 @@ function handleFile(file, options) {
106
116
function handleDirectory ( file , options ) {
107
117
if ( options . recursive ) {
108
118
// -r was passed, so directory can be removed
109
- rmdirSyncRecursive ( file , options . force ) ;
119
+ rmdirSyncRecursive ( file , options . force , options . verbose ) ;
110
120
} else {
111
121
common . error ( 'path is a directory' , { continue : true } ) ;
112
122
}
113
123
}
114
124
115
125
function handleSymbolicLink ( file , options ) {
126
+ function _unlink ( ) {
127
+ common . unlinkSync ( file ) ;
128
+ if ( options . verbose ) {
129
+ console . log ( "removed '" + file + "'" ) ;
130
+ }
131
+ }
132
+
116
133
var stats ;
117
134
try {
118
135
stats = common . statFollowLinks ( file ) ;
119
136
} catch ( e ) {
120
137
// symlink is broken, so remove the symlink itself
121
- common . unlinkSync ( file ) ;
138
+ _unlink ( ) ;
122
139
return ;
123
140
}
124
141
125
142
if ( stats . isFile ( ) ) {
126
- common . unlinkSync ( file ) ;
143
+ _unlink ( ) ;
127
144
} else if ( stats . isDirectory ( ) ) {
128
145
if ( file [ file . length - 1 ] === '/' ) {
129
146
// trailing separator, so remove the contents, not the link
130
147
if ( options . recursive ) {
131
148
// -r was passed, so directory can be removed
132
149
var fromSymlink = true ;
133
- rmdirSyncRecursive ( file , options . force , fromSymlink ) ;
150
+ rmdirSyncRecursive ( file , options . force , options . verbose , fromSymlink ) ;
134
151
} else {
135
152
common . error ( 'path is a directory' , { continue : true } ) ;
136
153
}
137
154
} else {
138
155
// no trailing separator, so remove the link
139
- common . unlinkSync ( file ) ;
156
+ _unlink ( ) ;
140
157
}
141
158
}
142
159
}
143
160
144
- function handleFIFO ( file ) {
161
+ function handleFIFO ( file , options ) {
145
162
common . unlinkSync ( file ) ;
163
+ if ( options . verbose ) {
164
+ console . log ( "removed '" + file + "'" ) ;
165
+ }
146
166
}
147
167
148
168
//@
@@ -193,7 +213,7 @@ function _rm(options, files) {
193
213
} else if ( lstats . isSymbolicLink ( ) ) {
194
214
handleSymbolicLink ( file , options ) ;
195
215
} else if ( lstats . isFIFO ( ) ) {
196
- handleFIFO ( file ) ;
216
+ handleFIFO ( file , options ) ;
197
217
}
198
218
} ) ; // forEach(file)
199
219
return '' ;
0 commit comments