| 199 | // processing. |
| 200 | |
| 201 | public rename(oldPath: string, newPath: string, cb: BFSOneArgCallback): void { |
| 202 | // Scenario 1: old and new are on same FS. |
| 203 | const fs1rv = this._getFs(oldPath); |
| 204 | const fs2rv = this._getFs(newPath); |
| 205 | if (fs1rv.fs === fs2rv.fs) { |
| 206 | return fs1rv.fs.rename(fs1rv.path, fs2rv.path, (e?: ApiError) => { |
| 207 | if (e) { |
| 208 | this.standardizeError(this.standardizeError(e, fs1rv.path, oldPath), fs2rv.path, newPath); |
| 209 | } |
| 210 | cb(e); |
| 211 | }); |
| 212 | } |
| 213 | |
| 214 | // Scenario 2: Different file systems. |
| 215 | // Read old file, write new file, delete old file. |
| 216 | return fs.readFile(oldPath, function(err: ApiError, data?: any) { |
| 217 | if (err) { |
| 218 | return cb(err); |
| 219 | } |
| 220 | fs.writeFile(newPath, data, function(err: ApiError) { |
| 221 | if (err) { |
| 222 | return cb(err); |
| 223 | } |
| 224 | fs.unlink(oldPath, cb); |
| 225 | }); |
| 226 | }); |
| 227 | } |
| 228 | |
| 229 | public renameSync(oldPath: string, newPath: string): void { |
| 230 | // Scenario 1: old and new are on same FS. |