Skip to content

Commit

Permalink
Release v2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeboer committed Jul 12, 2019
2 parents 89fe78b + 2010e3b commit 51c9e71
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alfred-hugo",
"version": "2.0.2",
"version": "2.0.3",
"description": "Alfred workflow bindings for NodeJS",
"author": "Maarten de Boer <maarten@cloudstek.nl> (https://cloudstek.nl)",
"contributors": [
Expand Down
30 changes: 27 additions & 3 deletions src/bin/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,33 @@ for (const app of apps) {
const src = path.dirname(pkgPath);
const dest = path.join(workflowsDir, pkg.name.replace("/", "-"));

del(dest, { force: true }).then(() => {
fs.ensureSymlink(src, dest);
});
if (fs.pathExistsSync(dest)) {
const destStat = fs.lstatSync(dest);

// Skip link creation if destination is a directory, not a symlink
if (destStat.isDirectory()) {
console.debug("Destination is a directory, skipping.");
return;
}

// Skip if destination exists but is not a directory or symlink
if (destStat.isSymbolicLink() === false) {
console.debug("Desination exists but is neither a directory or symlink, skipping.");
return;
}

// Skip link creation if already linked
if (fs.realpathSync(dest) === src) {
console.debug("Link already exists, skipping.");
return;
}

// Remove existing symlink
del.sync(dest, { force: true });
}

// Create symlink
fs.ensureSymlink(src, dest);
})
.catch((err) => {
console.error(err);
Expand Down
15 changes: 14 additions & 1 deletion src/bin/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ for (const app of apps) {
.then(({ package: pkg }) => {
const dest = path.join(workflowsDir, pkg.name.replace("/", "-"));

del(dest, { force: true });
// Skip if destination does not exist
if (fs.pathExistsSync(dest) === false) {
return;
}

const destStat = fs.lstatSync(dest);

// Skip if destination is not a symbolic link
if (destStat.isSymbolicLink() === false) {
console.debug("Destination is not a symbolic link, skipping.");
return;
}

del.sync(dest, { force: true });
});
} catch (err) {
continue;
Expand Down

0 comments on commit 51c9e71

Please sign in to comment.