Skip to content

Commit

Permalink
Add support for UNC paths
Browse files Browse the repository at this point in the history
Wildcards that now work: \\host\directory\*

Wildcards that still don't work: \\host\*

Fixes isaacs#74 and isaacs#123
  • Loading branch information
staticshock committed Dec 2, 2014
1 parent bc64587 commit 023f870
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@ var path = require("path")
var minimatch = require("minimatch")
var Minimatch = minimatch.Minimatch

function absWin (p) {
if (absUnix(p)) return true
function WinPath (p) {
if (!(this instanceof WinPath))
return new WinPath(p)

// pull off the device/UNC bit from a windows path.
// from node's lib/path.js
var splitDeviceRe =
/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/
var result = splitDeviceRe.exec(p)
var device = result[1] || ''
var isUnc = device && device.charAt(1) !== ':'
var isAbsolute = !!result[2] || isUnc // UNC paths are always absolute
this.device = result[1] || ''
this.sep = result[2] || ''
this.tail = result[3] || ''
this.isUnc = !!this.device && this.device.charAt(1) !== ':'
this.isAbsolute = !!this.sep || this.isUnc // UNC paths are always absolute
}

function absWin (p) {
if (absUnix(p)) return true

return isAbsolute
var winPath = new WinPath(p)
return winPath.isAbsolute
}

function absUnix (p) {
Expand Down Expand Up @@ -83,6 +92,14 @@ function setopts (self, pattern, options) {
self.changedCwd = path.resolve(options.cwd) !== cwd
}

if (process.platform === "win32") {
var winPath = new WinPath(pattern)
if (winPath.isAbsolute) {
options.root = winPath.device
pattern = winPath.sep + winPath.tail
}
}

self.root = options.root || path.resolve(self.cwd, "/")
self.root = path.resolve(self.root)
if (process.platform === "win32")
Expand Down

0 comments on commit 023f870

Please sign in to comment.