From ec85fabf660e69462ff00e67321d71dda7963b00 Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Thu, 11 Dec 2014 15:33:28 -0800 Subject: [PATCH] Sometimes we construct paths w/o them being absolute. For example: files.pathJoin('/something/', '/something/else') should result into '/something/something/else' and here the caller doesn't care if the passed arguments look like absolute paths or not. It can even be a middle part of some larger path. We don't care and shouldn't enforce it on files.pathJoin --- tools/files.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/files.js b/tools/files.js index 5308f32ebc..2035ac769e 100644 --- a/tools/files.js +++ b/tools/files.js @@ -1025,9 +1025,9 @@ files.linkToMeteorScript = function (scriptLocation, linkLocation) { /////// Below here, functions have been corrected for slashes -var toPosixPath = function (p) { +var toPosixPath = function (p, notAbsolute) { p = p.replace(/\\/g, '/'); - if (p[1] === ':') { + if (p[1] === ':' && ! notAbsolute) { // transform "C:/bla/bla" to "/C/bla/bla" p = '/' + p[0] + p.slice(2); } @@ -1035,8 +1035,8 @@ var toPosixPath = function (p) { return p; }; -var toDosPath = function (p) { - if (p[0] === '/') { +var toDosPath = function (p, notAbsolute) { + if (p[0] === '/' && ! notAbsolute) { if (! /^\/[A-Z]\//.test(p)) throw new Error("Surprising path: " + p); // transform a previously windows path back @@ -1049,17 +1049,17 @@ var toDosPath = function (p) { }; -var convertToOSPath = function (standardPath) { +var convertToOSPath = function (standardPath, notAbsolute) { if (process.platform === "win32") { - return toDosPath(standardPath); + return toDosPath(standardPath, notAbsolute); } return standardPath; }; -var convertToStandardPath = function (osPath) { +var convertToStandardPath = function (osPath, notAbsolute) { if (process.platform === "win32") { - return toPosixPath(osPath); + return toPosixPath(osPath, notAbsolute); } return osPath; @@ -1249,11 +1249,15 @@ files.unwatchFile = function () { // forward slashes) var wrapPathFunction = function (name) { var f = path[name]; - return function (/* args */) { if (process.platform === 'win32') { var args = _.toArray(arguments); - return toPosixPath(f.apply(path, _.map(args, toDosPath))); + args = _.map(args, function (p, i) { + // if partialPaths is turned on (for path.join mostly) + // forget about conversion of absolute paths for Windows + return toDosPath(p, partialPaths); + }); + return toPosixPath(f.apply(path, args), partialPaths); } else { return f.apply(path, arguments); }