sxyazi / yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.
https://yazi-rs.github.io
MIT License
14.45k stars 330 forks source link

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

Open xfzv opened 2 weeks ago

xfzv commented 2 weeks ago

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

https://github.com/sxyazi/yazi/blob/69c20d4dd3df49b22d80b11d63b35e8a914475bb/yazi-config/preset/yazi.toml#L49

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

Anything else?

No response

sxyazi commented 2 weeks ago

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:

xfzv commented 2 weeks ago
* 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 https://github.com/sxyazi/yazi/issues/1548#issuecomment-2309999382

* 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 https://github.com/sxyazi/yazi/issues/1548#issuecomment-2309999382

veltza commented 2 weeks ago

Windows 10 and 11 come with tar.

Links

xfzv commented 2 weeks ago

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 commented 2 weeks ago

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

DirkFi commented 2 weeks ago

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 commented 2 weeks ago

@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 commented 2 weeks ago

@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 commented 2 weeks ago

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 commented 1 week ago

Fix in PR1583.