Skip to content

Commit 0a8fd3d

Browse files
committed
Remove file from cache if inexistent
1 parent 971eb51 commit 0a8fd3d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/cache/CacheManager.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,16 @@ public CacheManager.Handler forFileId(@NotNull ByteString fileId) throws IOExcep
122122

123123
Handler handler = handlers.get(fileId);
124124
if (handler == null) {
125-
handler = new Handler(fileId);
125+
File file = getCacheFile(parent, fileId);
126+
if (!file.exists()) {
127+
try {
128+
remove(Utils.bytesToHex(fileId));
129+
} catch (SQLException ex) {
130+
throw new IOException(ex);
131+
}
132+
}
133+
134+
handler = new Handler(fileId, file);
126135
handlers.put(fileId, handler);
127136
}
128137

@@ -162,14 +171,12 @@ public static Header find(List<Header> headers, byte id) {
162171
}
163172

164173
public class Handler implements Closeable {
165-
private final File file;
166174
private final ByteString fileId;
167175
private final RandomAccessFile io;
168176
private boolean updatedTimestamp = false;
169177

170-
private Handler(@NotNull ByteString fileId) throws IOException {
178+
private Handler(@NotNull ByteString fileId, @NotNull File file) throws IOException {
171179
this.fileId = fileId;
172-
this.file = getCacheFile(parent, fileId);
173180

174181
if (!file.exists() && !file.createNewFile())
175182
throw new IOException("Couldn't create cache file!");

0 commit comments

Comments
 (0)