* Renames file and directory, it can also be use to move directory or file * @param {String} newname * @param {Boolean} move
(newname, move)
| 307 | * @param {Boolean} move |
| 308 | */ |
| 309 | rename(newname, move) { |
| 310 | const src = this.#path; |
| 311 | return new Promise((resolve, reject) => { |
| 312 | sftp.isConnected((connectionID) => { |
| 313 | (async () => { |
| 314 | if (this.#notConnected(connectionID)) { |
| 315 | try { |
| 316 | await this.connect(); |
| 317 | } catch (error) { |
| 318 | reject(error); |
| 319 | return; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | newname = move ? newname : Path.join(Path.dirname(src), newname); |
| 324 | sftp.rename( |
| 325 | this.#safeName(src), |
| 326 | this.#safeName(newname), |
| 327 | async (_res) => { |
| 328 | const url = move ? Url.join(newname, Url.basename(src)) : newname; |
| 329 | resolve(Url.join(this.#base, url)); |
| 330 | }, |
| 331 | (err) => { |
| 332 | reject(err); |
| 333 | }, |
| 334 | ); |
| 335 | })(); |
| 336 | }, reject); |
| 337 | }); |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Delete file or directory |
no test coverage detected