From 7a2533a3a41c3d7a103172bf0d5f2330a4d3c4c6 Mon Sep 17 00:00:00 2001 From: Aubrey Portwood Date: Fri, 26 Feb 2021 13:00:06 -0700 Subject: [PATCH] Unlink the file THEN symlink. Closes https://github.com/aubreypwd/local-tableplus/issues/9 The issue is that /tmp/mysql.lock isn't being unlink'd fast enough by the system before the symlinking process begins. I should have done this to begin with, but we don't symlink now UNTIL after the unlink process finishes. Essentially a race-condition. --- src/TablePlus.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/TablePlus.js b/src/TablePlus.js index ae363f5..1a210a0 100644 --- a/src/TablePlus.js +++ b/src/TablePlus.js @@ -138,6 +138,17 @@ export default class TablePlus extends React.Component { exec(`open "${this.getTablePlusURI()}"`, () => this.doNothing()); } + /** + * Reset /tmp/mysql.lock then symlink the socket file. + * + * @author Aubrey Portwood + * @since 1.0.2 + * @return {void} + */ + unlinkAndThenSymlinkTmpSockFile () { + fs.unlink('/tmp/mysql.sock', () => this.symlinkTmpSockFile()); + } + /** * Symlink the /tmp/mysql.sock file to the site sock file. * @@ -145,8 +156,7 @@ export default class TablePlus extends React.Component { * @since 1.0.0 * @return {void} */ - symlinkSockFile () { - fs.unlink('/tmp/mysql.sock', () => this.doNothing()); + symlinkTmpSockFile () { fs.symlinkSync(this.getSockFile(), '/tmp/mysql.sock', 'file', this.doNothing); } @@ -161,7 +171,7 @@ export default class TablePlus extends React.Component { * @return {void} */ openTablePlus () { - this.symlinkSockFile(); + this.unlinkAndThenSymlinkTmpSockFile(); this.openURI(); }