Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta-plugin should install bin and config at the top level #28162

Merged
merged 1 commit into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ private void installMetaPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
pluginInfos.add(info);
Path tmpBinDir = plugin.resolve("bin");
if (Files.exists(tmpBinDir)) {
Path destBinDir = env.binFile().resolve(metaInfo.getName()).resolve(info.getName());
Path destBinDir = env.binFile().resolve(metaInfo.getName());
deleteOnFailure.add(destBinDir);
installBin(info, tmpBinDir, destBinDir);
}
Expand All @@ -676,7 +676,7 @@ private void installMetaPlugin(Terminal terminal, boolean isBatch, Path tmpRoot,
if (Files.exists(tmpConfigDir)) {
// some files may already exist, and we don't remove plugin config files on plugin removal,
// so any installed config files are left on failure too
Path destConfigDir = env.configFile().resolve(metaInfo.getName()).resolve(info.getName());
Path destConfigDir = env.configFile().resolve(metaInfo.getName());
installConfig(info, tmpConfigDir, destConfigDir);
}
}
Expand Down Expand Up @@ -744,7 +744,6 @@ public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
});
}


/** Copies the files from {@code tmpBinDir} into {@code destBinDir}, along with permissions from dest dirs parent. */
private void installBin(PluginInfo info, Path tmpBinDir, Path destBinDir) throws Exception {
if (Files.isDirectory(tmpBinDir) == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,17 @@ MockTerminal installPlugin(String pluginUrl, Path home, InstallPluginCommand com
}

void assertMetaPlugin(String metaPlugin, String name, Path original, Environment env) throws IOException {
assertPluginInternal(name, original, env,
env.pluginsFile().resolve(metaPlugin), env.configFile().resolve(metaPlugin), env.binFile().resolve(metaPlugin));
assertPluginInternal(name, env.pluginsFile().resolve(metaPlugin));
assertConfigAndBin(metaPlugin, original, env);
}


void assertPlugin(String name, Path original, Environment env) throws IOException {
assertPluginInternal(name, original, env,
env.pluginsFile(), env.configFile(), env.binFile());
assertPluginInternal(name, env.pluginsFile());
assertConfigAndBin(name, original, env);
assertInstallCleaned(env);
}

void assertPluginInternal(String name, Path original, Environment env,
Path pluginsFile, Path configFile, Path binFile) throws IOException {
void assertPluginInternal(String name, Path pluginsFile) throws IOException {
Path got = pluginsFile.resolve(name);
assertTrue("dir " + name + " exists", Files.exists(got));

Expand All @@ -294,17 +293,19 @@ void assertPluginInternal(String name, Path original, Environment env,
PosixFilePermission.OTHERS_READ,
PosixFilePermission.OTHERS_EXECUTE));
}

assertTrue("jar was copied", Files.exists(got.resolve("plugin.jar")));
assertFalse("bin was not copied", Files.exists(got.resolve("bin")));
assertFalse("config was not copied", Files.exists(got.resolve("config")));
}

void assertConfigAndBin(String name, Path original, Environment env) throws IOException {
if (Files.exists(original.resolve("bin"))) {
Path binDir = binFile.resolve(name);
Path binDir = env.binFile().resolve(name);
assertTrue("bin dir exists", Files.exists(binDir));
assertTrue("bin is a dir", Files.isDirectory(binDir));
PosixFileAttributes binAttributes = null;
if (isPosix) {
binAttributes = Files.readAttributes(binFile, PosixFileAttributes.class);
binAttributes = Files.readAttributes(env.binFile(), PosixFileAttributes.class);
}
try (DirectoryStream<Path> stream = Files.newDirectoryStream(binDir)) {
for (Path file : stream) {
Expand All @@ -317,7 +318,7 @@ void assertPluginInternal(String name, Path original, Environment env,
}
}
if (Files.exists(original.resolve("config"))) {
Path configDir = configFile.resolve(name);
Path configDir = env.configFile().resolve(name);
assertTrue("config dir exists", Files.exists(configDir));
assertTrue("config is a dir", Files.isDirectory(configDir));

Expand All @@ -326,7 +327,7 @@ void assertPluginInternal(String name, Path original, Environment env,

if (isPosix) {
PosixFileAttributes configAttributes =
Files.getFileAttributeView(configFile, PosixFileAttributeView.class).readAttributes();
Files.getFileAttributeView(env.configFile(), PosixFileAttributeView.class).readAttributes();
user = configAttributes.owner();
group = configAttributes.group();

Expand All @@ -351,7 +352,6 @@ void assertPluginInternal(String name, Path original, Environment env,
}
}
}
assertInstallCleaned(env);
}

void assertInstallCleaned(Environment env) throws IOException {
Expand Down Expand Up @@ -734,7 +734,7 @@ public void testExistingConfig() throws Exception {

public void testExistingMetaConfig() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path envConfigDir = env.v2().configFile().resolve("my_plugins").resolve("fake");
Path envConfigDir = env.v2().configFile().resolve("my_plugins");
Files.createDirectories(envConfigDir);
Files.write(envConfigDir.resolve("custom.yml"), "existing config".getBytes(StandardCharsets.UTF_8));
Path metaDir = createPluginDir(temp);
Expand Down