70 lines
2.2 KiB
Diff
70 lines
2.2 KiB
Diff
diff -urN node-v0.10.29/lib/path.js node-v0.10.29-MSYS2-path-conversion/lib/path.js
|
|
--- node-v0.10.29/lib/path.js 2014-07-26 12:11:05.299704400 +0100
|
|
+++ node-v0.10.29-MSYS2-path-conversion/lib/path.js 2014-07-26 12:10:55.526463300 +0100
|
|
@@ -466,6 +466,8 @@
|
|
return '';
|
|
}
|
|
|
|
+ if (path.indexOf('/') == 0) path = mingwToWindowsPath(path);
|
|
+
|
|
var resolvedPath = exports.resolve(path);
|
|
|
|
if (/^[a-zA-Z]\:\\/.test(resolvedPath)) {
|
|
@@ -485,3 +487,56 @@
|
|
return path;
|
|
};
|
|
}
|
|
+
|
|
+var mingwMounts = [], mingwGotMounts = false;
|
|
+function mingwGetMounts() {
|
|
+ if (mingwGotMounts) return mingwMounts;
|
|
+ var spawn = require('child_process').spawn;
|
|
+ var fs = require('fs');
|
|
+ var os = require('os');
|
|
+ var tmp = os.tmpdir() + '/node-mount.tmp';
|
|
+ var fd = fs.openSync(tmp, 'w+');
|
|
+ var mount = spawn('sh', ['-c', 'mount; echo "EOF"'], {
|
|
+ 'stdio': ['ignore', fd, 'ignore']
|
|
+ });
|
|
+ var eof = os.EOL + 'EOF' + os.EOL;
|
|
+ var buflen = 4096;
|
|
+ var buf = new Buffer (buflen);
|
|
+ do {
|
|
+ var bytes = fs.readSync(fd, buf, 0, buflen, 0);
|
|
+ if (bytes >= buflen) {
|
|
+ console.error('mount overran the buffer');
|
|
+ mingwGotMounts = true;
|
|
+ return mingwMounts;
|
|
+ }
|
|
+ } while (buf.slice(bytes - eof.length, bytes).toString() != eof);
|
|
+ fs.closeSync(fd);
|
|
+ var lines = buf.slice(0, bytes).toString().split(os.EOL);
|
|
+ var splitLineRe = /^(.+) on (.+) type /;
|
|
+ for (var i = 0; i < lines.length; i++) {
|
|
+ var match = splitLineRe.exec(lines[i]);
|
|
+ if (! match) continue;
|
|
+ mingwMounts.push([match[1], match[2]]);
|
|
+ }
|
|
+ mingwMounts.sort(function(a, b) {
|
|
+ var cmp = b[1].length - a[1].length;
|
|
+ if (cmp) return cmp;
|
|
+ else return a[1] > b[1];
|
|
+ });
|
|
+ mingwGotMounts = true;
|
|
+ return mingwMounts;
|
|
+}
|
|
+function mingwToWindowsPath(path) {
|
|
+ var mounts = mingwGetMounts();
|
|
+ for (var i = 0; i < mounts.length; i++) {
|
|
+ var to = mounts[i][0], from = mounts[i][1];
|
|
+ from = from.replace(/\/$/, '');
|
|
+ var re = new RegExp('^' + from + '(.*)$');
|
|
+ var match = re.exec(path);
|
|
+ if (match && (match[1].length == 0 || match[1][0] == '/')) {
|
|
+ return to + match[1];
|
|
+ }
|
|
+ }
|
|
+ console.error(path + ' not found in mount');
|
|
+ return path;
|
|
+}
|