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

feat: make the builtin extract plugin support compressed tarballs (*.tar.gz, *.tar.bz2, etc.) #1583

Merged
merged 6 commits into from
Sep 14, 2024

Conversation

DirkFi
Copy link
Contributor

@DirkFi DirkFi commented Sep 1, 2024

Closes #1548.

Description:

  • Add spawn_tar function and is_tar_compatible function
    • Create spawn_tar function to run command with tar -xaf to unzip file to tmp directory
    • Create is_tar_compatible function to tell if a zip file can be extracted with tar command
  • Add os.excute() line to make sure the tmp dir exists because tar command will not automatically create that dir, unlike 7z
  • Refactor the logic in the try() function to if the zip file can be unzipped with tar and no password required, use tar, otherwise use 7z instead

yazi-plugin/preset/plugins/archive.lua Outdated Show resolved Hide resolved
@DirkFi
Copy link
Contributor Author

DirkFi commented Sep 1, 2024

BTW, Do I need to combine the other commits or I can have separate commit in the same PR?

@veltza
Copy link

veltza commented Sep 1, 2024

There are more suffixes than ".tar", ".tgz", ".tar.gz", ".tar.bz2". And short forms should be supported as well.

@sxyazi
Copy link
Owner

sxyazi commented Sep 1, 2024

BTW, Do I need to combine the other commits or I can have separate commit in the same PR?

You can make multiple commits in this PR, and I'll squash and merge them into one.

@DirkFi
Copy link
Contributor Author

DirkFi commented Sep 1, 2024

There are more suffixes than ".tar", ".tgz", ".tar.gz", ".tar.bz2". And short forms should be supported as well.

Thanks! Definitely will go test and add this!

@DirkFi DirkFi requested a review from sxyazi September 1, 2024 22:13
@veltza
Copy link

veltza commented Sep 3, 2024

Is this going to fix the preview issues with tar files as well?

@DirkFi
Copy link
Contributor Author

DirkFi commented Sep 3, 2024

Is this going to fix the preview issues with tar files as well?

What issue specifically? If you're talking about preview does not show the final file of the tar.gz or other type of tar, no. It is not fixed in this PR.

@veltza
Copy link

veltza commented Sep 4, 2024

What issue specifically? If you're talking about preview does not show the final file of the tar.gz or other type of tar, no. It is not fixed in this PR.

That's what I was referring to. And I hoped that this would have killed two birds with one stone. But that's okay because I think it will be easy to fix after this PR.

 * Add spawn_tar function and tar_compatible function
  - Create spawn_tar function to run command with tar -xvf to unzip file to tmp
    file
 * Add os.excute() line to make sure the tmp dir exists because tar
   command will not automatically create that dir
 * Refactor the logic in the try function to if the zip file can be
   unzipped with tar and no password required, use tar, otherwise use
   7z
 * Create a new method "create" in fs.rs
 * Delete archive:is_encrypted in tar use
 * Convert the tar command from -xvf to -xaf
 * Add more File suffix that can be unzipped with tar
@sxyazi
Copy link
Owner

sxyazi commented Sep 14, 2024

I finally had time to test it today (sorry for the delay), I found that we can directly reuse 7zip to extract tar files, which eliminates the need for an additional dependency. Plus, 7zip is more cross-platform friendly (some older Windows systems can also use it)

Copy link
Owner

@sxyazi sxyazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sxyazi sxyazi changed the title Make the plugins able to use tar to unzip when needed feat: make the builtin extract plugin support compressed tarballs (*.tar.gz, *.tar.bz2, etc.) Sep 14, 2024
@sxyazi sxyazi merged commit 276f691 into sxyazi:main Sep 14, 2024
6 checks passed
@xfzv
Copy link

xfzv commented Sep 14, 2024

Awesome! Thank you both.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the builtin extract and archive plugins handle *.tar formats better
4 participants