[ 
https://issues.apache.org/jira/browse/CB-14033?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16541448#comment-16541448
 ] 

ASF GitHub Bot commented on CB-14033:
-------------------------------------

raphinesse closed pull request #621: CB-14033 Support symbolic dir links on 
Windows
URL: https://github.com/apache/cordova-lib/pull/621
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/integration-tests/plugman_fetch.spec.js 
b/integration-tests/plugman_fetch.spec.js
index 4895bee07..e01010131 100644
--- a/integration-tests/plugman_fetch.spec.js
+++ b/integration-tests/plugman_fetch.spec.js
@@ -94,7 +94,7 @@ describe('fetch', function () {
         });
         it('Test 003 : should create a symlink if used with `link` param', 
function () {
             return fetch(test_plugin, temp, { link: true }).then(function () {
-                expect(sym).toHaveBeenCalledWith(test_plugin, path.join(temp, 
test_plugin_id), 'dir');
+                expect(sym).toHaveBeenCalledWith(test_plugin, path.join(temp, 
test_plugin_id), 'junction');
             });
         });
 
@@ -152,23 +152,13 @@ describe('fetch', function () {
             return Q(pluginDir);
         });
 
-        if (/^win/.test(process.platform)) {
-            it('Test 020 : should copy all but the /demo/ folder', function () 
{
-                var cp = spyOn(shell, 'cp');
-                return fetch(srcDir, appDir).then(function () {
-                    expect(cp).toHaveBeenCalledWith('-R', path.join(srcDir, 
'asset.txt'), path.join(appDir, 'test-recursive'));
-                    expect(cp).not.toHaveBeenCalledWith('-R', srcDir, 
path.join(appDir, 'test-recursive'));
-                });
-            });
-        } else {
-            it('Test 021 : should skip copy to avoid recursive error', 
function () {
+        it('Test 021 : should skip copy to avoid recursive error', function () 
{
 
-                var cp = spyOn(shell, 'cp').and.callFake(function () {});
+            var cp = spyOn(shell, 'cp').and.callFake(function () {});
 
-                return fetch(srcDir, appDir).then(function () {
-                    expect(cp).not.toHaveBeenCalled();
-                });
+            return fetch(srcDir, appDir).then(function () {
+                expect(cp).not.toHaveBeenCalled();
             });
-        }
+        });
     });
 });
diff --git a/src/plugman/fetch.js b/src/plugman/fetch.js
index 221e21ccb..7fe69209e 100644
--- a/src/plugman/fetch.js
+++ b/src/plugman/fetch.js
@@ -279,39 +279,15 @@ function copyPlugin (pinfo, plugins_dir, link) {
     shell.rm('-rf', dest);
 
     if (!link && dest.indexOf(path.resolve(plugin_dir) + path.sep) === 0) {
-
-        if (/^win/.test(process.platform)) {
-            /*
-                [CB-10423]
-                This is a special case. On windows we cannot create a symlink 
unless we are run as admin
-                The error that we have is because src contains dest, so we end 
up with a recursive folder explosion
-                This code avoids copy the one folder that will explode, and 
allows plugins to contain a demo project
-                and to install the plugin via `cordova plugin add ../`
-            */
-            var resolvedSrcPath = path.resolve(plugin_dir);
-            var filenames = fs.readdirSync(resolvedSrcPath);
-            var relPath = path.relative(resolvedSrcPath, dest);
-            var relativeRootFolder = relPath.split('\\')[0];
-            filenames.splice(filenames.indexOf(relativeRootFolder), 1);
-            shell.mkdir('-p', dest);
-            events.emit('verbose', 'Copying plugin "' + resolvedSrcPath + '" 
=> "' + dest + '"');
-            events.emit('verbose', 'Skipping folder "' + relativeRootFolder + 
'"');
-
-            filenames.forEach(function (elem) {
-                shell.cp('-R', path.join(resolvedSrcPath, elem), dest);
-            });
-            return dest;
-        } else {
-            events.emit('verbose', 'Copy plugin destination is child of src. 
Forcing --link mode.');
-            link = true;
-        }
+        events.emit('verbose', 'Copy plugin destination is child of src. 
Forcing --link mode.');
+        link = true;
     }
 
     if (link) {
         var isRelativePath = plugin_dir.charAt(1) !== ':' && 
plugin_dir.charAt(0) !== path.sep;
         var fixedPath = isRelativePath ? path.join(path.relative(plugins_dir, 
process.env.PWD || process.cwd()), plugin_dir) : plugin_dir;
         events.emit('verbose', 'Linking "' + dest + '" => "' + fixedPath + 
'"');
-        fs.symlinkSync(fixedPath, dest, 'dir');
+        fs.symlinkSync(fixedPath, dest, 'junction');
     } else {
         shell.mkdir('-p', dest);
         events.emit('verbose', 'Copying plugin "' + plugin_dir + '" => "' + 
dest + '"');
diff --git a/src/plugman/install.js b/src/plugman/install.js
index 51c6baf74..aec2be3a5 100644
--- a/src/plugman/install.js
+++ b/src/plugman/install.js
@@ -654,7 +654,7 @@ function copyPlugin (plugin_src_dir, plugins_dir, link, 
pluginInfoProvider) {
     if (link) {
         events.emit('verbose', 'Symlinking from location "' + plugin_src_dir + 
'" to location "' + dest + '"');
         shell.mkdir('-p', path.dirname(dest));
-        fs.symlinkSync(plugin_src_dir, dest, 'dir');
+        fs.symlinkSync(plugin_src_dir, dest, 'junction');
     } else {
         shell.mkdir('-p', dest);
         events.emit('verbose', 'Copying from location "' + plugin_src_dir + '" 
to location "' + dest + '"');


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> `cordova plugin add` skips directory on windows
> -----------------------------------------------
>
>                 Key: CB-14033
>                 URL: https://issues.apache.org/jira/browse/CB-14033
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-lib
>         Environment: Cordova 6.2.0
>            Reporter: Jack Lu
>            Assignee: Raphael
>            Priority: Major
>
> Suppose we have a cordova plugin project and a test project that are under 
> the same directory. The {color:#333333}cordova plugin project {color}is in 
> directory p, and the test project in directory t. When I run following 
> command in directory t:
>  
> {code:java}
> cordova plugin add ..\p
> {code}
> the install fails, and I found it's due to the src directory missing during 
> copying.
> After digging into the source, I found it's caused by a special handling in 
> the fetch action{color:#333333} on windows{color}. The source is 
> {color:#333333}[https://github.com/apache/cordova-lib/blob/master/src/plugman/fetch.js#L299]{color}.
> {code:java}
>             /*
>                 [CB-10423]
>                 This is a special case. On windows we cannot create a symlink 
> unless we are run as admin
>                 The error that we have is because src contains dest, so we 
> end up with a recursive folder explosion
>                 This code avoids copy the one folder that will explode, and 
> allows plugins to contain a demo project
>                 and to install the plugin via `cordova plugin add ../`
>             */
>             var resolvedSrcPath = path.resolve(plugin_dir);
>             var filenames = fs.readdirSync(resolvedSrcPath);
>             var relPath = path.relative(resolvedSrcPath,dest);
>             var relativeRootFolder = relPath.split('\\')[0];
>             filenames.splice(filenames.indexOf(relativeRootFolder),1);
> {code}
> in this case {color:#333333}relPath{color} will be "..\t\plugins\{{{{plugin 
> id}}}}", {color:#333333}relativeRootFolder{color} be "..", then 
> {color:#333333}filenames.indexOf(relativeRootFolder){color} be -1, finally 
> filenames lost the last element, which is the src directory in my case.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to