Skip to content

Commit

Permalink
fix: ensure R cache folder exists
Browse files Browse the repository at this point in the history
ymarcon committed Sep 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1e34dbd commit 9be21e5
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ public RCacheHelper(CryptoService cryptoService) {

public boolean hasCache(String cacheKey) {
File cache = new File(cacheDir, cacheKey + ".enc");
ensureCacheDir();
return cache.exists();
}

@@ -40,6 +41,7 @@ public void evictAll() {

public void evictCache(String prefix) {
try {
ensureCacheDir();
File[] files = cacheDir.listFiles(file -> file.getName().startsWith(prefix));
if (files != null) {
for (File file : files) {
@@ -53,12 +55,17 @@ public void evictCache(String prefix) {

public InputStream newRDSInputStream(String cacheKey) throws IOException {
File cache = new File(cacheDir, cacheKey + ".enc");
cache.getParentFile().mkdirs();
ensureCacheDir();
return cryptoService.newCipherInputStream(new FileInputStream(cache));
}

public OutputStream newRDSOutputStream(String cacheKey) throws IOException {
File cache = new File(cacheDir, cacheKey + ".enc");
ensureCacheDir();
return cryptoService.newCipherOutputStream(new FileOutputStream(cache));
}

private void ensureCacheDir() {
cacheDir.mkdirs();
}
}

0 comments on commit 9be21e5

Please sign in to comment.