MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / rename

Method rename

src/fileSystem/sftp.js:309–338  ·  view source on GitHub ↗

* Renames file and directory, it can also be use to move directory or file * @param {String} newname * @param {Boolean} move

(newname, move)

Source from the content-addressed store, hash-verified

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

Callers 1

moveToMethod · 0.95

Calls 7

#notConnectedMethod · 0.95
connectMethod · 0.95
#safeNameMethod · 0.95
resolveFunction · 0.85
basenameMethod · 0.80
isConnectedMethod · 0.65
renameMethod · 0.65

Tested by

no test coverage detected