Fixed 1.3.1 mkdir(): File exists When Trying To Drag & Drop Image Inline

Anthony Parsons

Well-known member
I tried to drag and drop two images into the editor and got the following error. This was also a front-end popup error, which is why I felt it relevant to mention here, as that confuses users.

Code:
Error Info
ErrorException: mkdir(): File exists - library/XenForo/Helper/File.php:68
Generated By: Anthony, 3 minutes ago
Stack Trace
#0 [internal function]: XenForo_Application::handlePhpError(2, 'mkdir(): File e...', '/home/myfruct/p...', 68, Array)
#1 /home/myfruct/public_html/library/XenForo/Helper/File.php(68): mkdir('/home/myfruct/p...')
#2 /home/myfruct/public_html/library/XenForo/DataWriter/AttachmentData.php(221): XenForo_Helper_File::createDirectory('/home/myfruct/p...', true)
#3 /home/myfruct/public_html/library/XenForo/DataWriter/AttachmentData.php(143): XenForo_DataWriter_AttachmentData->_writeAttachmentFile('/tmp/phpLhxmVy', Array)
#4 /home/myfruct/public_html/library/XenForo/DataWriter.php(1409): XenForo_DataWriter_AttachmentData->_postSave()
#5 /home/myfruct/public_html/library/XenForo/Model/Attachment.php(524): XenForo_DataWriter->save()
#6 /home/myfruct/public_html/library/XenForo/ControllerPublic/Attachment.php(201): XenForo_Model_Attachment->insertUploadedAttachmentData(Object(XenForo_Upload), 2)
#7 /home/myfruct/public_html/library/XenForo/FrontController.php(347): XenForo_ControllerPublic_Attachment->actionDoUpload()
#8 /home/myfruct/public_html/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#9 /home/myfruct/public_html/index.php(13): XenForo_FrontController->run()
#10 {main}
Request State
array(3) {
  ["url"] => string(121) "http://www.myfructosemalabsorption.com/attachments/do-upload.json?hash=2751ced4d5366bcf7bec94e2dc68a22f&content_type=post"
  ["_GET"] => array(2) {
    ["hash"] => string(32) "2751ced4d5366bcf7bec94e2dc68a22f"
    ["content_type"] => string(4) "post"
  }
  ["_POST"] => array(4) {
    ["_xfToken"] => string(8) "********"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfSessionId"] => string(32) "be59688b754419e54f320ad5147467fd"
    ["content_data"] => array(1) {
      ["node_id"] => string(1) "3"
    }
  }
}
 
This is the first time I'm seen this issue come up with attachments, but it's from a race condition. In general, it's nothing to worry about but it would have broken the attachment that triggered it.

The challenge here is closing the race condition as far as possible -- which I think I've already done. There's a file_exists check right before calling mkdir. (PHP does not cache failed file_exists calls so it should not be hitting the cache.) I don't really want to suppress the error as this is a common place where people run into permission errors that they need to sort. The only option I can see is actually trapping the exception and reading the text of the error to determine what happened -- a very ugly solution but perhaps the only viable one.
 
Top Bottom