Skip to content

Commit f312657

Browse files
committed
Extend missing-agent-dir guard to Linux and macOS cleanup paths
handleLinuxCleanup and handleMacosCleanup also did an unconditional writeFileSync to a path inside the agent dir, throwing ENOENT when Pre-step crashed before installing the agent (proven by integration test on synthetic-reject branch). Mirror the same dir-existence check that handleWindowsCleanup already has.
1 parent 0c7c518 commit f312657

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎dist/post/index.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32298,6 +32298,12 @@ function handleLinuxCleanup() {
3229832298
if (process.env.STATE_isTLS === "false" && process.arch === "arm64") {
3229932299
return;
3230032300
}
32301+
// If Pre-step crashed before installing the agent, /home/agent doesn't exist;
32302+
// bail out instead of throwing ENOENT on the writeFileSync below.
32303+
if (!external_fs_.existsSync("/home/agent")) {
32304+
console.log("Linux cleanup: /home/agent not found; agent was not installed (Pre-step likely failed). Skipping.");
32305+
return;
32306+
}
3230132307
if (isGithubHosted() && external_fs_.existsSync("/home/agent/post_event.json")) {
3230232308
console.log("Post step already executed, skipping");
3230332309
return;
@@ -32357,6 +32363,12 @@ function handleLinuxCleanup() {
3235732363
function handleMacosCleanup() {
3235832364
return cleanup_awaiter(this, void 0, void 0, function* () {
3235932365
const post_event = "/opt/step-security/post_event.json";
32366+
// If Pre-step crashed before installing the agent, /opt/step-security doesn't
32367+
// exist; bail out instead of throwing ENOENT on the writeFileSync below.
32368+
if (!external_fs_.existsSync("/opt/step-security")) {
32369+
console.log("macOS cleanup: /opt/step-security not found; agent was not installed (Pre-step likely failed). Skipping.");
32370+
return;
32371+
}
3236032372
if (isGithubHosted() && external_fs_.existsSync(post_event)) {
3236132373
console.log("Post step already executed, skipping");
3236232374
return;

‎dist/post/index.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/cleanup.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ async function handleLinuxCleanup() {
122122
return;
123123
}
124124

125+
// If Pre-step crashed before installing the agent, /home/agent doesn't exist;
126+
// bail out instead of throwing ENOENT on the writeFileSync below.
127+
if (!fs.existsSync("/home/agent")) {
128+
console.log(
129+
"Linux cleanup: /home/agent not found; agent was not installed (Pre-step likely failed). Skipping."
130+
);
131+
return;
132+
}
133+
125134
if (isGithubHosted() && fs.existsSync("/home/agent/post_event.json")) {
126135
console.log("Post step already executed, skipping");
127136
return;
@@ -193,6 +202,15 @@ async function handleLinuxCleanup() {
193202
async function handleMacosCleanup() {
194203
const post_event = "/opt/step-security/post_event.json";
195204

205+
// If Pre-step crashed before installing the agent, /opt/step-security doesn't
206+
// exist; bail out instead of throwing ENOENT on the writeFileSync below.
207+
if (!fs.existsSync("/opt/step-security")) {
208+
console.log(
209+
"macOS cleanup: /opt/step-security not found; agent was not installed (Pre-step likely failed). Skipping."
210+
);
211+
return;
212+
}
213+
196214
if (isGithubHosted() && fs.existsSync(post_event)) {
197215
console.log("Post step already executed, skipping");
198216
return;

0 commit comments

Comments
 (0)