From caa3827bc6f9dd17df6a862582843bfa5d6c5a28 Mon Sep 17 00:00:00 2001 From: Diederik de Groot Date: Sat, 15 Feb 2020 20:16:44 +0100 Subject: [PATCH] Use file_put_contents instead of open/write Use file_exist instead of stat Signed-off-by: Diederik de Groot --- tftpboot/resolver.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tftpboot/resolver.php b/tftpboot/resolver.php index a5ae4b3..653cce0 100755 --- a/tftpboot/resolver.php +++ b/tftpboot/resolver.php @@ -25,13 +25,9 @@ class Resolver { function __destruct() { //print_r($this->cache); if ($this->isDirty) { - if($f = @fopen($GLOBALS["CACHEFILE_NAME"],"w")) { - //if(@fwrite($f,serialize(get_object_vars($this)))) - if(@fwrite($f,serialize($this->cache))) { - @fclose($f); - } - } else - die("Could not write to file ".$GLOBALS["CACHEFILE_NAME"]." at Resolver::destruct"); + if (!file_put_contents($GLOBALS["CACHEFILE_NAME"], serialize($this->cache))) { + throw new Exception("Could not write to file ".$GLOBALS["CACHEFILE_NAME"]." at Resolver::destruct"); + } } } function searchForFile($filename) { @@ -83,7 +79,7 @@ class Resolver { $path = ""; if (array_key_exists($request, $this->cache)) { if ($path = $this->cache[$request]) { - if (!stat($path)) { + if (!file_exists($path)) { $this->removeFile($request); throw new Exception("File '$request' does not exist on FS"); }