Skip to content

Commit bce103b

Browse files
committed
chore: remove code around URL building
It is already supported by java.net.URI
1 parent 5bf0792 commit bce103b

File tree

2 files changed

+1
-16
lines changed

2 files changed

+1
-16
lines changed

src/main/kotlin/com/coder/toolbox/cli/downloader/CoderDownloadService.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.coder.toolbox.util.SemVer
77
import com.coder.toolbox.util.getHeaders
88
import com.coder.toolbox.util.getOS
99
import com.coder.toolbox.util.sha1
10-
import com.coder.toolbox.util.withLastSegment
1110
import okhttp3.ResponseBody
1211
import retrofit2.Response
1312
import java.io.FileInputStream
@@ -154,7 +153,7 @@ class CoderDownloadService(
154153
}
155154

156155
private suspend fun downloadSignature(url: URL, showTextProgress: (String) -> Unit): DownloadResult {
157-
val signatureURL = url.withLastSegment(context.settingsStore.defaultSignatureNameByOsAndArch)
156+
val signatureURL = url.toURI().resolve(context.settingsStore.defaultSignatureNameByOsAndArch).toURL()
158157
val localSignaturePath = localBinaryPath.parent.resolve(context.settingsStore.defaultSignatureNameByOsAndArch)
159158
context.logger.info("Downloading signature from $signatureURL")
160159

src/main/kotlin/com/coder/toolbox/util/URLExtensions.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ fun URL.withPath(path: String): URL = URL(
1313
if (path.startsWith("/")) path else "/$path",
1414
)
1515

16-
fun URL.withLastSegment(segment: String): URL {
17-
val uri = this.toURI()
18-
val basePath = uri.path.substringBeforeLast('/')
19-
val newPath = "$basePath/$segment"
20-
val newUri = URI(
21-
uri.scheme,
22-
uri.authority,
23-
newPath,
24-
uri.query,
25-
uri.fragment
26-
)
27-
return newUri.toURL()
28-
}
29-
3016
/**
3117
* Return the host, converting IDN to ASCII in case the file system cannot
3218
* support the necessary character set.

0 commit comments

Comments
 (0)