Fixed \XF\Util\File::copyFileToAbstractedPath runs fclose even when unnecessary

Affected version
Latest

Jake B.

Well-known member
On line 186 of src/XF/Util/File.php fclose($fp) is called even if $fp is not a resource stream. I've found that, for some reason, the microsoft/azure-storage-blob library runs fclose on the handler within one of its functions (Specifically here), which causes a warning to be thrown within XenForo when attempting to hook up the flysystem Azure handler.

Could we get:

PHP:
public static function copyFileToAbstractedPath($file, $abstractedPath, array $config = [])
{
   $fp = fopen($file, 'r');
   $result = \XF::app()->fs()->putStream($abstractedPath, $fp, $config);
   fclose($fp);

   return $result;
}

changed to:
PHP:
public static function copyFileToAbstractedPath($file, $abstractedPath, array $config = [])
{
   $fp = fopen($file, 'r');
   $result = \XF::app()->fs()->putStream($abstractedPath, $fp, $config);
   if (get_resource_type($fp) === 'stream') {
      fclose($fp);
   }

   return $result;
}

or:

PHP:
public static function copyFileToAbstractedPath($file, $abstractedPath, array $config = [])
{
   $fp = fopen($file, 'r');
   $result = \XF::app()->fs()->putStream($abstractedPath, $fp, $config);
   @fclose($fp);

   return $result;
}

to suppress this warning, which I think will be much cleaner and more future proof than having to manually patch the library (especially since copyAbstractedPathToTempFile already suppresses this, likely for the same reason
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.8).

Change log:
Supress warnings when closing file pointer after copying file
There may be a delay before changes are rolled out to the XenForo Community.
 
Top