[go: up one dir, main page]

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

Make the builtin extract and archive plugins handle *.tar formats better #1548

Closed
xfzv opened this issue Aug 24, 2024 · 10 comments · Fixed by #1583
Closed

Make the builtin extract and archive plugins handle *.tar formats better #1548

xfzv opened this issue Aug 24, 2024 · 10 comments · Fixed by #1583
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@xfzv
Copy link
xfzv commented Aug 24, 2024

What system are you running Yazi on?

Linux X11

What terminal are you running Yazi in?

kitty 0.35.2

yazi --debug output

Yazi
    Version: 0.3.1 (69c20d4 2024-08-24)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.1 (69c20d4 2024-08-24)

Emulator
    Emulator.via_env: ("xterm-kitty", "")
    Emulator.via_csi: Ok(Kitty)
    Emulator.detect : Kitty

Adapter
    Adapter.matches: Kitty

Desktop
    XDG_SESSION_TYPE: Some("tty")
    WAYLAND_DISPLAY : None
    DISPLAY         : Some(":0")

SSH
    shared.in_ssh_connection: false

WSL
    /proc/sys/fs/binfmt_misc/WSLInterop: false

Variables
    SHELL              : Some("/bin/zsh")
    EDITOR             : Some("nvim")
    VISUAL             : Some("nvim")
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None

Text Opener
    default: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block  : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : No such file or directory (os error 2)
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file             : 5.45
    ueberzugpp       : No such file or directory (os error 2)
    ffmpegthumbnailer: 2.2.2
    magick           : 7.1.1-25
    fzf              : 0.53.0
    fd               : 10.1.0
    rg               : 14.1.0
    chafa            : No such file or directory (os error 2)
    zoxide           : 0.9.4
    7z               : 16.02
    7zz              : No such file or directory (os error 2)
    jq               : 1.7.1


--------------------------------------------------
When reporting a bug, please also upload the `yazi.log` log file - only upload the most recent content by time.
You can find it in the "/home/xfzv/.local/state/yazi" directory.

Did you try the latest nightly build to see if the problem got fixed?

Yes, and I updated the debug information above (yazi --debug) to the nightly that I tried

Describe the bug

When extracting a tar.gz archive that contains a single file in it (no directory):

 archive.tar.gz
└──  binary

with default extract opener

{ run = 'ya pub extract --list "$@"', desc = "Extract here", for = "unix" },

Here's what happens:

  1. A directory named after the archive is created (archive)
  2. An archive.tar file is created inside archive directory
  3. After pressing Enter to extract the archive.tar file, another directory called archive is created
  4. Inside this archive directory, we finally have binary
  5. binary file permissions are not preserved (644, is actually 755)

The final file hierarchy structure:

 .
├──  archive                               # 1. first directory created
│   ├──  archive                           # 3. second directory created
│   │   └──  file                          # 4. binary
│   └──  archive.tar                       # 2. second archive created
├──  archive.tar.gz                        # 0. original archive

I'm aware this is the default 7z behavior (can reproduce with 7z x archive.tar.gz)
but this is really not convenient. With:

% tar -xvz archive.tar.gz

the binary is directly extracted to the current directory and permissions are preserved.

Any chance the extract feature could be more optimized? In this case, tar is definitely more suitable than 7z.

Minimal reproducer

  1. Download this tar.gz file
  2. Without any ~/.config/yazi directory, reproduce steps detailed in Describe the bug to extract the tar.gz archive and observe the final file structure
  3. Now try the following instead:
% tar -xvz viddy-v1.0.1-linux-x86_64.tar.gz
viddy

% ls -al viddy
-rwxr-xr-x 1 xfzv users 8.2M Aug 24 16:08 viddy

% lsd --tree
 .
├──  viddy
└──  viddy-v1.0.1-linux-x86_64.tar.gz
  • The binary is extracted to the current directory
  • Permissions (755) are preserved

Anything else?

No response

@xfzv xfzv added the bug Something isn't working label Aug 24, 2024
@sxyazi sxyazi added enhancement New feature or request and removed bug Something isn't working labels Aug 25, 2024
@sxyazi
Copy link
Owner
sxyazi commented Aug 25, 2024

Any chance the extract feature could be more optimized? In this case, tar is definitely more suitable than 7z.

I think this is possible, but I have a few questions/concerns:

  • What about Windows users?
  • Is tar available on all platforms (such as NixOS as well)? Do we need to add it to Yazi's dependency list?
  • Can tar provide an efficient archive preview feature? We need to make sure that the content users preview matches the content that's ultimately extracted. 7zip only previews the outer structure, so if we use 7zip to preview tar extractions, it might confuse users.
  • What if the user has only installed tar or 7zip (considering both extraction and preview)?

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Aug 25, 2024
@xfzv
Copy link
Author
xfzv commented Aug 25, 2024
* What about Windows users?

