Commit accbd682 authored by Etienne CHAMPETIER's avatar Etienne CHAMPETIER

ZP-794 Call FixFileOwner in SafePutContents.

Released under the Affero GNU General Public License (AGPL) version 3.

This prevents ownership/rights problem when running as root
Signed-off-by: 's avatarEtienne CHAMPETIER <champetier.etienne@gmail.com>
parent c42848ed
...@@ -932,7 +932,8 @@ class Utils { ...@@ -932,7 +932,8 @@ class Utils {
/** /**
* Safely write data to disk, using an unique tmp file (concurrent write), * 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 * If you use SafePutContents, you can safely use file_get_contents
* (you will always read a fully written file) * (you will always read a fully written file)
...@@ -944,9 +945,11 @@ class Utils { ...@@ -944,9 +945,11 @@ class Utils {
public static function SafePutContents($filename, $data) { public static function SafePutContents($filename, $data) {
//put the 'tmp' as a prefix (and not suffix) so all glob call will not see temp files //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); $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) if (rename($tmp, $filename) !== true)
$res = false; $res = false;
}
return $res; 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