Skip to content

Fix #3549: Load .tasty from jar if necessary #3550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

Array.empty
}
}
val tastyBytes = classfile match {
Copy link
Contributor

@allanrenucci allanrenucci Nov 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose something along the line of:

val tastyBytes = classfile.underlyingSource match {
  case None =>
    ??? // virtual file?
  case Some(jar: ZipArchive) => // We are in a jar
    val jarArchive = JarArchive.open(File(jar.jpath))
    val tastyFile = File(jarFile.jpath).resolve(classfile.name).changeExtension("tasty")
    val bytes = readBytes(tastyFile)
    jarArchive.close()
    bytes
  case _ =>
    readBytes(File(classfile.jpath).changeExtension("tasty"))
}

It's weird to pattern match on FileZipArchive#LeakyEntry. This is internal implementation detail, should probably be private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you add a comment: // TODO: simplify when #3552 is fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code snippet: underlyingSource seems to return None only for virtual files. In the case there is no underlyingSource, we cannot do anything...

if (attrLen == 0) { // A tasty attribute implies the existence of the .tasty file
def readBytes(file: io.Path): Array[Byte] = {
val plainFile = new PlainFile(file)
if (plainFile.exists) new AbstractFileReader(plainFile).nextBytes(plainFile.sizeOption.get)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is toByteArray defined on AbstractFile

@nicolasstucki nicolasstucki force-pushed the fix-loading-tasty-file-in-jar branch from 912ff90 to f8cc80a Compare November 24, 2017 17:17
@nicolasstucki nicolasstucki changed the title Fix #3549: Workaround broken FileZipArchive#LeakyEntry jpath Fix #3549: Load .tasty from jar if necessary Nov 24, 2017
@nicolasstucki nicolasstucki force-pushed the fix-loading-tasty-file-in-jar branch from f8cc80a to df9a82d Compare November 24, 2017 17:28
@nicolasstucki nicolasstucki force-pushed the fix-loading-tasty-file-in-jar branch from df9a82d to 4774922 Compare November 27, 2017 09:20
@allanrenucci allanrenucci removed their assignment Nov 27, 2017
@nicolasstucki nicolasstucki merged commit d8d1840 into scala:master Nov 27, 2017
@allanrenucci allanrenucci deleted the fix-loading-tasty-file-in-jar branch December 14, 2017 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants