Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
Gracefully handle realpath errors
Browse files Browse the repository at this point in the history
  • Loading branch information
subesokun committed Apr 8, 2018
1 parent 2e72fab commit 35f25c9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 35f25c9

Please sign in to comment.