sxyazi / yazi

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

extracting `tar.gz` archive doesn't preserve permissions #1864

Closed xfzv closed 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.36.4

yazi --debug output

Yazi
    Version: 0.3.3 (c668723 2024-10-30)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.3 (c668723 2024-10-30)

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

Adapter
    Adapter.matches: Kgp

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

SSH
    shared.in_ssh_connection: false

WSL
    WSL: 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} \"$@\"", block: true, orphan: false, desc: "Neovim", for_: None, spread: true })
    block-create: Some(Opener { run: "${EDITOR} \"$@\"", block: true, orphan: false, desc: "Neovim", for_: None, spread: true })
    block-rename: Some(Opener { run: "${EDITOR} \"$@\"", block: true, orphan: false, desc: "Neovim", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : No such file or directory (os error 2)
    tmux build flags   : enable-sixel=Unknown
    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-38
    fzf              : 0.54.3
    fd               : 10.2.0
    rg               : 14.1.1
    chafa            : No such file or directory (os error 2)
    zoxide           : 0.9.6
    7z               : 17.05
    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.

Describe the bug

When extracting a .tar.gz archive, directories and files permissions from the archive aren't preserved. After extraction, directories all have 700 permissions and files all have 644 permissions.

This could be avoided by using tar -p, --preserve-permissions option.

Minimal reproducer

  1. Compress any directory with at least e.g an executable (755 permissions) and any other kind of file with 600 permissions to a tar.gz archive
  2. Hover the archive and extract it with <Enter>
  3. Go to the extracted directory
  4. All directories have 700 permissions instead of 755 ; all files have 644 permissions
  5. Delete the extracted directory and extract the archive again with tar -p, --preserve-permissions option: tar -pxvzf or with Ark
  6. Go to the extracted directory
  7. All permissions are identical to those inside the archive

Anything else?

No response

Validations

sxyazi commented 2 weeks ago

Yazi uses 7zip instead of tar to extract tar.gz files to avoid adding new dependencies. I did a quick search, and it seems like there's no switch to preserve this information during extraction, which likely means that 7zip doesn't support it. Let me know if I'm wrong!

xfzv commented 2 weeks ago

Indeed, 7zip cannot preserve permissions. Quoting Wikipedia 7z page - Limitations:

The 7z format does not store filesystem permissions (such as UNIX owner/group permissions or NTFS ACLs), and hence can be inappropriate for backup/archival purposes.

I guess this also applies when extracting tar.gz archives, hence the issue.

Yazi uses 7zip instead of tar to extract tar.gz files to avoid adding new dependencies.

tar is installed by default on pretty much any Linux distro and also on macOS. It seems that it's also available in recent Microsoft Windows versions so I guess it wouldn't hurt using it over 7zip for all tar archives?

What about using tar if available and 7zip as fallback if it's not?

sxyazi commented 2 weeks ago

My main concern about doing this is that they're not interchangeable alternatives; tar and 7zip don't behave the same way, which adds more uncertainty and confusion.

For example, when users report a problem with tar.gz files, we'd have to ask them every time which one they used. Or when users use Yazi on a new system, they might forget to install tar and fall back to 7zip, only to be surprised by the inconsistent behavior.

Plus, since I plan to eventually implement my own extraction tool to replace 7zip (along with the feature of "open archives as directories" listed in feature requests) and right now 7zip is just a temporary solution, I'm not too keen on spending too much time adding new features, especially if those features are just for something that will eventually be discarded.

xfzv commented 2 weeks ago

Plus, since I plan to eventually implement my own extraction tool to replace 7zip and right now 7zip is just a temporary solution, I'm not too keen on spending too much time adding new features, especially if those features are just for something that will eventually be discarded.

I didn't know about that upcoming extraction tool, I completely agree with you in this case. I assume it will handle permissions correctly.

Feel free to close this. In the meantime, I'll just extract manually with tar.

Thanks!

sxyazi commented 2 weeks ago

OK close for now. If I still don't have enough time to finish my own extraction tool this year, I'll reconsider the idea of using tar