* 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:
23
file.php
23
file.php
@@ -274,6 +274,14 @@ class file
|
|||||||
$this->debug (2, "lockEX ($filename)");
|
$this->debug (2, "lockEX ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
$this->checkPathRW (dirname ($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");
|
$this->locks[$filename] = fopen ($filename, "rt");
|
||||||
return flock ($this->locks[$filename], LOCK_EX);
|
return flock ($this->locks[$filename], LOCK_EX);
|
||||||
}
|
}
|
||||||
@@ -288,6 +296,14 @@ class file
|
|||||||
$this->debug (2, "lockSH ($filename)");
|
$this->debug (2, "lockSH ($filename)");
|
||||||
$filename = $this->realpath ($filename);
|
$filename = $this->realpath ($filename);
|
||||||
$this->checkPathRW (dirname ($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");
|
$this->locks[$filename] = fopen ($filename, "rt");
|
||||||
return flock ($this->locks[$filename], LOCK_SH);
|
return flock ($this->locks[$filename], LOCK_SH);
|
||||||
}
|
}
|
||||||
@@ -311,7 +327,6 @@ class file
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Calculate the md5 sum of a file
|
/** Calculate the md5 sum of a file
|
||||||
* @param $filename The file to hash
|
* @param $filename The file to hash
|
||||||
* @return the calulated hash
|
* @return the calulated hash
|
||||||
@@ -327,9 +342,9 @@ class file
|
|||||||
"File '%s' is not a file"),
|
"File '%s' is not a file"),
|
||||||
$filename), 500);
|
$filename), 500);
|
||||||
if (! is_readable ($filename))
|
if (! is_readable ($filename))
|
||||||
throw new \Exception (sprintf (dgettext ("domframework",
|
throw new \Exception (sprintf (dgettext ("domframework",
|
||||||
"File '%s' is not readable"),
|
"File '%s' is not readable"),
|
||||||
$filename), 500);
|
$filename), 500);
|
||||||
return md5_file ($filename);
|
return md5_file ($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user