From e490f99bafee3acf49196b5838d052a9aca98d5a Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 3 Dec 2024 00:05:22 +0100 Subject: avoid leaving tempfiles lying around if rename fails for permission reasons --- it.class | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/it.class b/it.class index e6e67d9..cbb5486 100644 --- a/it.class +++ b/it.class @@ -1217,8 +1217,12 @@ static function file_put($filename, $data, $p = array()) $tmpdir = is_dir($tmp) && is_writable($tmp) && stat($tmp)[0] == stat(dirname($filename))[0] ? $tmp : dirname($filename); $tmpfile = "$tmpdir/.it_put." . basename($filename) . "." . getmypid(); if (($result = it::file_put_contents($filename == "-" ? "php://stdout" : $tmpfile, $data)) !== false && $filename != "-") + { if (($result = rename($tmpfile, $filename)) && $p['cdist']) $result = it::cdist($filename); + else + @unlink($tmpfile); + } return $result; } -- cgit v1.2.3