YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.25k stars 410 forks source link

Getting "Update Failed: The directory structure of the update is incorrect." (When directory structure appears to be correct) #456

Open Nitinkumar6319 opened 3 years ago

Nitinkumar6319 commented 3 years ago

Hello,

I'm trying to use both the plugin update checker and the WP update server. As far as I can tell, the update server is working fine; visiting https://hirewebxperts.com/wp-update-server/?action=get_metadata&slug=my-plugin gives me a nice JSON output.

However, when updating plugins, the update checker (3.1) successfully recognizes that an update is available, but whenever I actually attempt the update, I get this message:

"Update Failed: The directory structure of the update is incorrect. All plugin files should be inside a directory named [directory-name], not at the root of the ZIP file."

Note: [directory-name] here is where the actual directory name appears.

I've triple-checked that the ZIP file specified by "download_url" in the JSON output expands to create a single folder, with all plugin files and subdirectories contained inside it. All plugin files are indeed inside a directory with the same name as the plugin slug, not at the root of the ZIP. As far as I can tell, the directory structure is correct:

pluginname.zip -> extracts to create -> pluginname (directory) -> which contains pluginname.php (along with other plugin files)

I've also tried creating an alternate directory structure by nesting the pluginname folder inside ANOTHER directory by the same name, then zipping it up for the updater to use. When I do that, I receive a 500 Error from the update server, telling me that no valid package was found.

This has to be a bug, right? Or am I nuts?

YahnisElsts commented 3 years ago

Are you on a Mac by any chance? I haven't used it myself, but I've received multiple reports that the default ZIP utility in macOS makes it look like files are inside a directory when they're actually not. If you are using macOS, try some third-party ZIP software. For example, I think 7-Zip has a Mac version.

Another thing to check would be is if there are any hidden files/dot files at the top of the archive. That could interfere with the update checker's ability to find the plugin directory in the ZIP file.

code-kendrick commented 1 year ago

I've been trying to figure this out for days. I get the same error when I know for sure the file structure is correct.

LoganStrike commented 1 year ago

If you are on Mac, try zipping the folder using Terminal. This is what I use and have never had an issue. It will remove any hidden files that start with dot:

zip -r my-folder.zip my-folder -x "*/\.*"