Skip to content
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

Install-ChocolateyZipPackage - Unzip specific folder feature is broken after introducing 7zip #676

Closed
digitalcardboard opened this issue Mar 30, 2016 · 6 comments

Comments

@digitalcardboard
Copy link

Migrating issue # 406 from chocolatey-archive/chocolatey#406

In short, attempting to use the specificFolder parameter for Install-ChocolateyZipPackage (and ultimately Get-ChocolateyUnzip doesn't work. Regression issue after switching to 7za.

@ferventcoder
Copy link
Member

From original issue:

I'm updating a package that downloads an archive with x64 and Win32 subdirectories. I used to extract the entire thing and manually remove the unneeded components. But, I figured I would try the as-yet undocumented -specificFolder parameter of Install-ChocolateyZipPackage.

$name   = "bellavista"
$url    = "http://.../bellavista.zip"
$tools  = Split-Path $MyInvocation.MyCommand.Definition
$folder = if(Get-ProcessorBits 64) { "x64" } else { "Win32" }


Install-ChocolateyZipPackage -PackageName $name -Url $url -UnzipLocation $tools -SpecificFolder $folder

But, it didn't work. The first thing I saw was a goofy log message. Look at the "full path" in bold. It contains a non-path

"Extracting c:\users\foo\temp\chocolatey\bellavista\bellavistaInstall.zip\x64 to c:\Chocolatey\lib\bellavista.1.0\tools..."

And, digging in the source, I saw a bad 7za command line being constructed

7za x -o"c:\Chocolatey\lib\bellavista.1.0\tools" -y "c:\users\foo\temp\chocolatey\bellavista\bellavistaInstall.zip\x64"

From my reading of the command line reference, and hacking my helper function, the correct command line should be...

7za x "c:\users\foo\temp\chocolatey\bellavista\bellavistaInstall.zip -o"c:\Chocolatey\lib\bellavista.1.0\tools" "x64" -y

And, actually, with this fix, you could supply any glob pattern to 7za, not just a specific folder.

@alexjfisher
Copy link

I've just hit this too. In my case I wanted to extract a single directory and its contents from a zip. Changing the command from the broken current form...

7z e -aoa -bd --bb1 -o"c:\installdir" -y "C:\ProgramData\chocolatey\lib\my-package\tools\my.zip\some\path\in\zip"

to

7z e -aoa -bd --bb1 -o"c:\installdir" -y "C:\ProgramData\chocolatey\lib\my-package\tools\my.zip" "some\path\in\zip"

is maybe not quite right either. The files from some\path\in\zip are extracted, but not directly into c:\installdir, but instead into c:\installdir\some\path\in\zip

@ferventcoder
Copy link
Member

This is open for hacktoberfest, if you want to give it an attempt we'd be open to the contribution!

@DarwinJS
Copy link
Contributor

DarwinJS commented Oct 18, 2016

I can give this one a shot.

@ferventcoder - I need clarification on the behavior of whether to preserve the path in the zip package. @alexjfisher expressed uncertainty about this.

@DarwinJS
Copy link
Contributor

I can't tell under what circumstances this bit of code would be valid - tacking the specific folder directly onto the zip file name? What am I missing?

https://github.com/darwinjs/choco/blob/master/src/chocolatey.resources/helpers/functions/Get-ChocolateyUnzip.ps1#L91-L93

@DarwinJS
Copy link
Contributor

PR: #1023

@ferventcoder ferventcoder self-assigned this Nov 13, 2016
@ferventcoder ferventcoder modified the milestones: 0.10.4, 0.10.x Nov 13, 2016
ferventcoder pushed a commit that referenced this issue Mar 18, 2017
Previously, when attempting to unzip a subdirectory in a zipped
archive, the Chocolatey unzip functions were ignoring the `SpecificFolder`
parameter. This was caused by a change to use 7za.exe in August 2013 in commit
chocolatey-archive/chocolatey@2e83d2e.

That changed carried over into the newer codebase. More recently there was a
switch back to 7z.exe (full 7zip), so it is possible to unzip a subdirectory
in an archive again. Ensure that `SpecficFolder` is added to the 7zip options
when it is specified.
ferventcoder added a commit that referenced this issue Mar 18, 2017
* pr1023:
  (GH-676) Fix: Unzip specific folder feature is broken
ferventcoder added a commit that referenced this issue Mar 18, 2017
* stable:
  (GH-1184) Upgrade to 7zip 16.04
  (maint) remove unused 7za
  (maint) update why 32-bit 7z is required
  (GH-676) Fix: Unzip specific folder feature is broken
  (maint) Additional version environment variables
@ferventcoder ferventcoder changed the title Unzip specific folder feature is broken after introducing 7zip Install-ChocolateyZipPackage - Unzip specific folder feature is broken after introducing 7zip Feb 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants