From 023f870c210f7f59a322582c719b21e2ec357d44 Mon Sep 17 00:00:00 2001 From: Anton Backer Date: Tue, 2 Dec 2014 00:15:40 -0500 Subject: [PATCH] Add support for UNC paths Wildcards that now work: \\host\directory\* Wildcards that still don't work: \\host\* Fixes #74 and #123 --- common.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/common.js b/common.js index 610d1245..b8f69eae 100644 --- a/common.js +++ b/common.js @@ -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) { @@ -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")