Skip to content

Commit

Permalink
atomic create MO file: use tmp and rename to right name
Browse files Browse the repository at this point in the history
  • Loading branch information
Elbandi authored and CloCkWeRX committed Jan 28, 2012
1 parent 3a822b6 commit 7614cea
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Gettext/MO.php
Expand Up @@ -309,8 +309,10 @@ function save($file = null)
$file = $this->file;
}

$tmpfile = $file . "." . getmypid();

// open MO file
if (!is_resource($this->_handle = @fopen($file, 'wb'))) {
if (!is_resource($this->_handle = @fopen($tmpfile, 'wb'))) {
return parent::raiseError($php_errormsg . ' ' . $file);
}
// lock MO file exclusively
Expand Down Expand Up @@ -421,6 +423,9 @@ function save($file = null)
// done
@flock($this->_handle, LOCK_UN);
@fclose($this->_handle);

@rename($tmpfile, $file);
@unlink($tmpfile);
return true;
}
}
Expand Down

0 comments on commit 7614cea

Please sign in to comment.