mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-30 23:27:17 +02:00
Prevent duplicate files from being created and downloaded
This commit is contained in:
@@ -121,6 +121,30 @@ class DownloadItemManager(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if file already exists in shared storage
|
||||||
|
if (!downloadItemPart.isInternalStorage) {
|
||||||
|
val destinationFile =
|
||||||
|
DocumentFileCompat.fromFullPath(mainActivity, downloadItemPart.finalDestinationPath)
|
||||||
|
if (destinationFile != null && destinationFile.exists()) {
|
||||||
|
Log.d(
|
||||||
|
tag,
|
||||||
|
"File already exists in shared storage at path ${downloadItemPart.finalDestinationPath}"
|
||||||
|
)
|
||||||
|
downloadItemPart.completed = true
|
||||||
|
downloadItemPart.moved = true
|
||||||
|
downloadItemPart.failed = false
|
||||||
|
downloadItemPart.downloadId = 1
|
||||||
|
currentDownloadItemParts.add(downloadItemPart)
|
||||||
|
clientEventEmitter.onDownloadItemPartUpdate(downloadItemPart)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
Log.d(
|
||||||
|
tag,
|
||||||
|
"File does not exist in shared storage at path ${downloadItemPart.finalDestinationPath}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log.d(
|
Log.d(
|
||||||
tag,
|
tag,
|
||||||
"Start internal download to destination path ${downloadItemPart.finalDestinationPath} from ${downloadItemPart.serverUrl}"
|
"Start internal download to destination path ${downloadItemPart.finalDestinationPath} from ${downloadItemPart.serverUrl}"
|
||||||
@@ -163,8 +187,9 @@ class DownloadItemManager(
|
|||||||
|
|
||||||
if (downloadItemPart.completed) {
|
if (downloadItemPart.completed) {
|
||||||
val downloadItem = downloadItemQueue.find { it.id == downloadItemPart.downloadItemId }
|
val downloadItem = downloadItemQueue.find { it.id == downloadItemPart.downloadItemId }
|
||||||
if (!downloadItemPart.isInternalStorage) {
|
if (!downloadItemPart.isInternalStorage && !downloadItemPart.moved) {
|
||||||
// After downloading, move the downloaded file to the final destination
|
// After downloading, move the downloaded file to the final destination if it was
|
||||||
|
// not already moved during a previous multipart download
|
||||||
// After moving the file, checkDownloadItemFinished is called anyway
|
// After moving the file, checkDownloadItemFinished is called anyway
|
||||||
downloadItem?.let { moveDownloadedFile(it, downloadItemPart) }
|
downloadItem?.let { moveDownloadedFile(it, downloadItemPart) }
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -265,6 +265,10 @@ class AbsDownloader : Plugin() {
|
|||||||
val finalDestinationFile = File("$itemFolderPath/$destinationFilename")
|
val finalDestinationFile = File("$itemFolderPath/$destinationFilename")
|
||||||
val destinationFile = File("$tempFolderPath/$destinationFilename")
|
val destinationFile = File("$tempFolderPath/$destinationFilename")
|
||||||
|
|
||||||
|
/*
|
||||||
|
// This logic would delete files if they exist. This has been removed to allow for continuing
|
||||||
|
// downloads if the app is restarted. This should be handled in the download manager
|
||||||
|
// allow a setting to continue downloads or delete incomplete downloads
|
||||||
if (destinationFile.exists()) {
|
if (destinationFile.exists()) {
|
||||||
Log.d(
|
Log.d(
|
||||||
tag,
|
tag,
|
||||||
@@ -280,6 +284,7 @@ class AbsDownloader : Plugin() {
|
|||||||
)
|
)
|
||||||
finalDestinationFile.delete()
|
finalDestinationFile.delete()
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
val downloadItemPart =
|
val downloadItemPart =
|
||||||
DownloadItemPart.make(
|
DownloadItemPart.make(
|
||||||
|
|||||||
Reference in New Issue
Block a user