Skip to content

Commit c57b4ef

Browse files
ahornaceVladimir Kotal
authored andcommitted
Fix testRemoveFileOnFileChange test
1 parent 903e909 commit c57b4ef

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,7 @@ private History mergeOldAndNewHistory(File cacheFile, History histNew, Repositor
335335
* @param mergeHistory whether to merge the history with existing or
336336
* store the histNew as is
337337
*/
338-
private void storeFile(History histNew, File file, Repository repo,
339-
boolean mergeHistory) throws HistoryException {
340-
338+
private void storeFile(History histNew, File file, Repository repo, boolean mergeHistory) throws HistoryException {
341339
File cacheFile;
342340
try {
343341
cacheFile = getCachedFile(file);
@@ -348,9 +346,9 @@ private void storeFile(History histNew, File file, Repository repo,
348346
History history = histNew;
349347

350348
File dir = cacheFile.getParentFile();
351-
if (!dir.isDirectory() && !dir.mkdirs()) {
352-
throw new HistoryException(
353-
"Unable to create cache directory '" + dir + "'.");
349+
// calling isDirectory twice to prevent a race condition
350+
if (!dir.isDirectory() && !dir.mkdirs() && !dir.isDirectory()) {
351+
throw new HistoryException("Unable to create cache directory '" + dir + "'.");
354352
}
355353

356354
if (mergeHistory && cacheFile.exists()) {

0 commit comments

Comments
 (0)