Skip to content

Commit

Permalink
Avoid NoSuchFieldError.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Apr 24, 2023
1 parent b169e76 commit 6c146f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.db.obj.DownloadItem
import com.github.libretube.services.DownloadService
import java.nio.file.Path
import kotlin.io.path.createDirectories

object DownloadHelper {
const val VIDEO_DIR = "video"
Expand All @@ -35,7 +34,11 @@ object DownloadHelper {
}

fun getDownloadDir(context: Context, path: String): Path {
return getOfflineStorageDir(context).resolve(path).createDirectories()
// TODO: Use createDirectories() when https://issuetracker.google.com/issues/279034662 is
// fixed.
return getOfflineStorageDir(context).resolve(path).apply {
toFile().mkdirs()
}
}

fun getMaxConcurrentDownloads(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import java.nio.file.StandardOpenOption
import java.util.concurrent.Executors
import kotlin.io.path.absolute
import kotlin.io.path.createFile
import kotlin.io.path.deleteIfExists
import kotlin.io.path.fileSize
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -103,7 +104,6 @@ class DownloadService : LifecycleService() {
}

val thumbnailTargetPath = getDownloadPath(DownloadHelper.THUMBNAIL_DIR, fileName)
.absolute()

val download = Download(
videoId,
Expand Down Expand Up @@ -147,7 +147,7 @@ class DownloadService : LifecycleService() {
FileType.AUDIO -> getDownloadPath(DownloadHelper.AUDIO_DIR, item.fileName)
FileType.VIDEO -> getDownloadPath(DownloadHelper.VIDEO_DIR, item.fileName)
FileType.SUBTITLE -> getDownloadPath(DownloadHelper.SUBTITLE_DIR, item.fileName)
}.createFile().absolute()
}.apply { deleteIfExists() }.createFile()

lifecycleScope.launch(coroutineContext) {
item.id = Database.downloadDao().insertDownloadItem(item).toInt()
Expand Down Expand Up @@ -440,7 +440,7 @@ class DownloadService : LifecycleService() {
* Get a [File] from the corresponding download directory and the file name
*/
private fun getDownloadPath(directory: String, fileName: String): Path {
return DownloadHelper.getDownloadDir(this, directory).resolve(fileName)
return DownloadHelper.getDownloadDir(this, directory).resolve(fileName).absolute()
}

override fun onDestroy() {
Expand Down

0 comments on commit 6c146f7

Please sign in to comment.