| 120 | |
| 121 | |
| 122 | function _rmchildren(path, options, callback) { |
| 123 | const pathBuf = Buffer.from(path); |
| 124 | |
| 125 | readdir(pathBuf, readdirEncoding, (err, files) => { |
| 126 | if (err) |
| 127 | return callback(err); |
| 128 | |
| 129 | let numFiles = files.length; |
| 130 | |
| 131 | if (numFiles === 0) |
| 132 | return rmdir(path, callback); |
| 133 | |
| 134 | let done = false; |
| 135 | |
| 136 | const childPathPrefix = Buffer.concat([pathBuf, separator]); |
| 137 | |
| 138 | for (let i = 0; i < files.length; i++) { |
| 139 | const childPath = Buffer.concat([childPathPrefix, files[i]]); |
| 140 | |
| 141 | rimraf(childPath, options, (err) => { |
| 142 | if (done) |
| 143 | return; |
| 144 | |
| 145 | if (err) { |
| 146 | done = true; |
| 147 | return callback(err); |
| 148 | } |
| 149 | |
| 150 | numFiles--; |
| 151 | if (numFiles === 0) |
| 152 | rmdir(path, callback); |
| 153 | }); |
| 154 | } |
| 155 | }); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | function rimrafPromises(path, options) { |