Skip to content

Commit 56c2642

Browse files
authored
handle cache directory failures (#4165)
throw CacheException on cache directory failures
1 parent 26ea642 commit 56c2642

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.history;
2424

25+
import org.jetbrains.annotations.Nullable;
2526
import org.jetbrains.annotations.VisibleForTesting;
2627
import org.opengrok.indexer.configuration.RuntimeEnvironment;
2728
import org.opengrok.indexer.logger.LoggerFactory;
@@ -64,7 +65,15 @@ public static void writeCache(Object object, File output) throws IOException {
6465
}
6566
}
6667

68+
/**
69+
*
70+
* @param repository {@link RepositoryInfo} instance
71+
* @param cache {@link Cache} instance
72+
* @return absolute directory path for top level cache directory of given repository.
73+
* Will return {@code null} on error.
74+
*/
6775
@VisibleForTesting
76+
@Nullable
6877
public static String getRepositoryCacheDataDirname(RepositoryInfo repository, Cache cache) {
6978
String repoDirBasename;
7079

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2018, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -446,10 +446,14 @@ public void store(History history, Repository repository, String tillRevision) t
446446
// File based history cache does not store files for individual changesets so strip them.
447447
history.strip();
448448

449-
File histDataDir = new File(CacheUtil.getRepositoryCacheDataDirname(repository, this));
449+
String repoCachePath = CacheUtil.getRepositoryCacheDataDirname(repository, this);
450+
if (repoCachePath == null) {
451+
throw new CacheException(String.format("failed to get cache directory path for %s", repository));
452+
}
453+
File histDataDir = new File(repoCachePath);
450454
// Check the directory again in case of races (might happen in the presence of sub-repositories).
451455
if (!histDataDir.isDirectory() && !histDataDir.mkdirs() && !histDataDir.isDirectory()) {
452-
LOGGER.log(Level.WARNING, "cannot create history cache directory for ''{0}''", histDataDir);
456+
throw new CacheException(String.format("cannot create history cache directory for '%s'", histDataDir));
453457
}
454458

455459
Set<String> regularFiles = map.keySet().stream().

0 commit comments

Comments
 (0)