From f3f3d9eaf747dfc433e7d907f804691faeca1c9e Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 28 Nov 2016 11:20:49 +0000 Subject: [PATCH] * file : Do not allow the locks to be done if the file to lock doesn't exists git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3225 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- file.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/file.php b/file.php index c9d7ec9..43e8c3f 100644 --- a/file.php +++ b/file.php @@ -274,6 +274,14 @@ class file $this->debug (2, "lockEX ($filename)"); $filename = $this->realpath ($filename); $this->checkPathRW (dirname ($filename)); + if (! file_exists ($filename)) + throw new \Exception (sprintf (dgettext ("domframework", + "File '%s' doesn't exists : could not be locked"), + $filename), 500); + if (! is_readable ($filename)) + throw new \Exception (sprintf (dgettext ("domframework", + "File '%s' is not readable : could not be locked"), + $filename), 500); $this->locks[$filename] = fopen ($filename, "rt"); return flock ($this->locks[$filename], LOCK_EX); } @@ -288,6 +296,14 @@ class file $this->debug (2, "lockSH ($filename)"); $filename = $this->realpath ($filename); $this->checkPathRW (dirname ($filename)); + if (! file_exists ($filename)) + throw new \Exception (sprintf (dgettext ("domframework", + "File '%s' doesn't exists : could not be locked"), + $filename), 500); + if (! is_readable ($filename)) + throw new \Exception (sprintf (dgettext ("domframework", + "File '%s' is not readable : could not be locked"), + $filename), 500); $this->locks[$filename] = fopen ($filename, "rt"); return flock ($this->locks[$filename], LOCK_SH); } @@ -311,7 +327,6 @@ class file return $res; } - /** Calculate the md5 sum of a file * @param $filename The file to hash * @return the calulated hash @@ -327,9 +342,9 @@ class file "File '%s' is not a file"), $filename), 500); if (! is_readable ($filename)) - throw new \Exception (sprintf (dgettext ("domframework", - "File '%s' is not readable"), - $filename), 500); + throw new \Exception (sprintf (dgettext ("domframework", + "File '%s' is not readable"), + $filename), 500); return md5_file ($filename); }