rulec: Fix compiler after switch to NIO2 Paths
The compiler was broken in two ways that are trivially fixed: - If $site_path/cache/rules directory already exists (e.g. other rules were already compiled) creation of the directory failed on local filesystem. Use createDirectories instead, which silently ignores existing directories. - DELETE_ON_CLOSE for the temporary new JAR file holding the bytecode for the rules meant the JAR was deleted immediately after being packed and could not be renamed into the final destination. This caused the compiler to fail with a rename error and never produce the cached bytecode. Omit the option. Change-Id: Ib0855953ec7d1e4eb916946777d99e5c43513a1f
This commit is contained in:

committed by
Dave Borowitz

parent
c30cfb4e16
commit
42ed004363
@@ -14,8 +14,6 @@
|
||||
|
||||
package com.google.gerrit.rules;
|
||||
|
||||
import static java.nio.file.StandardOpenOption.DELETE_ON_CLOSE;
|
||||
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.common.Version;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
@@ -98,11 +96,7 @@ public class PrologCompiler implements Callable<PrologCompiler.Status> {
|
||||
if (ruleDir == null) {
|
||||
throw new CompileException("Caching not enabled");
|
||||
}
|
||||
try {
|
||||
Files.createDirectory(ruleDir);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Cannot create " + ruleDir);
|
||||
}
|
||||
Files.createDirectories(ruleDir);
|
||||
|
||||
File tempDir = File.createTempFile("GerritCodeReview_", ".rulec");
|
||||
if (!tempDir.delete() || !tempDir.mkdir()) {
|
||||
@@ -243,7 +237,7 @@ public class PrologCompiler implements Callable<PrologCompiler.Status> {
|
||||
|
||||
Path tmpjar =
|
||||
Files.createTempFile(archiveFile.getParent(), ".rulec_", ".jar");
|
||||
try (OutputStream stream = Files.newOutputStream(tmpjar, DELETE_ON_CLOSE);
|
||||
try (OutputStream stream = Files.newOutputStream(tmpjar);
|
||||
JarOutputStream out = new JarOutputStream(stream, mf)) {
|
||||
byte buffer[] = new byte[10240];
|
||||
// TODO: fixify this loop
|
||||
|
Reference in New Issue
Block a user