Skip to content

Commit

Permalink
Fix realpath function (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
remorses authored Dec 29, 2020
1 parent c9cba29 commit 2b208fc
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,6 @@ func AfterFileClose() {
<-fileOpenLimit
}

func realpath(path string) string {
dir := filepath.Dir(path)
if dir == path {
return path
}
dir = realpath(dir)
path = filepath.Join(dir, filepath.Base(path))
BeforeFileOpen()
defer AfterFileClose()
if link, err := os.Readlink(path); err == nil {
if filepath.IsAbs(link) {
return link
}
return filepath.Join(dir, link)
}
return path
}

func RealFS() FS {
cwd, err := os.Getwd()
if err != nil {
Expand All @@ -326,7 +308,15 @@ func RealFS() FS {
// so the current working directory should be processed the same way. Not
// doing this causes test failures with esbuild when run from inside a
// symlinked directory.
cwd = realpath(cwd)
//
// This deliberately ignores errors due to e.g. infinite loops. If there is
// an error, we will just use the original working directory and likely
// encounter an error later anyway. And if we don't encounter an error
// later, then the current working directory didn't even matter and the
// error is unimportant.
if path, err := filepath.EvalSymlinks(cwd); err == nil {
cwd = path
}
}
return &realFS{
entries: make(map[string]entriesOrErr),
Expand Down

0 comments on commit 2b208fc

Please sign in to comment.