mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 06:07:32 +02:00
Bugfixes and performance optimization for e_file_inspector
- MOD: e_file_inspector::validate() will no longer bother with checksumming a file if the database hash is not present for the requested version. - MOD: Better check for e_file_inspector::VALIDATED_DETERMINABLE - MOD: e_file_inspector::VALIDATED_UPTODATE will now pass if there is no checksum in the database and no calculable checksum in the real file. - FIX: Better documentation for e_file_inspector_interface::VALIDATED_DETERMINABLE - FIX: Use the same bit for e_file_inspector::VALIDATED for a full validation check in e_file_inspector::validate()
This commit is contained in:
@@ -33,13 +33,13 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
|||||||
|
|
||||||
$bits = 0x0;
|
$bits = 0x0;
|
||||||
$absolutePath = realpath(e_BASE . $path);
|
$absolutePath = realpath(e_BASE . $path);
|
||||||
$actualChecksum = $this->checksumPath($absolutePath);
|
|
||||||
$dbChecksum = $this->getChecksum($path, $version);
|
$dbChecksum = $this->getChecksum($path, $version);
|
||||||
|
$actualChecksum = $dbChecksum ? $this->checksumPath($absolutePath) : null;
|
||||||
|
|
||||||
if ($dbChecksum !== false) $bits |= self::VALIDATED_RELEVANCE;
|
if ($dbChecksum !== false) $bits |= self::VALIDATED_RELEVANCE;
|
||||||
if (file_exists($absolutePath)) $bits |= self::VALIDATED_PRESENCE;
|
if (file_exists($absolutePath)) $bits |= self::VALIDATED_PRESENCE;
|
||||||
if (!$this->isInsecure($path)) $bits |= self::VALIDATED_SECURITY;
|
if (!$this->isInsecure($path)) $bits |= self::VALIDATED_SECURITY;
|
||||||
if ($actualChecksum !== false) $bits |= self::VALIDATED_DETERMINABLE;
|
if ($this->isDeterminable($absolutePath)) $bits |= self::VALIDATED_DETERMINABLE;
|
||||||
if ($actualChecksum === $dbChecksum) $bits |= self::VALIDATED_UPTODATE;
|
if ($actualChecksum === $dbChecksum) $bits |= self::VALIDATED_UPTODATE;
|
||||||
|
|
||||||
foreach ($this->getChecksums($path) as $dbVersion => $dbChecksum)
|
foreach ($this->getChecksums($path) as $dbVersion => $dbChecksum)
|
||||||
@@ -47,7 +47,7 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
|||||||
if ($dbChecksum === $actualChecksum) $bits |= self::VALIDATED_HASH;
|
if ($dbChecksum === $actualChecksum) $bits |= self::VALIDATED_HASH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bits + 0x1 === $this->getValidatedBitmask()) $bits |= self::VALIDATED;
|
if ($bits + self::VALIDATED === $this->getValidatedBitmask()) $bits |= self::VALIDATED;
|
||||||
|
|
||||||
return $bits;
|
return $bits;
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
|||||||
*/
|
*/
|
||||||
public function checksumPath($absolutePath)
|
public function checksumPath($absolutePath)
|
||||||
{
|
{
|
||||||
if (!is_file($absolutePath) || !is_readable($absolutePath)) return false;
|
if (!$this->isDeterminable($absolutePath)) return false;
|
||||||
|
|
||||||
return $this->checksum(file_get_contents($absolutePath));
|
return $this->checksum(file_get_contents($absolutePath));
|
||||||
}
|
}
|
||||||
@@ -151,4 +151,13 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
|||||||
$this->validatedBitmask = (max($validated_constants) << 0x1) - 0x1;
|
$this->validatedBitmask = (max($validated_constants) << 0x1) - 0x1;
|
||||||
return $this->validatedBitmask;
|
return $this->validatedBitmask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $absolutePath
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isDeterminable($absolutePath)
|
||||||
|
{
|
||||||
|
return is_file($absolutePath) && is_readable($absolutePath);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -36,7 +36,7 @@ interface e_file_inspector_interface
|
|||||||
const VALIDATED_UPTODATE = 1 << 4;
|
const VALIDATED_UPTODATE = 1 << 4;
|
||||||
/**
|
/**
|
||||||
* TRUE: The file hash is calculable.
|
* TRUE: The file hash is calculable.
|
||||||
* FALSE: The file hash is not calculable (e.g. the core image itself, a user configuration file).
|
* FALSE: The file hash is not calculable (e.g. the core image itself, a user config file, a nonexistent file).
|
||||||
*/
|
*/
|
||||||
const VALIDATED_DETERMINABLE = 1 << 5;
|
const VALIDATED_DETERMINABLE = 1 << 5;
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user