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

[Regression][develop] Expand-ZipArchive cannot remove already removed archive #3473

Closed
Ash258 opened this issue May 17, 2019 · 3 comments
Closed

Comments

@Ash258
Copy link
Contributor

Ash258 commented May 17, 2019

A

Cause:
https://github.com/lukesampson/scoop/blob/f5fdc275ca27166c7fd862932f4ad2e124708f20/lib/decompress.ps1#L238-L246

If there is extract_dir property set, archive is deleted twice.

first in gci -exclude $ExtractDir | Remove
then in if ($Removal)

/cc @niheaven

@Ash258 Ash258 changed the title [Regression][develop] Expand-ZipArchive cannot remove archive [Regression][develop] Expand-ZipArchive cannot remove already removed archive May 17, 2019
@niheaven
Copy link
Member

niheaven commented May 17, 2019

Yes, fixed in #3472 😂

Expand-ZipArchive and Expand-MsiArchive are fixed.

@Ash258
Copy link
Contributor Author

Ash258 commented May 17, 2019

Why so complicated? You could just add gci . -Exlude $ExtractDir, $Path or not?

@niheaven
Copy link
Member

I try to do so in #3470, and in fact, gci . -Exclude $ExtractDir, (SplitPath $Path -Leaf) works.

But this failed when extract_dir has sub-dir, i.e. PFiles\Calibre2 for calibre-normal. -Exclude will not recognize sub dir, and Get-ChildItem or Remove-Item will remove PFiles.

Then I tried (Get-ChildItem . -Recurse).FullName -notmath '[Regex]::Escape($DestinationPath\$ExtractDir)|[Regex]::Escape($Path)' | Remove-Item and this will protect ExtractDir and Path, but it will remove other files if manifest has multi-url and multi-extract_dir (e.g. pkg-config).

So finanlly I choose to use _tmp dir for Expand-ZipArchive and Expand-MsiArchive.

For PowerShell Core, Expand-Archive has param -PassThru that return extracted files, and this will be helpful for filtering files, but PS 5 hasn't any output. Maybe ZipArchive.GetEntry and ZipFileExtensions.ExtractToFile will be helpful for rewriting Expand-Archive function with ExtractDir.

r15ch13 pushed a commit that referenced this issue May 17, 2019
For some `extract_dir` in .zip that has sub-dir, the former one would remove parent dir and get error (flac, flac-1.3.2-win\win64), now use temp dir instead. And also fix .msi, in case of some installer that don't have `SourceDir`.

`Expand-DarkArchive` will be used in wix extraction, so it doesn't need `-ExtractDir`.

`Expand-7zipArchive` and `Expand-InnoArchive` works well.

Tested:

- calibre-normal (msi, PFiles\Calibre2)
- flac (zip, flac-1.3.2-win\win64)
- pkg-config (zip, multiple url and extract_dir)

BTW, `Expand-Archive` has `-PassThru` param in PowerShell 6+, and it will be more convinient to support `-ExtractDir` with it. I'll check function's source code and plan to rewrite `Expand-ZipArchive`.

Fix #3473, ref #3473 (comment)
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

No branches or pull requests

2 participants