Skip to content

Commit

Permalink
improve handling of local file:// urls
Browse files Browse the repository at this point in the history
This simplifies the extraction location for reusable extraction of
nested archive files. This allows to use a local file:// url in asset
definitions (for purely local use).
  • Loading branch information
memo33 committed Oct 13, 2024
1 parent 67b59ad commit 4aef455
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/sc4pac/Sc4pac.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ trait UpdateService { this: Sc4pac =>
fallbackFilename,
tempPluginsRoot / pkgFolder,
recipe,
Some(Extractor.JarExtraction.fromUrl(art.url, context.cache, jarsRoot = jarsRoot, profileRoot = context.profileRoot)),
Some(Extractor.JarExtraction.fromUrl(art.url, jarsRoot = jarsRoot)),
hints = depAsset.archiveType,
stagingRoot)
// TODO catch IOExceptions
Expand Down
10 changes: 3 additions & 7 deletions src/main/scala/sc4pac/extractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,11 @@ object Extractor {
*/
case class JarExtraction(jarsDir: os.Path)
object JarExtraction {
def fromUrl[F[_]](archiveUrl: String, cache: FileCache, jarsRoot: os.Path, profileRoot: os.Path): JarExtraction = {
// we use cache to find a consistent archiveSubPath based on the url
val archivePath = os.Path(cache.localFile(archiveUrl), profileRoot)
val cachePath = os.Path(cache.location, profileRoot)
val archiveSubPath = archivePath.subRelativeTo(cachePath)
// we hash the the archiveSubPath to keep paths short
def fromUrl[F[_]](archiveUrl: String, jarsRoot: os.Path): JarExtraction = {
// we hash the the URL to find a deterministic and short storage path
val hash = JD.Checksum.bytesToString(
java.security.MessageDigest.getInstance("SHA-1")
.digest(archiveSubPath.toString.getBytes("UTF-8"))
.digest(archiveUrl.getBytes("UTF-8"))
.take(4).to(collection.immutable.ArraySeq) // 4 bytes = 8 hex characters
)
JarExtraction(jarsRoot / hash)
Expand Down

0 comments on commit 4aef455

Please sign in to comment.