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

unzip/extract options can't handle .7z files for some reason #98

Open
cobalt2727 opened this issue Apr 12, 2023 · 10 comments · Fixed by #141
Open

unzip/extract options can't handle .7z files for some reason #98

cobalt2727 opened this issue Apr 12, 2023 · 10 comments · Fixed by #141
Labels
bug Something isn't working help wanted Extra attention is needed sponsor needed Sponsorship required to prioritize

Comments

@cobalt2727
Copy link

cobalt@ideapad-flex-5:~/Desktop$ lastversion --assets unzip https://github.com/Venomalia/UniversalDynamicInput
DynamicInputTextures.7z: 120792.0KB [00:10, 11648.55KB/s]                                     
Traceback (most recent call last):
  File "/usr/lib/python3.10/tarfile.py", line 1705, in gzopen
    t = cls.taropen(name, mode, fileobj, **kwargs)
  File "/usr/lib/python3.10/tarfile.py", line 1682, in taropen
    return cls(name, mode, fileobj, **kwargs)
  File "/usr/lib/python3.10/tarfile.py", line 1542, in __init__
    self.firstmember = self.next()
  File "/usr/lib/python3.10/tarfile.py", line 2377, in next
    raise e
  File "/usr/lib/python3.10/tarfile.py", line 2350, in next
    tarinfo = self.tarinfo.fromtarfile(self)
  File "/usr/lib/python3.10/tarfile.py", line 1122, in fromtarfile
    buf = tarfile.fileobj.read(BLOCKSIZE)
  File "/usr/lib/python3.10/gzip.py", line 301, in read
    return self._buffer.read(size)
  File "/usr/lib/python3.10/_compression.py", line 68, in readinto
    data = self.read(len(byte_view))
  File "/usr/lib/python3.10/gzip.py", line 488, in read
    if not self._read_gzip_header():
  File "/usr/lib/python3.10/gzip.py", line 436, in _read_gzip_header
    raise BadGzipFile('Not a gzipped file (%r)' % magic)
gzip.BadGzipFile: Not a gzipped file (b'7z')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/cobalt/.local/bin/lastversion", line 8, in <module>
    sys.exit(main())
  File "/home/cobalt/.local/lib/python3.10/site-packages/lastversion/lastversion.py", line 590, in main
    extract_file(url)
  File "/home/cobalt/.local/lib/python3.10/site-packages/lastversion/utils.py", line 283, in extract_file
    with tarfile.open(fileobj=buffer, mode=mode) as tar_file:
  File "/usr/lib/python3.10/tarfile.py", line 1652, in open
    return func(name, filemode, fileobj, **kwargs)
  File "/usr/lib/python3.10/tarfile.py", line 1709, in gzopen
    raise ReadError("not a gzip file") from e
tarfile.ReadError: not a gzip file
cobalt@ideapad-flex-5:~/Desktop$ lastversion --assets extract https://github.com/Venomalia/UniversalDynamicInput
DynamicInputTextures.7z: 120792.0KB [00:09, 12598.66KB/s]                                     
Traceback (most recent call last):
  File "/usr/lib/python3.10/tarfile.py", line 1705, in gzopen
    t = cls.taropen(name, mode, fileobj, **kwargs)
  File "/usr/lib/python3.10/tarfile.py", line 1682, in taropen
    return cls(name, mode, fileobj, **kwargs)
  File "/usr/lib/python3.10/tarfile.py", line 1542, in __init__
    self.firstmember = self.next()
  File "/usr/lib/python3.10/tarfile.py", line 2377, in next
    raise e
  File "/usr/lib/python3.10/tarfile.py", line 2350, in next
    tarinfo = self.tarinfo.fromtarfile(self)
  File "/usr/lib/python3.10/tarfile.py", line 1122, in fromtarfile
    buf = tarfile.fileobj.read(BLOCKSIZE)
  File "/usr/lib/python3.10/gzip.py", line 301, in read
    return self._buffer.read(size)
  File "/usr/lib/python3.10/_compression.py", line 68, in readinto
    data = self.read(len(byte_view))
  File "/usr/lib/python3.10/gzip.py", line 488, in read
    if not self._read_gzip_header():
  File "/usr/lib/python3.10/gzip.py", line 436, in _read_gzip_header
    raise BadGzipFile('Not a gzipped file (%r)' % magic)
