* 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
This commit is contained in:
2016-11-28 11:20:49 +00:00
parent 0930c007b4
commit f3f3d9eaf7

View File

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