Example #1
0
 /**
  * Verify that the file has not modified since it was stored
  *
  * @param InstallFile $file
  * @return bool
  */
 public static function verifyChecksum(InstallFile $file) : bool
 {
     return $file->hashMatches(File::checksum($file->getPath()));
 }
Example #2
0
 /**
  * For CLI usage: Bypass the download process, use a local file instead.
  *
  * @param string $path
  * @param string $version
  * @return AutoUpdater
  * @throws FileNotFound
  */
 public function useLocalUpdateFile(string $path, string $version = '') : self
 {
     if (\file_exists($path)) {
         throw new FileNotFound();
     }
     $hash = File::checksum($path);
     $this->localUpdateFile = new UpdateFile(['path' => $path, 'version' => $version, 'hash' => $hash, 'size' => \filesize($path)]);
     return $this;
 }
Example #3
0
/**
 * Used in our cachebust filter. This is mostly useful for HTML5 app caching
 *
 * @param $relative_path
 * @return string
 */
function cachebust($relative_path)
{
    if ($relative_path[0] !== '/') {
        $relative_path = '/' . $relative_path;
    }
    $absolute = $_SERVER['DOCUMENT_ROOT'] . $relative_path;
    if (\is_readable($absolute)) {
        // Halite's File::checksum() uses less memory than reading the entire
        // file into memory.
        $key = new AuthenticationKey(CryptoUtil::raw_hash((string) \filemtime($absolute)));
        return $relative_path . '?' . Base64UrlSafe::encode(File::checksum($absolute, $key, true));
    }
    // Special value
    return $relative_path . '?404NotFound';
}