diff --git a/gradle.properties b/gradle.properties index d44a291..1787048 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official group=com.mineinabyss -version=3.1.0-alpha.3 +version=3.1.0-alpha.4 idofrontVersion=0.25.6 diff --git a/keepup-api/src/main/kotlin/com/mineinabyss/keepup/api/KeepupDownloader.kt b/keepup-api/src/main/kotlin/com/mineinabyss/keepup/api/KeepupDownloader.kt index 4d47eae..41cd85a 100644 --- a/keepup-api/src/main/kotlin/com/mineinabyss/keepup/api/KeepupDownloader.kt +++ b/keepup-api/src/main/kotlin/com/mineinabyss/keepup/api/KeepupDownloader.kt @@ -5,6 +5,7 @@ import com.mineinabyss.keepup.downloads.github.GithubConfig import com.mineinabyss.keepup.downloads.parsing.DownloadParser import com.mineinabyss.keepup.downloads.parsing.DownloadSource import com.mineinabyss.keepup.similarfiles.SimilarFileChecker +import com.mineinabyss.keepup.type_checker.FileTypeChecker.SYSTEM_SUPPORTS_FILE import io.ktor.client.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -28,6 +29,7 @@ class KeepupDownloader( dest: Path, scope: CoroutineScope, ): ReceiveChannel = scope.produce(Dispatchers.IO) { + SYSTEM_SUPPORTS_FILE // check if system supports file command val similarFileChecker = if (config.ignoreSimilar) SimilarFileChecker(dest) else null val downloader = DownloadParser( failAllDownloads = config.failAllDownloads, diff --git a/keepup-api/src/main/kotlin/com/mineinabyss/keepup/downloads/parsing/DownloadParser.kt b/keepup-api/src/main/kotlin/com/mineinabyss/keepup/downloads/parsing/DownloadParser.kt index 2a99f35..3c38a43 100644 --- a/keepup-api/src/main/kotlin/com/mineinabyss/keepup/downloads/parsing/DownloadParser.kt +++ b/keepup-api/src/main/kotlin/com/mineinabyss/keepup/downloads/parsing/DownloadParser.kt @@ -69,7 +69,7 @@ class DownloadParser( val expectedFileType = source.expectedType if (it !is DownloadResult.HasFiles || expectedFileType == null) return@map it val type = FileTypeChecker.getType(it.file) - if (type == expectedFileType) it + if (type == null || type == expectedFileType) it else DownloadResult.Failure( "Downloaded file type didn't match expected, got $type, expected $expectedFileType", it.keyInConfig diff --git a/keepup-api/src/main/kotlin/com/mineinabyss/keepup/type_checker/FileTypeChecker.kt b/keepup-api/src/main/kotlin/com/mineinabyss/keepup/type_checker/FileTypeChecker.kt index 8843b02..37cf7e0 100644 --- a/keepup-api/src/main/kotlin/com/mineinabyss/keepup/type_checker/FileTypeChecker.kt +++ b/keepup-api/src/main/kotlin/com/mineinabyss/keepup/type_checker/FileTypeChecker.kt @@ -1,11 +1,24 @@ package com.mineinabyss.keepup.type_checker +import com.github.ajalt.mordant.rendering.TextColors import com.lordcodes.turtle.shellRun +import com.mineinabyss.keepup.helpers.MSG +import com.mineinabyss.keepup.t import java.nio.file.Path import kotlin.io.path.absolutePathString object FileTypeChecker { - fun getType(file: Path): FileType { + val SYSTEM_SUPPORTS_FILE by lazy { + runCatching { + shellRun("command", listOf("-v", "file")) + }.onFailure { + t.println("${MSG.warn} ${TextColors.yellow("System does not support file command, file type checking will be disabled")}") + }.isSuccess + } + + fun getType(file: Path): FileType? { + if (!SYSTEM_SUPPORTS_FILE) return null + val result = shellRun("file", listOf("-b", file.absolutePathString())) return when { result.startsWith("Java archive data") || result.startsWith("Zip archive data") -> FileType.Archive