Skip to content

Commit

Permalink
use Files.exist() #77
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteph-de committed Apr 12, 2024
1 parent e03a81c commit afef5ea
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ public static DiskLruCache open(Path directory, int appVersion, int valueCount,

// If a bkp file exists, use it instead.
Path backupFile = directory.resolve(JOURNAL_FILE_BACKUP);
if (backupFile.toFile().exists()) {
if (Files.exists(backupFile)) {
Path journalFile = directory.resolve(JOURNAL_FILE);
// If journal file also exists just delete backup file.
if (journalFile.toFile().exists()) {
if (Files.exists(journalFile)) {
backupFile.toFile().delete();
} else {
renameTo(backupFile, journalFile, false);
Expand All @@ -223,7 +223,7 @@ public static DiskLruCache open(Path directory, int appVersion, int valueCount,

// Prefer to pick up where we left off.
DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
if (cache.journalFile.toFile().exists()) {
if (Files.exists(cache.journalFile)) {
try {
cache.readJournal();
cache.processJournal();
Expand Down Expand Up @@ -381,7 +381,7 @@ private synchronized void rebuildJournal() throws IOException {
closeWriter(writer);
}

if (journalFile.toFile().exists()) {
if (Files.exists(journalFile)) {
renameTo(journalFile, journalFileBackup, true);
}
renameTo(journalFileTmp, journalFile, false);
Expand Down Expand Up @@ -422,7 +422,7 @@ public synchronized Value get(String key) throws IOException {

for (Path file : entry.cleanFiles) {
// A file must have been deleted manually!
if (!file.toFile().exists()) {
if (!Files.exists(file)) {
return null;
}
}
Expand Down Expand Up @@ -517,26 +517,26 @@ private synchronized void completeEdit(Editor editor, boolean success) throws IO
editor.abort();
throw new IllegalStateException("Newly created entry didn't create value for index " + i);
}
if (!entry.getDirtyFile(i).toFile().exists()) {
if (!Files.exists(entry.getDirtyFile(i))) {
editor.abort();
return;
}
}
}

for (int i = 0; i < valueCount; i++) {
File dirty = entry.getDirtyFile(i).toFile();
Path dirty = entry.getDirtyFile(i);
if (success) {
if (dirty.exists()) {
if (Files.exists(dirty)) {
File clean = entry.getCleanFile(i).toFile();
dirty.renameTo(clean);
dirty.toFile().renameTo(clean);
long oldLength = entry.lengths[i];
long newLength = clean.length();
entry.lengths[i] = newLength;
size = size - oldLength + newLength;
}
} else {
deleteIfExists(dirty);
deleteIfExists(dirty.toFile());
}
}

Expand Down Expand Up @@ -591,8 +591,8 @@ public synchronized boolean remove(String key) throws IOException {
}

for (int i = 0; i < valueCount; i++) {
File file = entry.getCleanFile(i).toFile();
if (file.exists() && !file.delete()) {
Path file = entry.getCleanFile(i);
if (Files.exists(file) && !file.toFile().delete()) {
throw new IOException("failed to delete " + file);
}
size -= entry.lengths[i];
Expand Down

0 comments on commit afef5ea

Please sign in to comment.