Skip to content

Fix: Ignore missing folders during removeDir to prevent deployment failures #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4632,17 +4632,26 @@ class Client {
* @example client.removeDir("/") // Remove everything.
*/
async removeDir(remoteDirPath) {
return 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();
await this.clearWorkingDir();
const dirIsRoot = absoluteDirPath === "/";
if (!dirIsRoot) {
await this.cdup();
await this.removeEmptyDir(absoluteDirPath);
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();
await this.clearWorkingDir();
const dirIsRoot = absoluteDirPath === "/";
if (!dirIsRoot) {
await this.cdup();
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
Expand Down