summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Aistleitner <christian@quelltextlich.at>2020-05-31 15:27:12 +0200
committerChristian Aistleitner <christian@quelltextlich.at>2020-07-03 13:57:59 +0200
commitb5a08cf8191ee998a3a5ea75f13f27e6a923daca (patch)
treea09d4034948a8deee2e56befc0498fa41efe77bc
parent9764e50a45cae5cbd373e2e3be6e79a1162c27c0 (diff)
When writing temporary plugin files, ensure the directory exists
When adding plugins as streams in PluginIT (which upcoming commits will do), installing the plugin failed, as the temporary directory does not exist. Instead of fixing the caller of `asTemp` to create the directory before the call, we instead change `asTemp` itself to create the directory, and can thereby simplify other callers, which also manually create the directory. Change-Id: If7962ee2898f52c0db43cf030528a82530a2442b
-rw-r--r--java/com/google/gerrit/server/plugins/JarPluginProvider.java3
-rw-r--r--java/com/google/gerrit/server/plugins/PluginUtil.java3
2 files changed, 3 insertions, 3 deletions
diff --git a/java/com/google/gerrit/server/plugins/JarPluginProvider.java b/java/com/google/gerrit/server/plugins/JarPluginProvider.java
index 5b800596ee..82f97c95e6 100644
--- a/java/com/google/gerrit/server/plugins/JarPluginProvider.java
+++ b/java/com/google/gerrit/server/plugins/JarPluginProvider.java
@@ -110,9 +110,6 @@ public class JarPluginProvider implements ServerPluginProvider {
public static Path storeInTemp(String pluginName, InputStream in, SitePaths sitePaths)
throws IOException {
- if (!Files.exists(sitePaths.tmp_dir)) {
- Files.createDirectories(sitePaths.tmp_dir);
- }
return PluginUtil.asTemp(in, tempNameFor(pluginName), ".jar", sitePaths.tmp_dir);
}
diff --git a/java/com/google/gerrit/server/plugins/PluginUtil.java b/java/com/google/gerrit/server/plugins/PluginUtil.java
index d4110ca8d2..4f00cd0849 100644
--- a/java/com/google/gerrit/server/plugins/PluginUtil.java
+++ b/java/com/google/gerrit/server/plugins/PluginUtil.java
@@ -53,6 +53,9 @@ public class PluginUtil {
}
static Path asTemp(InputStream in, String prefix, String suffix, Path dir) throws IOException {
+ if (!Files.exists(dir)) {
+ Files.createDirectories(dir);
+ }
Path tmp = Files.createTempFile(dir, prefix, suffix);
boolean keep = false;
try (OutputStream out = Files.newOutputStream(tmp)) {