Merge 6b90cbdaf1b545fc01e063c4d59b76aee9169337 into a51268f67f6605236975928ae28b0f7e9971d50a

This commit is contained in:
Ghaith Atfeh 2025-08-26 09:37:28 +02:00 committed by GitHub
commit 4426d3a76e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

11
dist/index.js vendored
View File

@ -4642,7 +4642,8 @@ class Client {
* @example client.removeDir("/") // Remove everything.
*/
async removeDir(remoteDirPath) {
return this._exitAtCurrentDirectory(async () => {
try {
return await this._exitAtCurrentDirectory(async () => {
await this.cd(remoteDirPath);
// Get the absolute path of the target because remoteDirPath might be a relative path, even `../` is possible.
const absoluteDirPath = await this.pwd();
@ -4653,6 +4654,14 @@ class Client {
await this.removeEmptyDir(absoluteDirPath);
}
});
} catch (err) {
// Safely ignore if the folder doesn't exist
if (err.code === 550 || err.message.includes("No such file or directory") || err.message.includes("File not found")) {
console.warn(`Warning: Folder "${remoteDirPath}" not found, skipping deletion.`);
return;
}
throw err;
}
}
/**
* Remove all files and directories in the working directory without removing