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); }