File tree Expand file tree Collapse file tree
core/src/main/java/xyz/gianlu/librespot/cache Expand file tree Collapse file tree Original file line number Diff line number Diff 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!" );
You can’t perform that action at this time.
0 commit comments