Skip to content

Commit

Permalink
Wrap unlink in try so it doesn't throw error.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aubreypwd committed Apr 1, 2021
1 parent d4d5c93 commit e2befae
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/TablePlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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();

Expand Down

0 comments on commit e2befae

Please sign in to comment.