Skip to content

Commit

Permalink
feat: delete broken symlinks if need to stow
Browse files Browse the repository at this point in the history
  • Loading branch information
NihadBadalov committed May 4, 2024
1 parent b5a90f3 commit 52c5048
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/commands/stow.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ export default async function stow(cwd, force, recursive) {
}
}

if (fs.existsSync(stowPath)) {
let isBrokenSymlink = false;
try {
isBrokenSymlink = !!fs.lstatSync(stowPath).isSymbolicLink();
} catch (e) {
isBrokenSymlink = false;
}
if (fs.existsSync(stowPath) || isBrokenSymlink) {
if (fs.lstatSync(stowPath).isSymbolicLink()) {
if (force) {
fs.unlinkSync(stowPath);
} else {
console.error(`Failed to stow ${dotfileFilePath}: file already exists at stow location`);
continue;
console.error(`Failed to stow ${dotfileFilePath}: file already exists at stow location`);
continue;
}
}
else if (fs.lstatSync(stowPath).isDirectory()) {
Expand All @@ -69,7 +75,7 @@ export default async function stow(cwd, force, recursive) {
if (force) {
fs.unlinkSync(stowPath);
} else {
console.error(`Failed to stow ${dotfileFilePath}: file already exists at stow location`);
console.error(`Failed to stow ${dotfileFilePath}: file already exists at stow location`);
}
}
}
Expand Down

0 comments on commit 52c5048

Please sign in to comment.