Repository: cordova-lib
Updated Branches:
  refs/heads/master 3b2a1fc43 -> f794fe8c3


CB-11771 Deep symlink directories to target project instead of linking the 
directory itself

When installing a plugin with custom library using the --link option the whole 
directory is symlinked and temporary
files leak into the original plugin directory on build. This leads to broken 
builds if the same plugin is linked in
2 projects targeting different Cordova versions.

 This closes #485


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

Branch: refs/heads/master
Commit: f794fe8c384fc4764c0f95e88bd18a107974f0e9
Parents: 3b2a1fc
Author: Martin Bektchiev <martin.bektch...@telerik.com>
Authored: Fri Aug 26 15:08:16 2016 +0300
Committer: Steve Gill <stevengil...@gmail.com>
Committed: Thu Oct 13 18:54:42 2016 -0700

----------------------------------------------------------------------
 .../spec-plugman/platforms/common.spec.js       | 20 ++++++++++++++++++++
 cordova-lib/src/plugman/platforms/common.js     | 17 ++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/f794fe8c/cordova-lib/spec-plugman/platforms/common.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/platforms/common.spec.js 
b/cordova-lib/spec-plugman/platforms/common.spec.js
index f591193..216c597 100644
--- a/cordova-lib/spec-plugman/platforms/common.spec.js
+++ b/cordova-lib/spec-plugman/platforms/common.spec.js
@@ -30,6 +30,8 @@ var common = require('../../src/plugman/platforms/common')
   , java_dir = path.join(src, 'one', 'two', 'three')
   , java_file = path.join(java_dir, 'test.java')
   , symlink_file = path.join(java_dir, 'symlink')
+  , symlink_dir = path.join(java_dir, 'symlink_dir')
+  , symlink_dir_relative_file = path.join('one', 'two', 'file')
   , non_plugin_file = path.join(osenv.tmpdir(), 'non_plugin_file');
 
 describe('common platform handler', function() {
@@ -82,6 +84,24 @@ describe('common platform handler', function() {
             shell.rm('-rf', project_dir);
         });
 
+        it('should deeply symlink directory tree when src is a directory', 
function(){
+            var symlink_dir_relative_subdir = 
path.dirname(symlink_dir_relative_file);
+
+            shell.mkdir('-p', path.join(symlink_dir, 
symlink_dir_relative_subdir));
+            fs.writeFileSync(path.join(symlink_dir, 
symlink_dir_relative_file), 'contents', 'utf-8');
+
+            // This will fail on windows if not admin - ignore the error in 
that case.
+            if (ignoreEPERMonWin32(java_file, symlink_file)) {
+                return;
+            }
+
+            var create_symlink = true;
+            common.copyFile(test_dir, symlink_dir, project_dir, dest, 
create_symlink);
+
+            expect(path.resolve(dest, symlink_dir_relative_subdir, 
fs.readlinkSync(path.join(dest, 
symlink_dir_relative_file)))).toBe(path.resolve(symlink_dir, 
symlink_dir_relative_file));
+            shell.rm('-rf', project_dir);
+        });
+
         it('should throw if symlink is linked to a file outside the plugin', 
function(){
             shell.mkdir('-p', java_dir);
             fs.writeFileSync(non_plugin_file, 'contents', 'utf-8');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/f794fe8c/cordova-lib/src/plugman/platforms/common.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/platforms/common.js 
b/cordova-lib/src/plugman/platforms/common.js
index cb5075d..29d5df6 100644
--- a/cordova-lib/src/plugman/platforms/common.js
+++ b/cordova-lib/src/plugman/platforms/common.js
@@ -84,7 +84,7 @@ module.exports = common = {
         shell.mkdir('-p', path.dirname(dest));
 
         if (link) {
-            fs.symlinkSync(path.relative(path.dirname(dest), src), dest);
+            common.symlinkFileOrDirTree(src, dest);
         } else if (fs.statSync(src).isDirectory()) {
             // XXX shelljs decides to create a directory when -R|-r is used 
which sucks. http://goo.gl/nbsjq
             shell.cp('-Rf', src+'/*', dest);
@@ -100,6 +100,21 @@ module.exports = common = {
 
         common.copyFile(plugin_dir, src, project_dir, dest, !!link);
     },
+    symlinkFileOrDirTree:function symlinkFileOrDirTree(src, dest) {
+            if (fs.existsSync(dest)) {
+                shell.rm('-Rf', dest);
+            }
+            
+            if (fs.statSync(src).isDirectory()) {
+                shell.mkdir('-p', dest);
+                fs.readdirSync(src).forEach(function(entry) {
+                    symlinkFileOrDirTree(path.join(src, entry), 
path.join(dest, entry));
+                });
+            }
+            else {
+                
fs.symlinkSync(path.relative(fs.realpathSync(path.dirname(dest)), src), dest);
+            }
+    },
     // checks if file exists and then deletes. Error if doesn't exist
     removeFile:function(project_dir, src) {
         var file = module.exports.resolveSrcPath(project_dir, src);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to