protected void deleteFile(TranscodeFileImpl file, boolean delete_contents, boolean remove) throws TranscodeException { if (file.isDeleted()) { return; } if (delete_contents) { File f = file.getCacheFile(); int time = 0; while (f.exists() && !f.delete()) { if (time > 3000) { log("Failed to remove file '" + f.getAbsolutePath() + "'"); break; } else { try { Thread.sleep(500); } catch (Throwable e) { } time += 500; } } } if (remove) { try { // fire the listeners FIRST as this gives listeners a chance to extract data // from the file before it is deleted (otherwise operations fail with 'file has been // deleted' for (TranscodeTargetListener l : listeners) { try { l.fileRemoved(file); } catch (Throwable e) { Debug.out(e); } } synchronized (this) { if (device_files == null) { loadDeviceFile(); } else { device_files_last_mod = SystemTime.getMonotonousTime(); } device_files.remove(file.getKey()); device_files_dirty = true; } } catch (Throwable e) { throw (new TranscodeException("Delete failed", e)); } } }