From e2befaea0a46f630de4d06c2363218af03152ca7 Mon Sep 17 00:00:00 2001 From: Aubrey Portwood Date: Wed, 31 Mar 2021 18:03:17 -0600 Subject: [PATCH] Wrap unlink in try so it doesn't throw error. So here we always try and unlink it when you click the button. This is because fs.exists checks are going to fail on the symlink because upon restart of Local the site ID's might be changed and/or the symlink may actually link to so file that isn't there giving us a false positive.... This just always unlinks it, and if the file isn't there (e.g. a link isn't already there or the file links to something that fails exists checks) then it will fail but the try{} will catch the error and if the file does exist and can be unlinked, it will unlink it. --- src/TablePlus.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/TablePlus.js b/src/TablePlus.js index 2770a08..7824b1e 100644 --- a/src/TablePlus.js +++ b/src/TablePlus.js @@ -151,7 +151,8 @@ export default class TablePlus extends React.Component { */ setupTmpSockFileForSite () { if (!this.tmpSockFileExists()) { - return this.symlinkTmpSockFile(); + return this.unlinkTmpSockFile() + && this.symlinkTmpSockFile(); } if (this.tmpSockFileIsSymlinked()) { @@ -170,7 +171,11 @@ export default class TablePlus extends React.Component { * @return {bool} True if the file got deleted. */ unlinkTmpSockFile () { - fs.unlinkSync(this.getTmpSockFile(), this.doNothing); + try { + fs.unlinkSync(this.getTmpSockFile(), this.doNothing); + } catch (error) { + this.doNothing(); + } const tmpExists = this.tmpSockFileExists();