Compare commits

..

3 Commits

Author SHA1 Message Date
comp500
bca2d758e1 Fix SpaceSafeURI nullability issues 2022-02-21 22:03:56 +00:00
comp500
46771ce870 Clarify error message for missing index file 2021-07-16 04:07:45 +01:00
comp500
b143f67acd Fix symlink check by catching the correct exception 2021-06-22 13:54:06 +01:00
5 changed files with 12 additions and 14 deletions

View File

@@ -183,7 +183,7 @@ internal class DownloadTask private constructor(val metadata: IndexFile.File, de
// isDirectory follows symlinks, but createDirectories doesn't
try {
Files.createDirectories(destPath.parent)
} catch (e: FileAlreadyExistsException) {
} catch (e: java.nio.file.FileAlreadyExistsException) {
if (!Files.isDirectory(destPath.parent)) {
throw e
}

View File

@@ -21,7 +21,6 @@ import link.infra.packwiz.installer.ui.IUserInterface.ExceptionListResult
import link.infra.packwiz.installer.ui.data.InstallProgress
import link.infra.packwiz.installer.util.Log
import link.infra.packwiz.installer.util.ifletOrErr
import link.infra.packwiz.installer.util.ifletOrWarn
import okio.buffer
import java.io.FileNotFoundException
import java.io.FileReader
@@ -29,7 +28,6 @@ import java.io.FileWriter
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import java.util.concurrent.CompletionService
import java.util.concurrent.ExecutionException
import java.util.concurrent.ExecutorCompletionService
@@ -194,7 +192,8 @@ class UpdateManager internal constructor(private val opts: Options, val ui: IUse
handleCancellation()
}
try {
ifletOrWarn(pf.index, "No index file found") { index ->
// TODO: switch to OkHttp for better redirect handling
ui.ifletOrErr(pf.index, "No index file found, or the pack file is empty; note that Java doesn't automatically follow redirects from HTTP to HTTPS (and may cause this error)") { index ->
ui.ifletOrErr(index.hashFormat, index.hash, "Pack has no hash or hashFormat for index") { hashFormat, hash ->
ui.ifletOrErr(getNewLoc(opts.downloadURI, index.file), "Pack has invalid index file: " + index.file) { newLoc ->
processIndex(

View File

@@ -78,9 +78,9 @@ class IndexFile {
get() {
if (metafile) {
return linkedFile?.name ?: linkedFile?.filename ?:
file?.run { Paths.get(path).fileName.toString() } ?: "Invalid file"
file?.run { Paths.get(path ?: return "Invalid file").fileName.toString() } ?: "Invalid file"
}
return file?.run { Paths.get(path).fileName.toString() } ?: "Invalid file"
return file?.run { Paths.get(path ?: return "Invalid file").fileName.toString() } ?: "Invalid file"
}
// TODO: URIs are bad

View File

@@ -32,7 +32,7 @@ class SpaceSafeURI : Comparable<SpaceSafeURI>, Serializable {
)
}
val path: String get() = u.path.replace("%20", " ")
val path: String? get() = u.path?.replace("%20", " ")
override fun toString(): String = u.toString().replace("%20", " ")
@@ -52,9 +52,9 @@ class SpaceSafeURI : Comparable<SpaceSafeURI>, Serializable {
override fun compareTo(other: SpaceSafeURI): Int = u.compareTo(other.u)
val scheme: String get() = u.scheme
val authority: String get() = u.authority
val host: String get() = u.host
val scheme: String? get() = u.scheme
val authority: String? get() = u.authority
val host: String? get() = u.host
@Throws(MalformedURLException::class)
fun toURL(): URL = u.toURL()

View File

@@ -1,7 +1,6 @@
package link.infra.packwiz.installer.request.handlers
import link.infra.packwiz.installer.metadata.SpaceSafeURI
import java.util.*
import java.util.concurrent.locks.ReentrantReadWriteLock
import java.util.regex.Pattern
import kotlin.concurrent.read
@@ -21,7 +20,7 @@ class RequestHandlerGithub : RequestHandlerZip(true) {
private val zipUriMap: MutableMap<String, SpaceSafeURI> = HashMap()
private val zipUriLock = ReentrantReadWriteLock()
private fun getRepoName(loc: SpaceSafeURI): String? {
val matcher = repoMatcherPattern.matcher(loc.path)
val matcher = repoMatcherPattern.matcher(loc.path ?: return null)
return if (matcher.matches()) {
matcher.group(1)
} else {
@@ -47,7 +46,7 @@ class RequestHandlerGithub : RequestHandlerZip(true) {
}
private fun getBranch(loc: SpaceSafeURI): String? {
val matcher = branchMatcherPattern.matcher(loc.path)
val matcher = branchMatcherPattern.matcher(loc.path ?: return null)
return if (matcher.matches()) {
matcher.group(1)
} else {
@@ -66,6 +65,6 @@ class RequestHandlerGithub : RequestHandlerZip(true) {
return false
}
// TODO: more match testing?
return "github.com" == loc.host && branchMatcherPattern.matcher(loc.path).matches()
return "github.com" == loc.host && branchMatcherPattern.matcher(loc.path ?: return false).matches()
}
}