Skip to content

Commit

Permalink
fix 'mkdir(): File exists' error on create directory from parallel
Browse files Browse the repository at this point in the history
processes
  • Loading branch information
a-shpota committed Jul 14, 2017
1 parent a6f3a51 commit 6768340
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions libs/sysplugins/smarty_internal_runtime_writefile.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public function writeFile($_filepath, $_contents, Smarty $smarty)
}

$_dirpath = dirname($_filepath);
// if subdirs, create dir structure
if ($_dirpath !== '.' && !file_exists($_dirpath)) {
mkdir($_dirpath, $_dir_perms, true);

// if subdirs, create dir structure
if ($_dirpath !== '.' && !@mkdir($_dirpath, $_dir_perms, true) && !is_dir($_dirpath)) {
error_reporting($_error_reporting);
throw new SmartyException("unable to create directory {$_dirpath}");
}

// write to tmp file, then move to overt file lock race condition
Expand Down

1 comment on commit 6768340

@fixpunkt
Copy link

@fixpunkt fixpunkt commented on 6768340 Jul 24, 2017

Choose a reason for hiding this comment

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

Does this actually fix the race condition when two processes start creating the same directory structure in parallel (i.e. what this person reports: https://www.smarty.net/forums/viewtopic.php?t=26635&sid=8c1fd2650254f5a960be03effdf60dba)?

From what I see, this will still simply cause an error to be thrown. Is there any related issue / discussion for this?

Please sign in to comment.