Skip to content

[4.4] File::delete() throws error and terminates installation/update/uninstall#42533

Merged
laoneo merged 2 commits intojoomla:4.4-devfrom
Elfangor93:fix-issue-42495
Dec 19, 2023
Merged

[4.4] File::delete() throws error and terminates installation/update/uninstall#42533
laoneo merged 2 commits intojoomla:4.4-devfrom
Elfangor93:fix-issue-42495

Conversation

@Elfangor93
Copy link
Contributor

@Elfangor93 Elfangor93 commented Dec 17, 2023

With PR #40257 the File::delete() method in the framework was changed. It now throws a PHP error if it is called on a non-existing file path.
This behavior prevents installation, update and uninstall scripts of extensions from beeing executed correctly since the whole execution gets terminated as soon as Joomla\CMS\Installer tries to delete a file which does not exist anymore.

Pull Request for Issue #42495.

Summary of Changes

All occurrences of File::delete() in Joomla\CMS\Installer are first checked to see if the provided path exists and is a file by using the PHP built-in function if (is_file()) {File::delete()}.

Testing Instructions

Actual result BEFORE applying this Pull Request

Update terminates and a message appears stating Joomla\Filesystem\File::delete: Failed deleting inaccessible file controller.php and Error installing component

276254968-9946a7e3-b64b-419a-9295-b3f83eae4de1

After this unsuccessful update, uninstalling partially removed the component also does not work anymore.
It states Component Uninstall: Can't uninstall. Please remove manually. and Error uninstalling component.

Expected result AFTER applying this Pull Request

Update runs through without warning or error for non-existing files.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

Before calling File::delete(), the file path gets checked for existence with the PHP build in function is_file(). Only if the provided path is an existing file, it gets deleted using File::delete().
Copy link
Member

@richard67 richard67 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok by review, it covers all cases in the installer library. Of course it still needs human testers.

@alikon
Copy link
Contributor

alikon commented Dec 18, 2023

i've replicated the issue using com_patchtester 4.3.1
image

but with the patch applied I still have the same error

@Elfangor93
Copy link
Contributor Author

Elfangor93 commented Dec 18, 2023

but with the patch applied I still have the same error

@alikon The message you get with com_patchtester is a warning telling that a folder which should be deleted during the install/update is not existent. This gives you a warning, but is does not terminate the script. With non-existing files it is different:
Before applying this PR the install/update script was terminated and the installation was not successful leaving you behind with a partially installed extension which has to be removed by hand.

Deleting of non-existent folders is not scope of this PR since it "just" outputs you warning messages. In worst case you will get a huge number of messages telling all the different folders which could not be deleted. But the installation/update was still successful and the system is still healthy and usable.

I updated the initial comment of this PR to show you the error you get before applying this PR.
There you see a bunch of warnings because of non-existent folders and one warning followed by an error because of a non-existent file. The non-existent file terminated the installation completely!

@Elfangor93
Copy link
Contributor Author

For all the testers...

Prebuilt download packages of this PR are available here https://artifacts.joomla.org/drone/joomla/joomla-cms/4.4-dev/42533/downloads.
Use this packages to setup your fresh Joomla installation (step 1).

@laoneo
Copy link
Member

laoneo commented Dec 18, 2023

I think we should rather fix the Folder class as this is a BC break when a libraries function all of the sudden throws an exception instead of returning false instead.

@rowi68
Copy link

rowi68 commented Dec 18, 2023

I have tested this item ✅ successfully on ccb0e59


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42533.

@richard67
Copy link
Member

I think we should rather fix the Folder class as this is a BC break when a libraries function all of the sudden throws an exception instead of returning false instead.

The problem was the File class, not the Folder class, and the problöem came from changing the CMS code to use the framework library instead of the CMS one. To change the framework library now so it behaves like the CMS library did would mean a b/c break for the framework library.

@alikon
Copy link
Contributor

alikon commented Dec 18, 2023

@Elfangor93 i've got your point now
thanks for the clarification

@alikon
Copy link
Contributor

alikon commented Dec 18, 2023

I have tested this item ✅ successfully on ccb0e59


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42533.

@alikon
Copy link
Contributor

alikon commented Dec 18, 2023

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42533.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Dec 18, 2023
@alikon alikon added the bug label Dec 18, 2023
@laoneo
Copy link
Member

laoneo commented Dec 19, 2023

I think we should rather fix the Folder class as this is a BC break when a libraries function all of the sudden throws an exception instead of returning false instead.

The problem was the File class, not the Folder class, and the problöem came from changing the CMS code to use the framework library instead of the CMS one. To change the framework library now so it behaves like the CMS library did would mean a b/c break for the framework library.

So for me is sounds more reasonable to add a delete function back to the CMS class, call the base class with a try and catch. Like that is the BC break fixed. Or?

@richard67
Copy link
Member

richard67 commented Dec 19, 2023

I think we should rather fix the Folder class as this is a BC break when a libraries function all of the sudden throws an exception instead of returning false instead.

The problem was the File class, not the Folder class, and the problöem came from changing the CMS code to use the framework library instead of the CMS one. To change the framework library now so it behaves like the CMS library did would mean a b/c break for the framework library.

So for me is sounds more reasonable to add a delete function back to the CMS class, call the base class with a try and catch. Like that is the BC break fixed. Or?

@laoneo Sorry I don’t get it. You want to change the code so it uses the CMS class again and that one shall call the framework class with a try catch? Sorry but that is unnecessarily complicated, and requiring that from this PR here is a perfect example of how to stop a good PR with no reason.

P.S.: As far as I remember we want to come away from the CMS‘ filesystem library at all so we can throw it away one day, so using that again would be a step back.

@laoneo
Copy link
Member

laoneo commented Dec 19, 2023

Ah..., forget what I said. I thought that the File::delete from the CMS got remove and we work directly on the fw class. But all what was done is to change the namespace. So fine for me.

@laoneo laoneo added this to the Joomla! 4.4.2 milestone Dec 19, 2023
@laoneo laoneo merged commit 291c565 into joomla:4.4-dev Dec 19, 2023
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Dec 19, 2023
@laoneo
Copy link
Member

laoneo commented Dec 19, 2023

Sorry, for the noise. All good here. Thanks for the fix!

@richard67 richard67 mentioned this pull request Dec 20, 2023
@Elfangor93 Elfangor93 deleted the fix-issue-42495 branch July 6, 2024 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Comments