From 2e72fab3afa315890042b1dcaaed91ec0d50f453 Mon Sep 17 00:00:00 2001 From: Alex Thomae Date: Fri, 23 Mar 2018 07:00:35 +0100 Subject: [PATCH 1/2] Add `fs.realpathSync` to resolve folder real path Closes subesokun/atom-tree-view-git-status#49 --- lib/utils.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/utils.coffee b/lib/utils.coffee index 18ab91e..ef35fdd 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -1,3 +1,4 @@ +fs = require 'fs' path = require 'path' normalizePath = (repoPath) -> @@ -9,9 +10,9 @@ normalizePath = (repoPath) -> # For now just strip away the /private part. # Using the fs.realPath function to avoid this issue isn't such a good # idea because it tries to access that path and in case it's not - # existing path an error gets thrown + it's slow due to fs access. + # existing path an error gets thrown normPath = normPath.replace(/^\/private/, '') - return normPath.replace(/[\\\/]$/, '') + return fs.realpathSync(normPath.replace(/[\\\/]$/, '')) getRootDirectoryStatus = (repo) -> promise = Promise.resolve() From 35f25c922aee6e1736ae286e4851bdbcaddb5778 Mon Sep 17 00:00:00 2001 From: subesokun Date: Sun, 8 Apr 2018 11:48:29 +0200 Subject: [PATCH 2/2] Gracefully handle realpath errors --- lib/utils.coffee | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/utils.coffee b/lib/utils.coffee index ef35fdd..d9806fd 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -2,17 +2,20 @@ fs = require 'fs' path = require 'path' normalizePath = (repoPath) -> - normPath = path.normalize repoPath + normPath = (path.normalize repoPath).replace(/[\\\/]$/, '') if process.platform is 'darwin' # For some reason the paths returned by the tree-view and # git-utils are sometimes "different" on Darwin platforms. # E.g. /private/var/... (real path) !== /var/... (symlink) # For now just strip away the /private part. - # Using the fs.realPath function to avoid this issue isn't such a good - # idea because it tries to access that path and in case it's not - # existing path an error gets thrown normPath = normPath.replace(/^\/private/, '') - return fs.realpathSync(normPath.replace(/[\\\/]$/, '')) + try + # Finally try to resolve the real path to avoid issues with symlinks. + return fs.realpathSync(normPath) + catch e + # If the path doesn't exists `realpath` throws an error. + # In that case just return the normalized path. + return normPath getRootDirectoryStatus = (repo) -> promise = Promise.resolve()