Fix link/copy parent check for windows

Reported as cca issue #260
https://github.com/MobileChromeApps/mobile-chrome-apps/issues/260


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/35202bc6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/35202bc6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/35202bc6

Branch: refs/heads/master
Commit: 35202bc654c3b73e7780ec9d5f49aded0586a35d
Parents: b10be02
Author: Mark Koudritsky <kam...@gmail.com>
Authored: Tue Aug 12 16:53:16 2014 -0400
Committer: Anis Kadri <a...@apache.org>
Committed: Fri Sep 5 11:12:18 2014 -0700

----------------------------------------------------------------------
 cordova-lib/src/cordova/create.js | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/35202bc6/cordova-lib/src/cordova/create.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/create.js 
b/cordova-lib/src/cordova/create.js
index 7aef292..c8cb694 100644
--- a/cordova-lib/src/cordova/create.js
+++ b/cordova-lib/src/cordova/create.js
@@ -105,11 +105,15 @@ function create(dir, id, name, cfg) {
         config_json.lib.www.id = config_json.lib.www.id || 'dummy_id';
         symlink  = !!config_json.lib.www.link;
 
-        // Make sure that the source www/ is not a direct ancestor of the 
target www/, or else we will recursively copy forever.
-        // To do this, we make sure that the shortest relative path from 
source-to-target must start by going up at least one directory.
-        var relative_path_from_source_to_target = 
path.relative(config_json.lib.www.url, www_dir);
-        var does_relative_path_go_up_at_least_one_dir = 
relative_path_from_source_to_target.split(path.sep)[0] == '..';
-        if (!does_relative_path_go_up_at_least_one_dir) {
+        // Make sure that the source www/ is not a direct ancestor of the
+        // target www/, or else we will recursively copy forever. To do this,
+        // we make sure that the shortest relative path from source-to-target
+        // must start by going up at least one directory or with a drive
+        // letter for Windows.
+        var rel_path = path.relative(config_json.lib.www.url, www_dir);
+        var goes_up = rel_path.split(path.sep)[0] == '..';
+
+        if (!(goes_up || rel_path[1] == ':')) {
             throw new CordovaError(
                 'Project dir "' +
                 dir +

Reply via email to