gzip.BadGzipFile: Not a gzipped file (b'7z')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/cobalt/.local/bin/lastversion", line 8, in <module>
    sys.exit(main())
  File "/home/cobalt/.local/lib/python3.10/site-packages/lastversion/lastversion.py", line 590, in main
    extract_file(url)
  File "/home/cobalt/.local/lib/python3.10/site-packages/lastversion/utils.py", line 283, in extract_file
    with tarfile.open(fileobj=buffer, mode=mode) as tar_file:
  File "/usr/lib/python3.10/tarfile.py", line 1652, in open
    return func(name, filemode, fileobj, **kwargs)
  File "/usr/lib/python3.10/tarfile.py", line 1709, in gzopen
    raise ReadError("not a gzip file") from e
tarfile.ReadError: not a gzip file
@dvershinin
Copy link
Owner

This would require the py7zr library, which I'm hesitant to add because it's missing RPM packages in major distros..

@cobalt2727
Copy link
Author

Would just throwing an error message informing the user what's missing if it's not available be an acceptable workaround?

@vogler
Copy link

vogler commented Jan 8, 2024

I have the same problem also with .zip files:

$ brew install pipx
$ pipx install lastversion
$ lastversion --assets download SamusAranX/MinimalMIDIPlayer
Downloaded MinimalMIDIPlayer-v1.13.zip: : 7368.0KB [00:00, 10763.89KB/s]
$ unzip MinimalMIDIPlayer-v1.13.zip
Archive:  MinimalMIDIPlayer-v1.13.zip
   creating: MinimalMIDIPlayer.app/
...
$ rm -rf MinimalMIDIPlayer*

