Use file_put_contents instead of open/write

Use file_exist instead of stat

Signed-off-by: Diederik de Groot <ddegroot@talon.nl>
This commit is contained in:
Diederik de Groot
2020-02-15 20:16:44 +01:00
parent 31c5a69460
commit caa3827bc6

View File

@@ -25,13 +25,9 @@ class Resolver {
function __destruct() { function __destruct() {
//print_r($this->cache); //print_r($this->cache);
if ($this->isDirty) { if ($this->isDirty) {
if($f = @fopen($GLOBALS["CACHEFILE_NAME"],"w")) { if (!file_put_contents($GLOBALS["CACHEFILE_NAME"], serialize($this->cache))) {
//if(@fwrite($f,serialize(get_object_vars($this)))) throw new Exception("Could not write to file ".$GLOBALS["CACHEFILE_NAME"]." at Resolver::destruct");
if(@fwrite($f,serialize($this->cache))) { }
@fclose($f);
}
} else
die("Could not write to file ".$GLOBALS["CACHEFILE_NAME"]." at Resolver::destruct");
} }
} }
function searchForFile($filename) { function searchForFile($filename) {
@@ -83,7 +79,7 @@ class Resolver {
$path = ""; $path = "";
if (array_key_exists($request, $this->cache)) { if (array_key_exists($request, $this->cache)) {
if ($path = $this->cache[$request]) { if ($path = $this->cache[$request]) {
if (!stat($path)) { if (!file_exists($path)) {
$this->removeFile($request); $this->removeFile($request);
throw new Exception("File '$request' does not exist on FS"); throw new Exception("File '$request' does not exist on FS");
} }