[GRADLE-3269] Cannot expand archive with read only entries on non clean build Created: 24/Mar/15  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 5

Issue Links:
Related
Related to GRADLE-2959 zipTree unable to overwrite temporary... Resolved
Related to GRADLE-3310 Gradle 2.5 RC 1 broke .tar.gz Resolved

 Description   

If an archive has an entry that is read only, we fail to expand it if has already been expanded.



 Comments   
Comment by Gradle Forums [ 24/Mar/15 ]

I'm not aware of a limit, and if there is one, it's somewhere in the GB range. There appears to be some other problem with your archive.

Comment by Gradle Forums [ 24/Mar/15 ]

I am seeing the same issue with Gradle 2.2.1.

println tarTree(configurations.jdk.singleFile).files

Results in:

FAILURE: Build failed with an exception.

  • Where:
    Build file '/path/to/project/build.gradle' line: 40
  • What went wrong:
    A problem occurred evaluating root project 'project'.
    > Unable to expand TAR '/path/to/jdk/archive/jdk-8u40-linux-x64.tar.gz'
    The tar might be corrupted or it is compressed in an unexpected way.
    By default the tar tree tries to guess the compression based on the file extension.
    If you need to specify the compression explicitly please refer to the DSL reference.
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.081 secs

This is an unaltered copy of the Oracle JDK tarball. I have verified that it is usable from the command line. Something Gradle-related doesn't like it. I could see it being the size (166M) as I've not run into this particular error before with tarballs.

In case it comes up, I get the exact same error inside a copy task

Comment by Gradle Forums [ 24/Mar/15 ]

Could you please run with `--stacktrace` and provide the stack. Hopefully it contains information on the real error.

Comment by Gradle Forums [ 24/Mar/15 ]

Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'project'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:148)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:59)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:504)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:83)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:42)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: org.gradle.api.GradleException: Unable to expand TAR '/path/to/jdk/archive/jdk-8u40-linux-x64.tar.gz'
The tar might be corrupted or it is compressed in an unexpected way.
By default the tar tree tries to guess the compression based on the file extension.
If you need to specify the compression explicitly please refer to the DSL reference.
at org.gradle.api.internal.file.archive.TarFileTree.visit(TarFileTree.java:79)
at org.gradle.api.internal.file.collections.FileTreeAdapter.visit(FileTreeAdapter.java:96)
at org.gradle.api.internal.file.AbstractFileTree.getFiles(AbstractFileTree.java:37)
at build_465ftqg9bnx9fjui5v1nrftif.run(/path/to/project/build.gradle:40)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 32 more
Caused by: org.gradle.api.GradleException: Could not copy tar entry /path/to/jdk/archive/jdk-8u40-linux-x64.tar.gz!jdk1.8.0_40/README.html to '/path/to/project/build/tmp/expandedArchives/jdk-8u40-linux-x64.tar.gz_7rgta7iqynbzorxi3d85umfvr/jdk1.8.0_40/README.html'.
at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:79)
at org.gradle.api.internal.file.archive.TarFileTree$DetailsImpl.getFile(TarFileTree.java:121)
at org.gradle.api.internal.file.AbstractFileTree$1.visitFile(AbstractFileTree.java:39)
at org.gradle.api.internal.file.archive.TarFileTree.visitImpl(TarFileTree.java:91)
at org.gradle.api.internal.file.archive.TarFileTree.visit(TarFileTree.java:70)
... 36 more
Caused by: java.io.FileNotFoundException: /path/to/project/build/tmp/expandedArchives/jdk-8u40-linux-x64.tar.gz_7rgta7iqynbzorxi3d85umfvr/jdk1.8.0_40/README.html (Permission denied)
at org.gradle.api.internal.file.AbstractFileTreeElement.copyFile(AbstractFileTreeElement.java:91)
at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:74)
... 40 more

$ ls -l build/tmp/expandedArchives/jdk-8u40-linux-x64.tar.gz_7rgta7iqynbzorxi3d85umfvr/jdk1.8.0_40/README.html
rrr- 1 myuser myuser 159 Mar 20 16:05 build/tmp/expandedArchives/jdk-8u40-linux-x64.tar.gz_7rgta7iqynbzorxi3d85umfvr/jdk1.8.0_40/README.html

I notice that the file has a mode of 444. Could it just be that under the covers Gradle/Groovy/Java is trying to write to an existing read-only file without deleting it first? Not sure why it would be trying to untar it twice. For additional context, here is the relevant block of the build script up until the failing line:

configurations

{ jdk jce }

dependencies.jdk "com.oracle.java.jdk:jdk:${version}:[1]linux-x64@tar.gz"
dependencies.jce "com.oracle.java.jce:unlimited-jce-policy:${version[0]}@zip"

try

{ configurations.jdk.resolve() }

catch (org.gradle.api.artifacts.ResolveException e) {
println "We cannot build ${project.name} with version '${version}'. Try something like '8u40'"
System.exit(1)
}

println tarTree(configurations.jdk.singleFile).files
----------------------------------------------------------------------------------------
[1] linux-x64@tar.gz

Comment by Gradle Forums [ 24/Mar/15 ]

Does this happen on a clean build?

Comment by Gradle Forums [ 24/Mar/15 ]

Actually, yes. My thought is that something about that block of code expands the tarball twice. Perhaps tarTree does it once, and then files tries it again?

Comment by Adam Kaufman [ 25/Mar/15 ]

Upon closer inspection, this does not happen on a clean build. My confusion arose out of the fact that the build couldn't clean itself because the error was happening during the configuration phase. When I manually removed the build directory, I found that the error goes away for that first build from a "clean" state.

That said, I would still consider this a pretty big issue as it makes build scripts that hit it very brittle. Here is a very simple script to reproduce it:

repositories { flatDir { dirs projectDir }}
configurations { jdk }
dependencies.jdk "com.oracle.java.jdk:jdk:8u40:linux-x64@tar.gz"
configurations.jdk.resolve()
def secondTimeDeath = tarTree(configurations.jdk.singleFile).files
  1. Download the 8u40 version of Oracle's jdk to the directory containing build.gradle
  2. Execute gradle
    $ gradle
    :help
    
    Welcome to Gradle 2.3.
    
    To run a build, run gradle <task> ...
    
    To see a list of available tasks, run gradle tasks
    
    To see a list of command-line options, run gradle --help
    
    To see more detail about a task, run gradle help --task <task>
    
    BUILD SUCCESSFUL
    
    Total time: 4.006 secs
    
  3. Execute gradle again
    $ gradle
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/tmp/gradle-test-build/build.gradle' line: 5
    
    * What went wrong:
    A problem occurred evaluating root project 'gradle-test-build'.
    > Unable to expand TAR '/tmp/gradle-test-build/jdk-8u40-linux-x64.tar.gz'
        The tar might be corrupted or it is compressed in an unexpected way.
        By default the tar tree tries to guess the compression based on the file extension.
        If you need to specify the compression explicitly please refer to the DSL reference.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    BUILD FAILED
    
    Total time: 1.728 secs
    
  4. Delete the build directory and try it again, and see the exact same behavior.

This has been tested with Gradle 2.2.1 and 2.3.

Comment by Harris Bowron [ 14/Oct/16 ]

Any update?

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:44:24 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.