]> git.joonet.de Git - adminer.git/commitdiff
Refactor working with a locked file
authorPeter Knut <peter@pematon.com>
Mon, 7 Oct 2024 20:20:32 +0000 (22:20 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 16 Mar 2025 19:54:24 +0000 (20:54 +0100)
adminer/include/functions.inc.php

index d0475f0eaebaff6f04b5186c27a88db4e306f698..1e9755ae242e31583dc22670fd90cd327b59761b 100644 (file)
@@ -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;
 }