Question

I need to download a tar.gz file, and replace a directory in it with the contents of another tar.gz file. So far, I've tried the following gems, and found them lacking

  • archive-tar2: it lost the penultimate path separator ("/") so couldn't actually extract
  • archive-tarsimple: simply didn't extract the compressed tarball, and returned no error msg
  • minitar: ran into a bug where it failed for filepaths longer than 100 characters
  • archive-tar-minitar - fails the same as its parent Errno::ENAMETOOLONG / File name too long
  • libarchive: bundle install failed the gcc compile (even after successful brew install libarchive)

I'm starting to lose faith. Is there a good, up to date, well maintained tar archive gem that just works? I'd prefer one that doesn't call out to the command line, since I'd like to eliminate the possibility of commandline injection attacks. But at this point I'll take anything that avoids manually calling out to a shell.

Was it helpful?

Solution 2

I ended up giving up with using a gem to manipulate the tar archives, and just doing it by shelling out to the commandline.

`cd #{container} && tar xvfz sdk.tar.gz`    
`cd #{container} && tar xvfz Wizard.tar.gz`

    #update the framework packaged with the wizard
    FileUtils.rm_rf(container + "/Wizard.app/Contents/Resources/SDK.bundle")
    FileUtils.rm_rf(container + "/Wizard.app/Contents/Resources/SDK.framework")
    FileUtils.mv(container +  "/resources/SDK.bundle", container + "/Wizard.app/Contents/Resources/")
    FileUtils.mv(container +  "/resources/SDK.framework", container + "/Wizard.app/Contents/Resources/")

    config_plist =  render_to_string({
             file: 'site/_wizard_config',
             layout: false,
             locals: { app_id: @version.app.id },
             formats: 'xml'
            })  

File.open(container + "/Wizard.app/Contents/Resources/Configuration.plist", 'w') { |file| file.write( config_plist ) } 

`cd #{container} && rm Wizard.tar.gz`    
`cd #{container} && tar -cvf Wizard.tar 'Wizard.app'`
`cd #{container} && gzip Wizard.tar`

All these backticks make me feel like I'm writing Perl again.

OTHER TIPS

You can also check out archive-tar-minitar, it is partially based on minitar that you already tested out, and it doesn't seem that it emmits calls to the command line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top