Skip to content

Commit

Permalink
Fix regression in resolving real paths. [closes #588]
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Sep 2, 2018
1 parent 3b16b1e commit d0a7299
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
17 changes: 2 additions & 15 deletions src/fs/stat-fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { Stats } from "../safe/fs.js"

import binding from "../binding.js"
import call from "../util/call.js"
import realpath from "./realpath.js"
import shared from "../shared.js"
import statSync from "./stat-sync.js"
import toNamespacedPath from "../path/to-namespaced-path.js"

function init() {
const { isFile, isSymbolicLink } = Stats.prototype
const { isFile } = Stats.prototype

let useFastPath

Expand Down Expand Up @@ -53,19 +52,7 @@ function init() {
const stat = statSync(thePath)

if (stat) {
if (call(isFile, stat)) {
return 0
}

if (! call(isSymbolicLink, stat)) {
return 1
}

thePath = realpath(thePath)

if (thePath) {
return call(isFile, statSync(thePath)) ? 0 : 1
}
return call(isFile, stat) ? 0 : 1
}

return -1
Expand Down
4 changes: 2 additions & 2 deletions src/fs/stat-sync.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lstatSync, Stats } from "../safe/fs.js"
import { statSync as _statSync, Stats } from "../safe/fs.js"

import setPrototypeOf from "../util/set-prototype-of.js"
import shared from "../shared.js"
Expand All @@ -17,7 +17,7 @@ function init() {
let result = null

try {
result = lstatSync(thePath)
result = _statSync(thePath)

// Electron and Muon return a plain object for asar files.
// https://github.com/electron/electron/blob/master/lib/common/asar.js
Expand Down
26 changes: 4 additions & 22 deletions src/module/internal/find-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const {
FLAGS
} = ENV

const { isFile, isSymbolicLink } = Stats.prototype
const { isFile } = Stats.prototype
const { preserveSymlinks, preserveSymlinksMain } = FLAGS

const mainFields = ["main"]
Expand Down Expand Up @@ -118,7 +118,6 @@ function findPath(request, paths, isMain, fields, exts) {
thePath = resolve(curPath, request)
}

let isSymLink = false
let rc = -1
let stat = null

Expand All @@ -128,12 +127,6 @@ function findPath(request, paths, isMain, fields, exts) {

if (stat) {
rc = call(isFile, stat) ? 0 : 1

if (rc &&
call(isSymbolicLink, stat)) {
isSymLink = true
rc = statFast(thePath)
}
}
} else {
rc = statFast(thePath)
Expand All @@ -144,14 +137,9 @@ function findPath(request, paths, isMain, fields, exts) {
if (! trailingSlash) {
// If a file.
if (rc === 0) {
if (useRealpath &&
(! stat ||
stat.nlink > 1 ||
isSymLink)) {
filename = realpath(thePath)
} else {
filename = thePath
}
filename = useRealpath
? realpath(thePath)
: thePath
}

if (! filename) {
Expand Down Expand Up @@ -226,12 +214,6 @@ function tryFilename(filename, isMain) {

if (stat) {
rc = call(isFile, stat) ? 0 : 1

if (rc &&
call(isSymbolicLink, stat)) {
isSymLink = true
rc = statFast(filename)
}
}
} else {
rc = statFast(filename)
Expand Down
2 changes: 1 addition & 1 deletion src/safe/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const {
realpathSync,
realpathNativeSync,
Stats,
lstatSync,
statSync,
unlinkSync,
writeFileSync
} = safeFs
Expand Down

0 comments on commit d0a7299

Please sign in to comment.