Commit f49acb93 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #156 in ZP/z-push from...

Merge pull request #156 in ZP/z-push from bugfix/ZP-794-use-safeputcontents-to-ensure-atomacy-2 to develop

* commit 'f34003c0':
  ZP-794 Remove now useless call to FixFileOwner.
  ZP-794 Call FixFileOwner in SafePutContents.
parents 52e58756 f34003c0
......@@ -374,7 +374,6 @@ class FileStateMachine implements IStateMachine {
$settings[self::VERSION] = $version;
ZLog::Write(LOGLEVEL_INFO, sprintf("FileStateMachine->SetStateVersion() saving supported state version, value '%d'", $version));
$status = Utils::SafePutContents($this->settingsfilename, serialize($settings));
Utils::FixFileOwner($this->settingsfilename);
return $status;
}
......
......@@ -932,7 +932,8 @@ class Utils {
/**
* Safely write data to disk, using an unique tmp file (concurrent write),
* and using rename for atomicity
* and using rename for atomicity. It also calls FixFileOwner to prevent
* ownership/rights problems when running as root
*
* If you use SafePutContents, you can safely use file_get_contents
* (you will always read a fully written file)
......@@ -944,9 +945,11 @@ class Utils {
public static function SafePutContents($filename, $data) {
//put the 'tmp' as a prefix (and not suffix) so all glob call will not see temp files
$tmp = dirname($filename).DIRECTORY_SEPARATOR.'tmp-'.getmypid().'-'.basename($filename);
if (($res = file_put_contents($tmp, $data)) !== false)
if (($res = file_put_contents($tmp, $data)) !== false) {
self::FixFileOwner($tmp);
if (rename($tmp, $filename) !== true)
$res = false;
}
return $res;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment