diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-11-12 23:00:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-12 23:00:06 +0100 |
commit | 46c3d4e8c1a4031837569916318328e4fc8ede76 (patch) | |
tree | 2279a57bfd7f4cc6f886f2d8792b7f7c426dfcac /core | |
parent | 7bfb53cc001dcb98a40a3fe327b9d53b4a60a144 (diff) | |
download | AntennaPod-46c3d4e8c1a4031837569916318328e4fc8ede76.zip |
Fix file deletion (#6758)
- When deleting local folders, don't delete files
- Don't try to delete files twice
- Fix deleting non-local feeds
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index 1453f701d..c5c656705 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -116,7 +116,16 @@ public class DBWriter { Log.i(TAG, String.format(Locale.US, "Requested to delete FeedMedia [id=%d, title=%s, downloaded=%s", media.getId(), media.getEpisodeTitle(), media.isDownloaded())); boolean localDelete = false; - if (media.isDownloaded() || media.getFile_url() != null) { + if (media.getFile_url() != null && media.getFile_url().startsWith("content://")) { + // Local feed + DocumentFile documentFile = DocumentFile.fromSingleUri(context, Uri.parse(media.getFile_url())); + if (documentFile == null || !documentFile.exists() || !documentFile.delete()) { + EventBus.getDefault().post(new MessageEvent(context.getString(R.string.delete_local_failed))); + return false; + } + media.setFile_url(null); + localDelete = true; + } else if (media.getFile_url() != null) { // delete downloaded media file File mediaFile = new File(media.getFile_url()); if (mediaFile.exists() && !mediaFile.delete()) { @@ -131,15 +140,6 @@ public class DBWriter { adapter.open(); adapter.setMedia(media); adapter.close(); - } else if (media.getFile_url().startsWith("content://")) { - // Local feed - DocumentFile documentFile = DocumentFile.fromSingleUri( - context, Uri.parse(media.getFile_url())); - if (documentFile == null || !documentFile.exists() || !documentFile.delete()) { - EventBus.getDefault().post(new MessageEvent(context.getString(R.string.delete_local_failed))); - return false; - } - localDelete = true; } if (media.getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId()) { @@ -224,10 +224,12 @@ public class DBWriter { PlaybackPreferences.writeNoMediaPlaying(); IntentUtils.sendLocalBroadcast(context, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE); } - if (item.getMedia().isDownloaded()) { - deleteFeedMediaSynchronous(context, item.getMedia()); + if (!item.getFeed().isLocalFeed()) { + DownloadServiceInterface.get().cancel(context, item.getMedia()); + if (item.getMedia().isDownloaded()) { + deleteFeedMediaSynchronous(context, item.getMedia()); + } } - DownloadServiceInterface.get().cancel(context, item.getMedia()); } } |