@@ -646,9 +646,11 @@ private void installMetaPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
646646 Environment env , List <Path > deleteOnFailure ) throws Exception {
647647 final MetaPluginInfo metaInfo = MetaPluginInfo .readFromProperties (tmpRoot );
648648 verifyPluginName (env .pluginsFile (), metaInfo .getName (), tmpRoot );
649+
649650 final Path destination = env .pluginsFile ().resolve (metaInfo .getName ());
650651 deleteOnFailure .add (destination );
651652 terminal .println (VERBOSE , metaInfo .toString ());
653+
652654 final List <Path > pluginPaths = new ArrayList <>();
653655 try (DirectoryStream <Path > paths = Files .newDirectoryStream (tmpRoot )) {
654656 // Extract bundled plugins path and validate plugin names
@@ -665,19 +667,11 @@ private void installMetaPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
665667 for (Path plugin : pluginPaths ) {
666668 final PluginInfo info = verify (terminal , plugin , isBatch , env );
667669 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 );
681675 }
682676 }
683677 movePlugin (tmpRoot , destination );
@@ -693,17 +687,28 @@ private void installMetaPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
693687
694688 /**
695689 * 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 .
697691 */
698692 private void installPlugin (Terminal terminal , boolean isBatch , Path tmpRoot ,
699693 Environment env , List <Path > deleteOnFailure ) throws Exception {
700694 final PluginInfo info = verify (terminal , tmpRoot , isBatch , env );
701695 final Path destination = env .pluginsFile ().resolve (info .getName ());
702696 deleteOnFailure .add (destination );
703697
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 {
704710 Path tmpBinDir = tmpRoot .resolve ("bin" );
705711 if (Files .exists (tmpBinDir )) {
706- Path destBinDir = env .binFile ().resolve (info .getName ());
707712 deleteOnFailure .add (destBinDir );
708713 installBin (info , tmpBinDir , destBinDir );
709714 }
@@ -712,14 +717,8 @@ private void installPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
712717 if (Files .exists (tmpConfigDir )) {
713718 // some files may already exist, and we don't remove plugin config files on plugin removal,
714719 // so any installed config files are left on failure too
715- Path destConfigDir = env .configFile ().resolve (info .getName ());
716720 installConfig (info , tmpConfigDir , destConfigDir );
717721 }
718- movePlugin (tmpRoot , destination );
719- if (info .requiresKeystore ()) {
720- createKeystoreIfNeeded (terminal , env , info );
721- }
722- terminal .println ("-> Installed " + info .getName ());
723722 }
724723
725724 /** Moves the plugin directory into its final destination. **/
0 commit comments