thoemmi / 7Zip4Powershell

Powershell module for creating and extracting 7-Zip archives
GNU Lesser General Public License v2.1
398 stars 64 forks source link

Invalid archive `tar` #47

Open m93a opened 6 years ago

m93a commented 6 years ago

I'm using a PowerShell script to download and extract an archive. It's a .tar.bz2 and when I use Expand-7Zip for the first time, it only decompresses it, leaving a .tar file. But when I try to extract it, I get an error message saying it's an invalid package. That is weird because when I double-click on it, 7Zip GUI opens it normally 🤔. This is the whole script:

$ErrorActionPreference = "Stop"

function Expand-Tar($TarFile, $Destination) {

    if (-not (Get-Command Expand-7Zip -ErrorAction Ignore)) {
        Install-Package -Scope CurrentUser -Force 7Zip4PowerShell > $null
    }

    Expand-7Zip $TarFile $Destination
}

Write-Output "Downloading libraries..."

Invoke-WebRequest http://fna.flibitijibibo.com/archive/fnalibs.tar.bz2 -OutFile libs.tar.bz2
New-Item -ItemType directory -Name libs

Write-Output "Exctracting..."

Expand-Tar -TarFile libs.tar.bz2
Expand-Tar -TarFile libs.tar -Destination libs
Remove-Item libs.tar.bz2
Write-Output "Libs have been extracted to the libs/ directory. Copy files for your platform to the debug folder."

And this is the error:

Expand-7Zip : Invalid archive: open/read error! Is it encrypted and a wrong password was provided?
If your archive is an exotic one, it is possible that SevenZipSharp has no signature for its format and thus decided it is TAR by mistake.
At C:\Users\Michal Grňo\Documents\GitHub\mff-totem\getlibs.ps1:14 char:5
+     Expand-7Zip $TarFile $Destination
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (SevenZip4PowerS...ip+ExpandWorker:ExpandWorker) [Expand-7Zip], SevenZipArchiveException
    + FullyQualifiedErrorId : err01,SevenZip4PowerShell.Expand7Zip

As I said, extracting with GUI (v18.01) works fine...

james-d-elliott commented 4 years ago

I'm going to guess that it's the same filename as you see in the GUI except it ends in .tar? For example if you have file.tar.bz2 and inside that is document.txt, it comes out with document.txt.tar? If so your problem is similar to what I had with the openSUSE images.

What's happening is it's extracting the whole file, correctly, but adding tar to the extension for some reason. For example with http://download.opensuse.org/tumbleweed/appliances/openSUSE-MicroOS.x86_64-Kubic-kubeadm-MS-HyperV.vhdx.xz it names the file openSUSE-MicroOS.x86_64-Kubic-kubeadm-MS-HyperV.vhdx.tar but it should be openSUSE-MicroOS.x86_64-Kubic-kubeadm-MS-HyperV.vhdx.