After a quick research, it doesn't seem that tar is natively available for MS Windows. Found Tar for Windows but it's completely out-of-date (2003) so it's probably not relevant. Correct me if I'm wrong, maybe a maintained port exists.

Edit: tar is actually available out-of-the-box on MS Windows, see #1548 (comment)

* Is tar available on all platforms (such as NixOS as well)? Do we need to add it to Yazi's dependency list?

It seems that it's available as gnutar for NixOS and with brew too.

* Can tar provide an efficient archive preview feature? We need to make sure that the content users preview matches the content that's ultimately extracted. 7zip only previews the outer structure, so if we use 7zip to preview tar extractions, it might confuse users.

Using -t, --list:

man 1 tar

-t, --list
List the contents of an archive. Arguments are optional. When given, they specify the names of the members to list.

Using the provided tar.gz example:

% tar -tf viddy-v1.0.1-linux-x86_64.tar.gz
viddy

Note that unlike 7z, it only works for tar archives:

% tar -tf test.zip
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
  • What if the user has only installed tar or 7zip (considering both extraction and preview)?

Considering both tools can preview/extract, just use the one installed I guess? Since tar doesn't seem to be available on MS Windows (again, I might be wrong), 7z would be the only option for Windows users.

Edit: tar is actually available out-of-the-box on MS Windows, see #1548 (comment)

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Aug 25, 2024
@veltza
Copy link
veltza commented Aug 26, 2024

Windows 10 and 11 come with tar.

Links

@xfzv
Copy link
Author
xfzv commented Aug 26, 2024

Windows 10 and 11 come with tar.

Links

* [The Windows Process Journey — tar.exe (BSD tar Archive Tool)](https://medium.com/@boutnaru/the-windows-process-journey-tar-exe-bsd-tar-archive-tool-d307a4412c46)

* [How to extract .tar.gz files on Windows 11](https://pureinfotech.com/extract-tar-gz-files-windows-11/)

Thanks for the info, I didn't know that. I've just tried on a Windows 10 VM, -t, --list seems to work just fine:

% C:\Users\User\Downloads> tar -tf viddy-v1.0.1-linux-x86_64.tar.gz
viddy

@sxyazi
Copy link
Owner
sxyazi commented Aug 26, 2024

Thanks for the info! I think it's worth a try.

Is anyone interested in implementing it? If it's simple enough and doesn't add too much maintenance overhead (let's say <100 lines), I'd be open to accepting a PR.

The code for the extract plugin is here: https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/plugins/extract.lua

@sxyazi sxyazi added the good first issue Good for newcomers label Aug 26, 2024
@sxyazi sxyazi changed the title ya pub extract - 7z creates useless complex file structure Make the builtin extract and archive plugins handle *.tar formats better Aug 26, 2024
@DirkFi
Copy link
Contributor
DirkFi commented Aug 28, 2024

Hi, @xfzv .
Can you tell a bit more about steps to reproduce? I'm using Arch Linux and have deleted the ~/.config/yazi to use the default extract opener. But heres what happened: I only gets a dir called viddy-v1.0.1-linux-x86_64 with a file viddy-v1.0.1-linux-x86_64.tar in it. And the state in the right corner shows the task is processing 99%.
Check out here: reproduce preview.

Update: After restarting my computer, the 99% disappeared, but the dir still looks the same.

@xfzv
Copy link
Author
xfzv commented Aug 28, 2024

@DirkFi I've just tried on my Arch Linux install and it behaves as I mentioned in OP, the extract task isn't stuck and I eventually have the viddy binary.

And the state in the right corner shows the task is processing 99%.

If you manage to get the task stuck at 99% again, open the task manager and press Enter to see more details about it.

I assume you do have tar installed considering it's in the base group? Edit: Sorry, I meant p7zip

Can you try with another tarball maybe?

Which version of yazi are you using? As far as I'm concerned:

% yazi -V
Yazi 0.3.2 (ddb8ce5 2024-08-28)

Anything in ~/.local/state/yazi/yazi.log?

@DirkFi
Copy link
Contributor
DirkFi commented Aug 28, 2024

@xfzv

I did not see any useful info in log file. My version is 0.3.1 and i also tried to install from the source code which was just now updated to 0.3.2 but still got similar results.

And, yes, I have p7zip installed and can run 7z command. Maybe I need to try another tarball.

Sorry about the misunderstanding, seems that I misunderstands your point. The image I shared with you actually reproduced the problem but I did not notice that and thought it was not the issue. Right now I understand that the issue is for tar.gz file it needs to unzip twice to get the original file and create some redundant dirs.

BTW, how to open the task manager inside Yazi?

@xfzv
Copy link
Author
xfzv commented Aug 29, 2024

BTW, how to open the task manager inside Yazi?

With w:

https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/keymap.toml#L146-L147

@DirkFi
Copy link
Contributor
DirkFi commented Sep 1, 2024

Fix in PR1583.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
4 participants