On local machine, I’ve made changes to the casper theme. I then used the download button to download the theme. In production, I use the upload button, selected downloaded theme then upload… then got “Failed to read zip file”
Form Data:
Content-Disposition: form-data; name="file"; filename="mayneweb.zip"
Content-Type: application/zip
After the message, I got a status code of 422
This server is a one-click install using DO. I’ve recently upgraded to 2.25.8 (on both dev and prod) using:
ghost upgrade 2.25.8
Local machines cannot upload the same file it downloaded either
Think I got it. I needed to run gulp zip
as per package.json
Kevin
July 19, 2019, 8:45am
3
This process should work Do you see any more specific error messages in your log files?
Kevin
July 19, 2019, 3:54pm
5
Thanks! That suggests that we should be skipping the node_modules
directory if it exists when creating a zip on the server. I’ll open an issue.
1 Like
Kevin
July 19, 2019, 4:16pm
6
Issue opened here. This should be a fairly self-contained and small task good for anyone new to the codebase if someone fancies tackling it
opened 04:13PM - 19 Jul 19 UTC
closed 08:17AM - 06 Aug 19 UTC
bug
good first issue
server / core
help wanted
### Issue Summary
When performing local development of a theme it can be usef… ul to click the "download" button for the theme in the admin area to get a zip in order to upload it. However, if you have any node modules installed in the theme then they can get bundled up, creating a _huge_ zip file and potentially breaking the theme import.
This issue was originally reported on the forum here https://forum.ghost.org/t/failed-to-read-zip-file/8325
### To Reproduce
1. `cd` into the `content/themes` directory and run `cp -R casper casper-custom`
2. `cd casper-custom` then run `yarn`
3. start Ghost
4. navigation to the Design screen in the admin area
5. click the "download" link for the custom casper theme to get a zip
6. click "Upload a theme" and attempt to upload the zip file
7. note the error messages in your server logs
The upload is failing because the `node_modules` directory is included in the zip and Casper uses the `gscan` module which has an intentionally bad symlink in it's test files to ensure that theme uploads fail on bad symlinks.
Although it's not always the _correct_ way of creating a zip file for a local theme (it won't run any build steps for example) the above flow is still useful in many circumstances. We should ensure that the `node_modules` directory is skipped when creating a zip to fix the flow and to reduce server load from attempting to zip potentially thousands of module files.
### Potential Solution
For reference, zip files creation is [triggered in ThemeStorage class](https://github.com/TryGhost/Ghost/blob/master/core/frontend/services/themes/ThemeStorage.js#L38) and uses the [zip-folder utility](https://github.com/TryGhost/Ghost/blob/master/core/server/lib/fs/zip-folder.js) which in turn uses the external [archiver](https://www.npmjs.com/package/archiver) module.
A potential solution could be performing some file globbing (Ghost already has the [glob](https://github.com/isaacs/node-glob) dependency) to generate a file list excluding the `node_modules` directory which can then be passed to the `archiver` instance.
1 Like