joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[5.1] Migrating Joomla\CMS\Filesystem\Folder::exists() to is_dir()

Open Hackwar opened this issue 2 years ago • 6 comments

Summary of Changes

We are migrating away from the Joomla\CMS\Filesystem classes to the framework Filesystem classes. This PR replaces all occurences of Joomla\CMS\Filesystem\Folder::exists() with is_dir(). The former method does not exist in the framework class, mainly because it is an unnecessary wrapper for the later. Where necessary, an import for Joomla\Filesystem\Path has been added and unnecessary ones removed. All the existing imports to Joomla\CMS\Filesystem\Path are changed to the framework package in another PR.

Joomla\Filesystem\Path::clean() should be used when the given path can not be 100% assumed to be safe, for example when the path is coming from some outside input. That method will make sure that a path will have the systems directory separator and not contain double slashes or double backslashes.

Testing Instructions

Codereview

Link to documentations

Please select:

  • [ ] Documentation link for docs.joomla.org:

  • [X] No documentation changes for docs.joomla.org needed

  • [ ] Pull Request link for manual.joomla.org:

  • [X] No documentation changes for manual.joomla.org needed

Hackwar avatar Mar 16 '23 09:03 Hackwar

It would be helpful for extension developers when you can write a couple of words in the pr description why you have used Path::clean.

laoneo avatar Mar 19 '23 10:03 laoneo

Done.

Hackwar avatar Mar 19 '23 19:03 Hackwar

I fixed the merge conflict but I'm not 100% sure if it make sense, since now we call is_dir(Path::clean()) before we just call Folder::exists() which implicit called Path::clean() for 3rd party developer it's possible that they forget or ignore the Path::clean() which might be an issue?

HLeithner avatar Sep 02 '23 15:09 HLeithner

The nice thing is, that we are not changing third party code, but just our core code. After this change, third party code will still behave the same. 😉

Hackwar avatar Sep 02 '23 15:09 Hackwar

The Codestyle error reported here is unrelated to this PR.

Hackwar avatar Sep 02 '23 15:09 Hackwar

I have tested this item :white_check_mark: successfully on 58f6055724a9da2faec4320d31b47b114a9edd79


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

Fedik avatar Feb 25 '24 12:02 Fedik

Thx

bembelimen avatar Mar 02 '24 06:03 bembelimen