From 43e3fe375de20af2ede9e13e0a1ebed7776ce77c Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Mon, 7 Oct 2024 22:20:32 +0200 Subject: [PATCH] Refactor working with a locked file --- adminer/include/functions.inc.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index d0475f0e..1e9755ae 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -799,15 +799,15 @@ function get_temp_dir() { * @return resource or null for error */ function file_open_lock($filename) { - $fp = @fopen($filename, "r+"); // @ - may not exist - if (!$fp) { // c+ is available since PHP 5.2.6 - $fp = @fopen($filename, "w"); // @ - may not be writable - if (!$fp) { - return; - } - chmod($filename, 0660); + $fp = @fopen($filename, "c+"); // @ - may not be writable + if (!$fp) { + return; + } + chmod($filename, 0660); + if (!flock($fp, LOCK_EX)) { + fclose($fp); + return; } - flock($fp, LOCK_EX); return $fp; }