Skip to content

Commit 6c925cf

Browse files
authored
fix(plugins): Handle uninstalling multiple plugin assets (apache#1540)
Try to safely clean up empty directories when uninstalling plugin assets without always forcibly removing the plugin directory itself. This should provide better handling for cases where plugins have multiple assets that get added to the plugin folder. Closes apacheGH-1530.
1 parent 2e5d626 commit 6c925cf

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

lib/plugman/pluginHandlers.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,9 @@ const handlers = {
205205
throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
206206
}
207207

208-
removeFile(project.www, target);
209-
removeFileF(path.resolve(project.www, 'plugins', plugin.id));
208+
removeFileAndParents(project.www, target);
210209
if (options && options.usePlatformWww) {
211-
removeFile(project.platformWww, target);
212-
removeFileF(path.resolve(project.platformWww, 'plugins', plugin.id));
210+
removeFileAndParents(project.platformWww, target);
213211
}
214212
}
215213
},
@@ -376,12 +374,6 @@ function linkFileOrDirTree (src, dest) {
376374
}
377375
}
378376

379-
// checks if file exists and then deletes. Error if doesn't exist
380-
function removeFile (project_dir, src) {
381-
const file = path.resolve(project_dir, src);
382-
fs.rmSync(file);
383-
}
384-
385377
// deletes file/directory without checking
386378
function removeFileF (file) {
387379
fs.rmSync(file, { recursive: true, force: true });

tests/spec/unit/Plugman/pluginHandler.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ describe('ios plugin handler', () => {
586586
it('Test 043 : should put module to www only when options.usePlatformWww flag is not specified', () => {
587587
uninstall(jsModule, dummyPluginInfo, dummyProject);
588588
expect(fs.rmSync).toHaveBeenCalledWith(wwwDest, { recursive: true, force: true });
589-
expect(fs.rmSync).not.toHaveBeenCalledWith(platformWwwDest);
589+
expect(fs.rmSync).not.toHaveBeenCalledWith(platformWwwDest, { recursive: true, force: true });
590590
});
591591
});
592592

@@ -611,14 +611,14 @@ describe('ios plugin handler', () => {
611611

612612
it('Test 044 : should put module to both www and platform_www when options.usePlatformWww flag is specified', () => {
613613
uninstall(asset, dummyPluginInfo, dummyProject, { usePlatformWww: true });
614-
expect(fs.rmSync).toHaveBeenCalledWith(wwwDest);
615-
expect(fs.rmSync).toHaveBeenCalledWith(platformWwwDest);
614+
expect(fs.rmSync).toHaveBeenCalledWith(wwwDest, { recursive: true, force: true });
615+
expect(fs.rmSync).toHaveBeenCalledWith(platformWwwDest, { recursive: true, force: true });
616616
});
617617

618618
it('Test 045 : should put module to www only when options.usePlatformWww flag is not specified', () => {
619619
uninstall(asset, dummyPluginInfo, dummyProject);
620-
expect(fs.rmSync).toHaveBeenCalledWith(wwwDest);
621-
expect(fs.rmSync).not.toHaveBeenCalledWith(platformWwwDest);
620+
expect(fs.rmSync).toHaveBeenCalledWith(wwwDest, { recursive: true, force: true });
621+
expect(fs.rmSync).not.toHaveBeenCalledWith(platformWwwDest, { recursive: true, force: true });
622622
});
623623
});
624624
});

0 commit comments

Comments
 (0)