Skip to content

Commit

Permalink
Fix windows issue symlinking (#3565)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndricimrr authored Dec 6, 2023
1 parent 598d04f commit 98b4517
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions symbolic-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,36 @@ async function createSymbolicLinkFromTo(source, destination, scope, index, numLi

// Function to create a symbolic link. Deletes destination folder if already exists
function createSymbolicLink(source, target) {
return new Promise(async (resolve, reject) => {
try {
// Check if the destination path already exists
const destExists = await fs.promises
.access(target)
.then(() => true)
.catch(() => false);

// If the destination path exists, delete it
if (destExists) {
await fs.promises.rm(target, { recursive: true });
return new Promise((resolve, reject) => {
// Check if the destination path already exists
fs.access(target, fs.constants.F_OK, err => {
if (!err) {
// If the destination path exists, delete it
fs.rm(target, { recursive: true }, err => {
if (err) {
reject(err);
} else {
// Create the symbolic link
fs.symlink(source, target, 'junction', err => {
if (err) {
reject(err);
} else {
resolve();
}
});
}
});
} else {
// Create the symbolic link
fs.symlink(source, target, 'junction', err => {
if (err) {
reject(err);
} else {
resolve();
}
});
}

// Create the symbolic link
fs.symlink(source, target, 'dir', error => {
if (error) {
reject(error);
} else {
resolve();
}
});
} catch (error) {
reject(error);
}
});
});
}

Expand Down

0 comments on commit 98b4517

Please sign in to comment.