Skip to content

Commit ad1826b

Browse files
vladakahornace
authored andcommitted
handle delete() better
also make the log messages more useful
1 parent 2328725 commit ad1826b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.InputStream;
4242
import java.io.OutputStreamWriter;
4343
import java.io.Writer;
44+
import java.nio.file.Files;
4445
import java.nio.file.NoSuchFileException;
4546
import java.nio.file.Paths;
4647
import java.util.ArrayList;
@@ -271,15 +272,17 @@ private void writeHistoryToFile(File dir, History history, File cacheFile) throw
271272
LOGGER.log(Level.WARNING,
272273
"Failed to remove temporary history cache file");
273274
}
274-
throw new HistoryException(
275-
"Cachefile exists, and I could not delete it.");
275+
throw new HistoryException(String.format("Cache file '%s' exists, and could not be deleted.",
276+
cacheFile));
276277
}
277278
if (!output.renameTo(cacheFile)) {
278-
if (!output.delete()) {
279-
LOGGER.log(Level.WARNING,
280-
"Failed to remove temporary history cache file");
279+
try {
280+
Files.delete(output.toPath());
281+
} catch (IOException e) {
282+
throw new HistoryException("failed to delete output file", e);
281283
}
282-
throw new HistoryException("Failed to rename cache tmpfile.");
284+
throw new HistoryException(String.format("Failed to rename cache temporary file '%s' to '%s'",
285+
output, cacheFile));
283286
}
284287
}
285288
}

0 commit comments

Comments
 (0)