Duplicate build process fails when removing folders containing symlinks

Sim

Well-known member
Affected version
XF 2.1
One of my addons uses composer packages, one of which (Carbon) creates a symlink from the vendor/bin folder to an executable in the package.

During the build cleanup process, XenForo attempts to delete the _build directory, however it fails due to one of the directories not being empty.

This is because the code is resolving the "real path" of the file and deleting that, rather than deleting the symlink itself.

PHP:
public static function deleteDirectory($path)
       
        ...
   
        $files = self::getRecursiveDirectoryIterator($path);
        foreach ($files AS $file)
        {
            if ($file->isDir())
            {
                rmdir($file->getRealPath());
            }
            else
            {
                unlink($file->getRealPath()); // <-- does not delete symlinks
            }
        }

        ...
}

This can be fixed by checking whether the file is a symlink and deleting it directly.

PHP:
public static function deleteDirectory($path)
{
        ...

        $files = self::getRecursiveDirectoryIterator($path);
        foreach ($files AS $file)
        {
            if ($file->isDir())
            {
                rmdir($file->getRealPath());
            }
            elseif ($file->isLink())
            {
                unlink($file->getPathname()); // unlink symlinks
            }
            else
            {
                unlink($file->getRealPath());
            }
        }

        ...
}

I have verified that this change correctly removes symlinks and allows the build process to complete successfully.
 
Which version of XF 2.1 specifically? (realistically, entering 2.1 in affected versions isn't helpful)

I believe we fixed this in XF 2.1.3:
 
Oops - apologies, I didn't realise I was still running XF 2.1.3 on my dev server ... with 8 servers in production plus my various dev servers (one for each major release) I had forgotten which versions I had installed where.

I can confirm this is fixed in XF 2.1.4

Thanks for your prescience :D
 
Back
Top Bottom