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

Feature: exclude leading directory when extracting #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Svintooo
Copy link

This pull request aims to add a new feature to unzipper. If an archive to be extracted only contains one single directory in its root, unzipper can now choose to only extract the content of this single directory and not include the directory itself in the extraction.

The feature is controlled by a checkbox added to the HTML.

I got this idea when trying to deploy WordPress on a new website. After extracting the zip file downloaded from wordpress.org I got a wordpress/ directory in my website root instead of the WordPress files and folders, which is not what I intended.

I tried many solutions to this problem and finally decided on the following:

  • extract archive to a newly created empty temporary directory (tempdir) and move all files and folder from the tempdir to the real destination.
  • if the tempdir only contains one single directory, move the content of said directory instead of the tempdir content.

It may seem like a better idea to extract each file from an archive directly to the destination folder, thereby not needing a tmpdir. But the only way I found to do this was by iterating over the archive files and using copy("zip://archive.zip#path/to/file.txt"). And this solution has serious performance problems with larger archives. Archives that can normally be extracted will instead be cancelled by the PHP max_execution_time.

The implemented solution is also easy to incorporate in any future additions to supported archive formats.

Feedback is welcome.

Hugo Ankarloo added 5 commits August 12, 2020 21:14
Add function createTmpDir in Unzipper.
Function creates a temporary directory.

This is a part of a bigger update to add the feature of excluding a
leading directory in an archive when extracting.
Add function moveFilesExcludingLeadingDir in Unzipper.
Function moves all files and folders from one directory to another, but
if the source folder only contains a singe directory, only the content
of tha single directory will be moved, not the directory itself.

This is a part of a bigger update to add the feature of excluding a
leading directory in an archive when extracting.
The function extractZipArchive() in Unzipper is the only function that
doesn't have a proper description of its parameters.

This commit aims to correct this.
Fully implements the feature in Unzipper of excluding a leading
directory in an archive when extracting.

The implementation is made to be easily incorporated with any archive
format.
Adds a checkbox to the html for controlling the usage of the new feature
of excluding a leading directory in an archive when extracting.
@Svintooo
Copy link
Author

Should I maybe wait a little more before receiving a response on this? Or is the project dead?

@Svintooo
Copy link
Author

Svintooo commented Oct 1, 2020

Any ideas or comments on this?
I really like this project, and I think it would be awesome if this feature was added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant