fix: child folder detection in ZIP for plugin extraction
locateName does not support directory detection, fixed with new changes
Plugins can now correctly be uploaded as 1 zipped directory.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.
I have read the CLA Document and I hereby sign the CLA
Thanks, but I don't understand the problem with locateName? It does detect directories?
I tried with a zip that directly contains the plugin data and a zip that has a folder with the plugin data and both imported fine.
That's strange, on me it does not, with the current state of the branch when I upload: my-plugin.zip/my-plugin/plugin.json it creates /root/plugins/my-plugin/my-plugin/plugin.json, since when I dd $zip->locateName($pluginName . '/') it gives false even tho the zip structure is my-plugin.zip/my-plugin/plugin.json
aaa I found the issue, so the issue is not locateName not detecting directories, but different ZIP tools not creating directory entries, for example, a ZIP tool which does not create a directory entry would only contain:
my-plugin/plugin.json
my-plugin/src/MyPluginPlugin.php
While a ZIP tool which does create a directory entry would actually contain
my-plugin/
my-plugin/plugin.json
my-plugin/src/MyPluginPlugin.php
Which would indeed work with the current code, so a more reliable way to check for this is by checking for the plugin.json file instead of the root directory it self:
$extractPath = $zip->locateName($pluginName . '/plugin.json') !== false ? base_path('plugins') : plugin_path($pluginName);