please fix existing mkdir error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamie
    Member
    • Aug 2025
    • 39

    #1

    please fix existing mkdir error

    this one is triggering a php error for me and breaking the front end

    no i don't want to turn down php loging on a development server its needed


    <b>Warning</b>: mkdir(): File exists in <b>/var/www/html/application/Espo/Core/Utils/File/Manager.php</b> on line <b>519</b><br />

    thanks
  • yuri
    EspoCRM product developer
    • Mar 2014
    • 9345

    #2
    If it's a race condition that two concurrent processes run the same code creating the dir simultaneously, then I'm not sure how to fix since error suppression is not available in PHP. Maybe you know how to fix.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • yuri
      EspoCRM product developer
      • Mar 2014
      • 9345

      #3
      Maybe such a fix will help. But requires testing.

      Code:
      set_error_handler(fn() => {});
      $result = mkdir($path, $permission);
      restore_error_handler();
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment


      • yuri
        yuri commented
        Editing a comment
        The downside of this fix is that true permission errors won't be logged.
    • yuri
      EspoCRM product developer
      • Mar 2014
      • 9345

      #4
      Now I think I understand. You enabled PHP error printing somehow.

      Then, your initial post should have been like this:

      I have enabled PHP error printing for development purposes. After this, sometimes the following PHP warning breaks the frontend:

      <b>Warning</b>: mkdir(): File exists in <b>/var/www/html/application/Espo/Core/Utils/File/Manager.php</b> on line <b>519</b><br />
      What changed:
      • Provided prerequisites.
      • Sentences start with a capital letters.
      • Dots used in the end of sentences.
      • No blunt language like, "no i don't want...", is used.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • jamie
        Member
        • Aug 2025
        • 39

        #5
        The usual way to handle this in PHP is something like:

        PHP Code:
        if (!file_exists($path) && !is_link($path)) {
        mkdir($path0700);

        This check prevents the “file exists” warning from appearing. It’s a very common safeguard and part of the normal pattern developers use when creating directories.

        It’s also worth making sure PHP errors are enabled when you’re debugging — otherwise, it can be really difficult to track down what’s going on behind the scenes. Having them on will save you time and give you clearer insights into issues like this.

        And just a note on tone: developers (especially in open source) tend to be direct and to the point — that’s usually about efficiency, not criticism. I know your posts are also very straightforward, which is a strength. The important part is just working together and keeping things constructive.

        I’m here to help, not to make your day harder — let’s get this sorted together.

        Comment

        • yuri
          EspoCRM product developer
          • Mar 2014
          • 9345

          #6
          This code is not race condition safe. As far as I remember, there's no race condition safe method to create dirs in PHP without throwing warning.

          Code:
          if (!file_exists($path) && !is_link($path)) {
               mkdir($path, 0700);
          }
          The only difference between our version, it that we also have $umask = umask(0); in between check and execution.
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment


          • yuri
            yuri commented
            Editing a comment
            Maybe we'd rather get rid of unmask which would reduce race condition probability. But this code is very crucial, and tested by time. Would require quite an effort to test and analyze.

            Moving unmask before the check is not a good option too I believe.
        • jamie
          Member
          • Aug 2025
          • 39

          #7
          yeah a bit of a conundrum, this has worked quite well for me in the past, though with the modern speed of computers the race is real

          perhaps throwing a RuntimeException is the way forward? that should avoid triggering system php errors and the exception can just be ignored?
          Last edited by jamie; Today, 08:31 AM.

          Comment

          • yuri
            EspoCRM product developer
            • Mar 2014
            • 9345

            #8
            The race condition actually likely had happened when you had that warning. Maybe umask usage increases its probability drastically, not sure. I removed umask: https://github.com/espocrm/espocrm/c...cba1ba874a44a7
            If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

            Comment

            • jamie
              Member
              • Aug 2025
              • 39

              #9
              yeah might do, thanks for that though i am going to have to wait till the official upgrade for benefit, still good to know it's on the way <3

              hope ya got a great weekend planned

              Comment

              Working...