Try to delete a non-existent file by execute the following line within Joomla > 4.4:
$res = \Joomla\Filesystem\File::delete(JPATH_ROOT . 'test.php');
$res = true
PHP Error Joomla\Filesystem\File::delete: Failed deleting inaccessible file test.php
Wampserver v3.3.1 on Windows 10 (64bit)
Joomla v4.4.1
PHP v8.1.2
MySQL v5.7.37
The old delete method ($res = \Joomla\CMS\Filesystem\File::delete(JPATH_ROOT . 'test.php');
) returns true when deleteing a non-existent file. With the new class \Joomla\Filesystem\File
, a PHP Error is thrown instead. This BC break stops some extension installation scripts from beeing executed correctly.
Example: JoomGalleryfriends/JG4-dev#161
Labels |
Added:
No Code Attached Yet
|
The change from the CMS to the Framework filesystem library was made with PR #40257 .
A simple and I personally think sufficient fix could be to wrap calls to File::delete()
into an if (is_file(...))
like it is e.g. proposed here #42088 for 4.4-dev (and already done in 5.0-dev) for Joomla Update or at other places.
@Hackwar Any other ideas?
sufficient fix could be to wrap calls to File::delete() into an if (is_file(...)) like it is e.g. proposed here #42088 for 4.4-dev (and already done in 5.0-dev)
me too i think so
@Elfangor93 can you link an extension so we can do some tests ?
can you link an extension so we can do some tests
We came across this issue when trying to update JoomGallery from version 3.6.2 to version 4.0.0. See JoomGalleryfriends/JG4-dev#161 (comment).
Steps to reproduce the error with JoomGallery
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-12-17 13:03:04 |
Closed_By | ⇒ | richard67 |
I propose eighter to make sure
\Joomla\Filesystem\File::delete()
returns true again when deleteing a non-existent file or change all occurrences of\Joomla\Filesystem\File::delete()
within Joomla\CMS\Installer such that it outputs for example a warning likeTrying to delete file "test.php" but file didn't exist.
instead of throwing an error which end the whole execution and leave a half-installed extension behind.What is your opinion on that?