File tree Expand file tree Collapse file tree 1 file changed +31
-8
lines changed Expand file tree Collapse file tree 1 file changed +31
-8
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments