Fixed Building an add-on fails for certain Composer packages

DragonByte Tech

Well-known member
Affected version
2.1.3
If a composer package uses a symbolic link, building an add-on using that package will fail.

My composer.json file:
JSON:
{
    "require": {
        "defuse/php-encryption": "^2.2"
    }
}

My build.json file:
JSON:
{
    "additional_files": [
        "js/DBTech/Tickets"
    ],
    "exec": [
        "rm -f _build/upload/src/addons/{addon_id}/dev.json",
        "rm -f _build/upload/src/addons/{addon_id}/git.json",
        "rm -f _build/upload/src/addons/{addon_id}/build-server.json",
        "composer install --working-dir=_build/upload/src/addons/{addon_id}/ --no-dev --optimize-autoloader"
    ],
    "minify": "*"
}

In File.php line 610:

[ErrorException]
[E_WARNING] rmdir(/www/public_html/devboards/xf2/src/addons/DBTech/Tickets/_build/upload/src/addons/DBTech/Tickets/vendor/bin): Directory not empty

Code:
() at /www/public_html/devboards/xf2/src/XF/Util/File.php:610
 XF::handlePhpError() at n/a:n/a
 rmdir() at /www/public_html/devboards/xf2/src/XF/Util/File.php:610
 XF\Util\File::deleteDirectory() at /www/public_html/devboards/xf2/src/XF/Service/AddOn/ReleaseBuilder.php:439
 XF\Service\AddOn\ReleaseBuilder->finalizeRelease() at /www/public_html/devboards/xf2/src/XF/Cli/Command/AddOn/BuildRelease.php:86
 XF\Cli\Command\AddOn\BuildRelease->execute() at /www/public_html/devboards/xf2/src/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /www/public_html/devboards/xf2/src/vendor/symfony/console/Application.php:960
 Symfony\Component\Console\Application->doRunCommand() at /www/public_html/devboards/xf2/src/vendor/symfony/console/Application.php:255
 Symfony\Component\Console\Application->doRun() at /www/public_html/devboards/xf2/src/vendor/symfony/console/Application.php:148
 Symfony\Component\Console\Application->run() at /www/public_html/devboards/xf2/src/XF/Cli/Runner.php:63
 XF\Cli\Runner->run() at /www/public_html/devboards/xf2/cmd.php:15

Code:
#0 [internal function]: XF::handlePhpError(2, '[E_WARNING] rmd...', '/www/public_htm...', 610, Array)
#1 src/XF/Util/File.php(610): rmdir('/www/public_htm...')
#2 src/XF/Service/AddOn/ReleaseBuilder.php(439): XF\Util\File::deleteDirectory('/www/public_htm...')
#3 src/XF/Cli/Command/AddOn/BuildRelease.php(86): XF\Service\AddOn\ReleaseBuilder->finalizeRelease()
#4 src/vendor/symfony/console/Command/Command.php(255): XF\Cli\Command\AddOn\BuildRelease->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 src/vendor/symfony/console/Application.php(960): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 src/vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(XF\Cli\Command\AddOn\BuildRelease), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 src/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 src/XF/Cli/Runner.php(63): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 cmd.php(15): XF\Cli\Runner->run()
#10 {main}

Request state:
Code:
array(1) {
  ["cli"] => string(48) "cmd.php xf-addon:build-release DBTech/Tickets -v"
}

Fix: In \XF\Util\File find:
PHP:
                unlink($file->getRealPath());
Replace with:
PHP:
                if ($file->isLink())
                {
                    unlink($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename());
                }
                else
                {
                    unlink($file->getRealPath());
                }

This works for me and allows the build to finish without error. The _build directory is successfully cleaned up.
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.4).

Change log:
Correctly handle deleting directories with symlinks
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Back
Top Bottom