From 7dfbc8ef3ea946220bbcee75dcec51e9e91103bb Mon Sep 17 00:00:00 2001 From: Maarten de Boer Date: Fri, 12 Jul 2019 16:10:06 +0200 Subject: [PATCH 1/2] Fix hugo-link and hugo-unlink --- src/bin/link.ts | 30 +++++++++++++++++++++++++++--- src/bin/unlink.ts | 15 ++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/bin/link.ts b/src/bin/link.ts index fed42b8..bbb3e71 100644 --- a/src/bin/link.ts +++ b/src/bin/link.ts @@ -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); diff --git a/src/bin/unlink.ts b/src/bin/unlink.ts index c953f51..e4678f5 100644 --- a/src/bin/unlink.ts +++ b/src/bin/unlink.ts @@ -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; From 2010e3b8632d4ae9f11bc3a4c83316736be82748 Mon Sep 17 00:00:00 2001 From: Maarten de Boer Date: Fri, 12 Jul 2019 16:10:16 +0200 Subject: [PATCH 2/2] Bump patch version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 824a54c..b950701 100644 --- a/package.json +++ b/package.json @@ -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 (https://cloudstek.nl)", "contributors": [