Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to create config directories if non existant #3115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Blaklis
Copy link
Contributor

@Blaklis Blaklis commented Jan 23, 2023

The patch will allow dompdf to try creating tmpDir, fontDir and fontCache if they do not exist on the filesystem - and will trigger a warning if they can't be created.

Even if the Options.php file mention that pathes should exist, a number of people will set the options and won't even see that the folders weren't created.

Trying to create them by default will :

  • Avoid bugs / lack of performances when directories are created
  • Will warn the user that his configurations are not suitable if necessary.

Later, it might also be possible to change the trigger_error to an exception, but right now, it would be a BC break.

The patch will allow dompdf to try creating tmpDir, fontDir and fontCache if they do not exist on the filesystem - and will trigger a warning if they can't be created.

Even if the Options.php file mention that pathes should exist, a number of people will set the options and won't even see that the folders weren't created.

Trying to create them by default will : 
- Avoid bugs / lack of performances when directories are created
- Will warn the user that his configurations are not suitable if necessary.

Later, it might also be possible to change the trigger_error to an exception, but right now, it would be a BC break.
@bsweeney
Copy link
Member

This seems reasonable.

@bsweeney bsweeney modified the milestones: 2.0.2, 2.0.3 Jan 23, 2023
Copy link
Member

@bsweeney bsweeney left a comment

Choose a reason for hiding this comment

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

Thinking on this again, I wonder if we just require that the user create the necessary directories prior to setting them in Dompdf. The main reason being that if we really want to do this we should probably allow the user to specify the permissions, which complicates things a bit. We could, instead of making the directory, just throw an exception if the specified directory is invalid so that the user knows they forgot to do something.

I'm still open to this change, just trying to think through potential unintended consequences.

@@ -848,6 +848,9 @@ public function getDpi()
*/
public function setFontCache($fontCache)
{
if (!is_dir($fontCache) && !mkdir($fontCache)) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we make the directory recursively (e.g., mkdir($dir, 0777, true))?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that would be definitely better, even if the 777 permission might be problematic somehow

@bsweeney bsweeney modified the milestones: 2.0.4, 2.0.5 Jun 11, 2023
@Blaklis
Copy link
Contributor Author

Blaklis commented Jun 22, 2023

Thinking on this again, I wonder if we just require that the user create the necessary directories prior to setting them in Dompdf. The main reason being that if we really want to do this we should probably allow the user to specify the permissions, which complicates things a bit. We could, instead of making the directory, just throw an exception if the specified directory is invalid so that the user knows they forgot to do something.

I'm still open to this change, just trying to think through potential unintended consequences.

Yep, I agree - however, I didn't want to have a BC break by preventing people to run if the folder doesn't exist. Might it be a simple warning message for the next version, and a break on the next one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants