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
This commit is contained in:
Christian Aistleitner
2020-05-31 15:27:12 +02:00
parent 51b865f0f3
commit 7bfa1c320b
2 changed files with 1 additions and 3 deletions

View File

@@ -110,9 +110,6 @@ public class JarPluginProvider implements ServerPluginProvider {
public static Path storeInTemp(String pluginName, InputStream in, SitePaths sitePaths) public static Path storeInTemp(String pluginName, InputStream in, SitePaths sitePaths)
throws IOException { throws IOException {
if (!Files.exists(sitePaths.tmp_dir)) {
Files.createDirectories(sitePaths.tmp_dir);
}
return PluginUtil.asTemp(in, tempNameFor(pluginName), ".jar", sitePaths.tmp_dir); return PluginUtil.asTemp(in, tempNameFor(pluginName), ".jar", sitePaths.tmp_dir);
} }

View File

@@ -53,6 +53,7 @@ public class PluginUtil {
} }
static Path asTemp(InputStream in, String prefix, String suffix, Path dir) throws IOException { static Path asTemp(InputStream in, String prefix, String suffix, Path dir) throws IOException {
Files.createDirectories(dir);
Path tmp = Files.createTempFile(dir, prefix, suffix); Path tmp = Files.createTempFile(dir, prefix, suffix);
boolean keep = false; boolean keep = false;
try (OutputStream out = Files.newOutputStream(tmp)) { try (OutputStream out = Files.newOutputStream(tmp)) {