@@ -646,9 +646,11 @@ private void installMetaPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
646
646
Environment env , List <Path > deleteOnFailure ) throws Exception {
647
647
final MetaPluginInfo metaInfo = MetaPluginInfo .readFromProperties (tmpRoot );
648
648
verifyPluginName (env .pluginsFile (), metaInfo .getName (), tmpRoot );
649
+
649
650
final Path destination = env .pluginsFile ().resolve (metaInfo .getName ());
650
651
deleteOnFailure .add (destination );
651
652
terminal .println (VERBOSE , metaInfo .toString ());
653
+
652
654
final List <Path > pluginPaths = new ArrayList <>();
653
655
try (DirectoryStream <Path > paths = Files .newDirectoryStream (tmpRoot )) {
654
656
// Extract bundled plugins path and validate plugin names
@@ -665,19 +667,11 @@ private void installMetaPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
665
667
for (Path plugin : pluginPaths ) {
666
668
final PluginInfo info = verify (terminal , plugin , isBatch , env );
667
669
pluginInfos .add (info );
668
- Path tmpBinDir = plugin .resolve ("bin" );
669
- if (Files .exists (tmpBinDir )) {
670
- Path destBinDir = env .binFile ().resolve (metaInfo .getName ());
671
- deleteOnFailure .add (destBinDir );
672
- installBin (info , tmpBinDir , destBinDir );
673
- }
674
-
675
- Path tmpConfigDir = plugin .resolve ("config" );
676
- if (Files .exists (tmpConfigDir )) {
677
- // some files may already exist, and we don't remove plugin config files on plugin removal,
678
- // so any installed config files are left on failure too
679
- Path destConfigDir = env .configFile ().resolve (metaInfo .getName ());
680
- installConfig (info , tmpConfigDir , destConfigDir );
670
+ installPluginSupportFiles (info , plugin , env .binFile ().resolve (metaInfo .getName ()),
671
+ env .configFile ().resolve (metaInfo .getName ()), deleteOnFailure );
672
+ // ensure the plugin dir within the tmpRoot has the correct name
673
+ if (plugin .getFileName ().toString ().equals (info .getName ()) == false ) {
674
+ Files .move (plugin , plugin .getParent ().resolve (info .getName ()), StandardCopyOption .ATOMIC_MOVE );
681
675
}
682
676
}
683
677
movePlugin (tmpRoot , destination );
@@ -693,17 +687,28 @@ private void installMetaPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
693
687
694
688
/**
695
689
* Installs the plugin from {@code tmpRoot} into the plugins dir.
696
- * If the plugin has a bin dir and/or a config dir, those are copied .
690
+ * If the plugin has a bin dir and/or a config dir, those are moved .
697
691
*/
698
692
private void installPlugin (Terminal terminal , boolean isBatch , Path tmpRoot ,
699
693
Environment env , List <Path > deleteOnFailure ) throws Exception {
700
694
final PluginInfo info = verify (terminal , tmpRoot , isBatch , env );
701
695
final Path destination = env .pluginsFile ().resolve (info .getName ());
702
696
deleteOnFailure .add (destination );
703
697
698
+ installPluginSupportFiles (info , tmpRoot , env .binFile ().resolve (info .getName ()),
699
+ env .configFile ().resolve (info .getName ()), deleteOnFailure );
700
+ movePlugin (tmpRoot , destination );
701
+ if (info .requiresKeystore ()) {
702
+ createKeystoreIfNeeded (terminal , env , info );
703
+ }
704
+ terminal .println ("-> Installed " + info .getName ());
705
+ }
706
+
707
+ /** Moves bin and config directories from the plugin if they exist */
708
+ private void installPluginSupportFiles (PluginInfo info , Path tmpRoot ,
709
+ Path destBinDir , Path destConfigDir , List <Path > deleteOnFailure ) throws Exception {
704
710
Path tmpBinDir = tmpRoot .resolve ("bin" );
705
711
if (Files .exists (tmpBinDir )) {
706
- Path destBinDir = env .binFile ().resolve (info .getName ());
707
712
deleteOnFailure .add (destBinDir );
708
713
installBin (info , tmpBinDir , destBinDir );
709
714
}
@@ -712,14 +717,8 @@ private void installPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
712
717
if (Files .exists (tmpConfigDir )) {
713
718
// some files may already exist, and we don't remove plugin config files on plugin removal,
714
719
// so any installed config files are left on failure too
715
- Path destConfigDir = env .configFile ().resolve (info .getName ());
716
720
installConfig (info , tmpConfigDir , destConfigDir );
717
721
}
718
- movePlugin (tmpRoot , destination );
719
- if (info .requiresKeystore ()) {
720
- createKeystoreIfNeeded (terminal , env , info );
721
- }
722
- terminal .println ("-> Installed " + info .getName ());
723
722
}
724
723
725
724
/** Moves the plugin directory into its final destination. **/
0 commit comments