Skip to content

Commit fc81301

Browse files
committed
Update cli-release-build.yml
1 parent 3c03fac commit fc81301

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

.github/workflows/cli-release-build.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,44 @@ jobs:
122122
continue;
123123
}
124124
125-
if (fs.existsSync(link)) {
125+
let linkStats = null;
126+
try {
127+
linkStats = fs.lstatSync(link);
128+
} catch (error) {
129+
if (error?.code !== 'ENOENT') {
130+
throw error;
131+
}
132+
}
133+
134+
if (linkStats) {
135+
let alreadyLinked = false;
126136
try {
127137
const actual = fs.realpathSync(link);
128-
if (actual === target) {
129-
continue;
130-
}
131-
} catch (error) {
132-
// If the link is broken or realpath fails, remove it.
138+
alreadyLinked = actual === target;
139+
} catch {
140+
// Broken symlink or unreadable target; we'll replace it.
141+
}
142+
143+
if (alreadyLinked) {
144+
continue;
133145
}
146+
134147
fs.rmSync(link, { recursive: true, force: true });
135148
}
136149
137150
const type = process.platform === 'win32' ? 'junction' : 'dir';
138-
fs.symlinkSync(target, link, type);
139-
console.log(`Linked ${link} -> ${target}`);
151+
try {
152+
fs.symlinkSync(target, link, type);
153+
console.log(`Linked ${link} -> ${target}`);
154+
} catch (error) {
155+
if (error?.code === 'EEXIST') {
156+
fs.rmSync(link, { recursive: true, force: true });
157+
fs.symlinkSync(target, link, type);
158+
console.log(`Re-linked ${link} -> ${target}`);
159+
} else {
160+
throw error;
161+
}
162+
}
140163
}
141164
NODE
142165

0 commit comments

Comments
 (0)