Signed-off-by: Diederik de Groot <ddegroot@talon.nl>
This commit is contained in:
Diederik de Groot
2020-02-18 03:50:23 +01:00
parent 41516a5fc9
commit 0ce2a149fc
2 changed files with 8 additions and 18 deletions

View File

@@ -23,10 +23,10 @@ class fileCache extends resolveCache {
function __destruct() { function __destruct() {
if ($this->_isDirty) { if ($this->_isDirty) {
if (!is_writable($this->_cache_file)) { /*if (!is_writable($this->_cache_file)) {
log_error_and_throw("Could not write to file '".$this->_cache_file."' at Resolver::destruct"); log_error_and_throw("Could not write to file '".$this->_cache_file."' at Resolver::destruct");
} }*/
if (!file_put_contents($this->_cache_file, serialize($this->cache))) { if (!file_put_contents($this->_cache_file, serialize($this->_cache))) {
log_error_and_throw("Could not write to file '".$this->_cache_file."' at Resolver::destruct"); log_error_and_throw("Could not write to file '".$this->_cache_file."' at Resolver::destruct");
} }
} }

View File

@@ -39,7 +39,6 @@ class Resolver {
} }
} }
public function searchForFile($filename) { public function searchForFile($filename) {
foreach($this->config['subdirs'] as $key => $value) { foreach($this->config['subdirs'] as $key => $value) {
if ($key === "firmware" || $key === "tftproot" ) { if ($key === "firmware" || $key === "tftproot" ) {
@@ -47,7 +46,7 @@ class Resolver {
} }
$path = realpath($this->config['main']['base_path'] . "/" . $value['path'] . "/$filename"); $path = realpath($this->config['main']['base_path'] . "/" . $value['path'] . "/$filename");
if (file_exists($path)) { if (file_exists($path)) {
$this-> addFile($filename, $path); $this->cache->addFile($filename, $path);
return $path; return $path;
} }
} }
@@ -56,6 +55,7 @@ class Resolver {
} }
public function rebuildCache() { public function rebuildCache() {
log_debug("Rebuilding Cache, standby...");
foreach($this->config['subdirs'] as $key =>$value) { foreach($this->config['subdirs'] as $key =>$value) {
if ($key === "tftproot") { if ($key === "tftproot") {
continue; continue;
@@ -66,10 +66,10 @@ class Resolver {
foreach ($iterator as $file) { foreach ($iterator as $file) {
if ($file->isFile()) { if ($file->isFile()) {
if ($value['strip']) { if ($value['strip']) {
$this->addFile($file->getFileName(), $file->getPathname()); $this->cache->addFile($file->getFileName(), $file->getPathname());
} else { } else {
$subdir = basename(dirname($file->getPathname())); $subdir = basename(dirname($file->getPathname()));
$this->addFile('$subpath/'.$file->getFileName(), $file->getPathname()); $this->cache->addFile('$subpath/'.$file->getFileName(), $file->getPathname());
} }
} }
} }
@@ -77,16 +77,6 @@ class Resolver {
$this->isDirty = TRUE; $this->isDirty = TRUE;
} }
public function addFile($requestpath, $truepath) {
log_debug("Adding $requestpath");
$this->cache->addFile($requestpath, $truepath);
}
public function removeFile($requestpath) {
log_debug("Removing $hash");
$this->cache->removeFile($requestpath, $truepath);
}
public function validateRequest($request) { public function validateRequest($request) {
/* make sure request does not startwith or contain: "/", "../" or "/./" */ /* make sure request does not startwith or contain: "/", "../" or "/./" */
/* make sure request only starts with filename or one of $config[$subdir]['locale'] or $config[$subdir]['wallpaper'] */ /* make sure request only starts with filename or one of $config[$subdir]['locale'] or $config[$subdir]['wallpaper'] */
@@ -120,7 +110,7 @@ class Resolver {
} }
if (($path = $this->cache->getPath($request))) { if (($path = $this->cache->getPath($request))) {
if (!file_exists($path)) { if (!file_exists($path)) {
$this->removeFile($request); $this->cache->removeFile($request);
log_error("File '$request' does not exist on FS"); log_error("File '$request' does not exist on FS");
return ResolveResult::FileNotFound; return ResolveResult::FileNotFound;
} }