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

Distributable zip files cannot be renamed without affecting extraction directory name #5

Closed
raamdev opened this issue Jun 12, 2015 · 3 comments
Assignees
Labels

Comments

@raamdev
Copy link
Contributor

raamdev commented Jun 12, 2015

At present, the distributable zip files generated by the build script cannot be renamed to include a version number (e.g., I can't rename zencache.zip to zencache-v150605.zip) because doing so would result in the plugin getting extracted to /zencache-v150605/ instead of /zencache/ in the wp-content/plugins/ directory.

What's happening is that Phing is generating a zip file with file paths that do not include a leading directory, i.e., Phing is zipping the contents of /zencache/ instead of zipping up the zencache directory itself.

We need to modify the build script so that what gets zipped includes the original plugin directory name, so that we can rename the zip files whatever we want without that affecting the name of the directory that the plugin gets extracted to when installed via the WordPress Dashboard.

For more background on this, read on...


When I manually zip up a directory called zencache/, the directory name (at the time the zip file was created) get added to the path of each file in the zip:

     1085  03-14-15 20:29   zencache/uninstall.inc.php
      513  03-14-15 20:29   zencache/uninstall.php
    92441  03-14-15 20:29   zencache/zencache.inc.php
      667  03-14-15 20:49   zencache/zencache.php

Phing is zipping the contents of the directory, so we end up with zip file that contains file paths without a leading directory (notice there's no leading directory name):

        0  06-05-15 14:08   src/vendor/websharks/wp-php-rv/src/includes/
      515  05-11-15 11:20   src/vendor/websharks/wp-php-rv/src/includes/check.php
        0  06-05-15 14:08   src/vendor/websharks/wp-php-rv/src/includes/functions/
    10014  05-11-15 11:20   src/vendor/websharks/wp-php-rv/src/includes/functions/wp.php
      317  06-05-15 14:08   uninstall.php
      409  06-05-15 14:08   zencache.php

When there's no leading directory name, the zip file gets extracted into a directory that matches the name of the zip file. That means if we rename the Phing-generated zip file to zencache-v150606.zip, it will get extracted to zencache-v150605/.

If the zip file was built with a leading directory name (i.e., you zip up a directory vs zipping up a bunch of files), then it doesn't matter what you name the zip file--it will always be extracted to the original name of the directory that was zipped up.

Mystery solved!

@raamdev
Copy link
Contributor Author

raamdev commented Jun 19, 2015

@jaswsinc This was a lot easier to solve than I expected. The Phing ZipTask already has a prefix attribute that allows you to specify the path that should prefix each filename/path. I updated the ZipTask to use ${project_slug}/ as the prefix:

<zip basedir="${project.basedir}" prefix="${project_slug}/" includeemptydirs="false" destfile="${project.basedir}/.~build/${project_slug}.zip">

I noticed there's also an includeemptydirs attribute to prevent empty directories from being included with the zip, so I added that in there (having that enabled would prevented #6 from appearing).

Now when I run the build script, the zip file includes the prefix, which allows us to rename the ZIP file to anything we want without changing the directory name the zip file gets extracted to:

$ unzip -l .~build/zencache/.~build/zencache.zip
...
        0  06-19-15 16:25   zencache/src/vendor/websharks/wp-php-rv/src/includes/
      515  05-11-15 11:20   zencache/src/vendor/websharks/wp-php-rv/src/includes/check.php
    10014  05-11-15 11:20   zencache/src/vendor/websharks/wp-php-rv/src/includes/functions/wp.php
      317  06-19-15 16:25   zencache/uninstall.php
      409  06-19-15 16:25   zencache/zencache.php

I've made the same updates to the TarTask (exclude empty dirs, use ${project_slug}/ as the filename prefix).

@raamdev raamdev closed this as completed Jun 19, 2015
@jaswrks
Copy link
Contributor

jaswrks commented Jun 20, 2015

@raamdev writes...

I updated the ZipTask to use ${project_slug}/ as the prefix:

Ah, that's cool. Good to know. Thanks!

@raamdev writes...

I noticed there's also an includeemptydirs attribute to prevent empty directories from being included with the zip, so I added that in there (having that enabled would prevented #6 from appearing).

I love it!


If you get a chance to note those items in the CHANGELOG.md, I will try to do the same on my end whenever I make changes. See: https://github.com/websharks/phings/blob/master/CHANGELOG.md

raamdev added a commit that referenced this issue Jun 20, 2015
@raamdev
Copy link
Contributor Author

raamdev commented Jun 20, 2015

@jaswsinc Done.

jaswrks pushed a commit that referenced this issue Mar 3, 2016
@jaswrks jaswrks mentioned this issue Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants