diff options
author | Brian Muramatsu <btmura@google.com> | 2011-12-19 12:21:46 -0800 |
---|---|---|
committer | Brian Muramatsu <btmura@google.com> | 2011-12-19 12:54:32 -0800 |
commit | bad23f6a001704bc287aa7038a87afc8f3d1e319 (patch) | |
tree | 1b884266f18895e58179cee64791cf00f0ffa5da | |
parent | 1348933b1d6df0386f9442c97af269bc9c702c0e (diff) | |
download | platform_cts-bad23f6a001704bc287aa7038a87afc8f3d1e319.tar.gz platform_cts-bad23f6a001704bc287aa7038a87afc8f3d1e319.tar.bz2 platform_cts-bad23f6a001704bc287aa7038a87afc8f3d1e319.zip |
Fix Build Race Condition
One thread could see that the directory was not there
and context switch to another thread that also
doesn't see the directory and creates it. The other
thread would then fail because mkDirs returns
false if the directory exists...
Change-Id: I8fa50acbcaf2637a89cb876e7bc4c544a5c9c1e7
-rw-r--r-- | tools/cts-native-xml-generator/src/com/android/cts/nativexml/Generator.java | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/cts-native-xml-generator/src/com/android/cts/nativexml/Generator.java b/tools/cts-native-xml-generator/src/com/android/cts/nativexml/Generator.java index 3a75e495f3d..7c074b860a4 100644 --- a/tools/cts-native-xml-generator/src/com/android/cts/nativexml/Generator.java +++ b/tools/cts-native-xml-generator/src/com/android/cts/nativexml/Generator.java @@ -59,9 +59,12 @@ class Generator { if (mOutputPath != null) { File outputFile = new File(mOutputPath); File outputDir = outputFile.getParentFile(); - if (!outputDir.exists() && !outputDir.mkdirs()) { - System.err.println("Couldn't make output directory: " + mOutputPath); - System.exit(1); + if (!outputDir.exists()) { + outputDir.mkdirs(); + if (!outputDir.exists()) { + System.err.println("Couldn't make output directory: " + outputDir); + System.exit(1); + } } output = new FileOutputStream(outputFile); } |