$ lastversion --assets unzip SamusAranX/MinimalMIDIPlayer
MinimalMIDIPlayer-v1.13.zip: 7368.0KB [00:00, 10887.83KB/s]
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 1876, in gzopen
    t = cls.taropen(name, mode, fileobj, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 1853, in taropen
    return cls(name, mode, fileobj, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 1711, in __init__
    self.firstmember = self.next()
                       ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 2635, in next
    raise e
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 2608, in next
    tarinfo = self.tarinfo.fromtarfile(self)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 1293, in fromtarfile
    buf = tarfile.fileobj.read(BLOCKSIZE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/gzip.py", line 324, in read
    return self._buffer.read(size)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/_compression.py", line 68, in readinto
    data = self.read(len(byte_view))
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/gzip.py", line 527, in read
    if not self._read_gzip_header():
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/gzip.py", line 496, in _read_gzip_header
    last_mtime = _read_gzip_header(self._fp)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/gzip.py", line 456, in _read_gzip_header
    raise BadGzipFile('Not a gzipped file (%r)' % magic)
gzip.BadGzipFile: Not a gzipped file (b'PK')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/voglerr/.local/bin/lastversion", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/voglerr/Library/Application Support/pipx/venvs/lastversion/lib/python3.12/site-packages/lastversion/lastversion.py", line 890, in main
    extract_file(url)
  File "/Users/voglerr/Library/Application Support/pipx/venvs/lastversion/lib/python3.12/site-packages/lastversion/utils.py", line 415, in extract_file
    extract_tar(buffer, mode)
  File "/Users/voglerr/Library/Application Support/pipx/venvs/lastversion/lib/python3.12/site-packages/lastversion/utils.py", line 358, in extract_tar
    with tarfile.open(fileobj=buffer, mode=mode) as tar_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 1821, in open
    return func(name, filemode, fileobj, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tarfile.py", line 1880, in gzopen
    raise ReadError("not a gzip file") from e
tarfile.ReadError: not a gzip file

@vogler
Copy link

vogler commented Jan 8, 2024

Also, what's the difference between extract and unzip?

vogler added a commit to vogler/dotfiles that referenced this issue Jan 8, 2024
Reported issues:
- add Homebrew package: SamusAranX/MinimalMIDIPlayer#14
- `lastversion unzip` did not work: dvershinin/lastversion#98 (comment)
@vogler
Copy link

vogler commented Jan 26, 2024

Still does not work for me with #141:

$ pipx uninstall lastversion
uninstalled lastversion! ✨ 🌟 ✨
$ pipx install git+https://github.com/dvershinin/lastversion
  installed package lastversion 3.4.6, installed using Python 3.12.1
  These apps are now globally available
    - lastversion
done! ✨ 🌟 ✨
$ lastversion --assets unzip SamusAranX/MinimalMIDIPlayer
MinimalMIDIPlayer-v1.13.zip: 7368.0KB [00:00, 44333.42KB/s]
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/lastversion/utils.py", line 378, in extract_tar_and_zip
    with tarfile.open(fileobj=buffer, mode="r") as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tarfile.py", line 1811, in open
    raise ReadError(f"file could not be opened successfully:\n{error_msgs_summary}")
tarfile.ReadError: file could not be opened successfully:
- method gz: ReadError('not a gzip file')
- method bz2: ReadError('not a bzip2 file')
- method xz: ReadError('not an lzma file')
- method tar: ReadError('bad checksum')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/bin/lastversion", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/lastversion/lastversion.py", line 889, in main
    extract_file(url)
  File "/opt/homebrew/lib/python3.11/site-packages/lastversion/utils.py", line 437, in extract_file
    extract_tar_and_zip(buffer, to_dir=to_dir)
  File "/opt/homebrew/lib/python3.11/site-packages/lastversion/utils.py", line 384, in extract_tar_and_zip
    extract_archive(file)
  File "/opt/homebrew/lib/python3.11/site-packages/lastversion/utils.py", line 373, in extract_archive
    archive_file.extract(item, to_dir)
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zipfile.py", line 1664, in extract
    return self._extract_member(member, path, pwd)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/zipfile.py", line 1735, in _extract_member
    open(targetpath, "wb") as target:
    ^^^^^^^^^^^^^^^^^^^^^^
NotADirectoryError: [Errno 20] Not a directory: 'Contents/CodeResources'

@dvershinin dvershinin reopened this Jan 26, 2024
@dvershinin
Copy link
Owner

@vogler unzip is just an alias to extract. While not solved the issue with zip files stripping, I realize, OS X bundles should not be stripped. You can check with latest master again.

@vogler
Copy link

vogler commented Jan 26, 2024

Thanks, works now 👍

$ lastversion --assets unzip SamusAranX/MinimalMIDIPlayer
MinimalMIDIPlayer-v1.13.zip: 7368.0KB [00:00, 30144.44KB/s]
$ ll | grep Mini
drwxr-xr-x     3 voglerr staff   96 Jan 26 20:46 MinimalMIDIPlayer.app

@vogler
Copy link

vogler commented Jan 26, 2024

Are you making a release for this? If not, I'll just keep pipx install git+https://github.com/dvershinin/lastversion in my dotfiles for now.

@dvershinin
Copy link
Owner

@vogler Fixed in lastversion v3.5.0

@vogler
Copy link

vogler commented Jan 29, 2024

lastversion --assets unzip still doesn't work for macOS apps:
image

$ open MinimalMIDIPlayer.app
The application cannot be opened for an unexpected reason, error=Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x6000020c4570 {Error Domain=NSPOSIXErrorDomain Code=111 "Unknown error: 111" UserInfo={NSLocalizedDescription=Launchd job spawn failed}}}

Whereas there's no problem with download + unzip:

$ lastversion --assets download SamusAranX/MinimalMIDIPlayer
Downloaded MinimalMIDIPlayer-v1.13.zip: : 7368.0KB [00:00, 30527.86KB/s]

$ unzip MinimalMIDIPlayer-v1.13.zip
Archive:  MinimalMIDIPlayer-v1.13.zip
   creating: MinimalMIDIPlayer.app/
   creating: MinimalMIDIPlayer.app/Contents/
  inflating: MinimalMIDIPlayer.app/Contents/CodeResources
...
  MinimalMIDIPlayer.app/Contents/Frameworks/Sparkle.framework/Versions/Current -> A

$ open MinimalMIDIPlayer.app

The contents and permissions seem to be the same.

@dvershinin dvershinin reopened this Jan 30, 2024
@dvershinin dvershinin added bug Something isn't working help wanted Extra attention is needed sponsor needed Sponsorship required to prioritize labels Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed sponsor needed Sponsorship required to prioritize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants