Skip to content

Commit 9f58ada

Browse files
author
ntwigg
committed
Hack for parallelism.
1 parent 852b633 commit 9f58ada

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/main/java/com/diffplug/webtools/node/SetupCleanup.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,25 @@
2626

2727
abstract class SetupCleanup<K> {
2828
public void start(File keyFile, K key) throws Exception {
29-
byte[] required = toBytes(key);
30-
if (keyFile.exists()) {
31-
byte[] actual = Files.readAllBytes(keyFile.toPath());
32-
if (Arrays.equals(actual, required)) {
33-
// short-circuit if our state is already setup
34-
return;
35-
} else {
36-
Files.delete(keyFile.toPath());
37-
@SuppressWarnings("unchecked")
38-
K lastKey = (K) fromBytes(required);
39-
doStop(lastKey);
29+
synchronized (key.getClass()) {
30+
byte[] required = toBytes(key);
31+
if (keyFile.exists()) {
32+
byte[] actual = Files.readAllBytes(keyFile.toPath());
33+
if (Arrays.equals(actual, required)) {
34+
// short-circuit if our state is already setup
35+
return;
36+
} else {
37+
Files.delete(keyFile.toPath());
38+
@SuppressWarnings("unchecked")
39+
K lastKey = (K) fromBytes(required);
40+
doStop(lastKey);
41+
}
4042
}
43+
// write out the key
44+
doStart(key);
45+
Files.createDirectories(keyFile.toPath().getParent());
46+
Files.write(keyFile.toPath(), required);
4147
}
42-
// write out the key
43-
doStart(key);
44-
Files.createDirectories(keyFile.toPath().getParent());
45-
Files.write(keyFile.toPath(), required);
4648
}
4749

4850
protected abstract void doStart(K key) throws Exception;

0 commit comments

Comments
 (0)