public function getURLLastModified($url, $symlink, $bucket) { $symlink .= '.link'; $now = $this->time; if (!$this->fileExists($symlink)) { return array('time' => 0, 'revalidate' => true, 'cache_age' => 0); } $contents = $this->getFile($symlink); $contents = json_decode($contents, true); if ($contents['link'] == '/dev/null') { // Dead URL $failed_time = $now - $contents['mtime']; if ($failed_time > binarypool_config::getBadUrlExpiry()) { $this->unlink($symlink); return array('time' => 0, 'revalidate' => true, 'cache_age' => $failed_time); } $failed_nextfetch = $contents['mtime'] + binarypool_config::getBadUrlExpiry() - $now; throw new binarypool_exception(122, 400, "File download failed {$failed_time} seconds ago. Re-fetching allowed in next time in {$failed_nextfetch} seconds: {$url}"); } $cache_age = $now - $contents['mtime']; $revalidate = false; if ($cache_age > binarypool_config::getCacheRevalidate($bucket)) { $revalidate = true; } return array('time' => $contents['mtime'], 'revalidate' => $revalidate, 'cache_age' => $cache_age); }
public function getURLLastModified($url, $symlink, $bucket) { $this->clearstatcache(); if (!$this->fileExists($symlink)) { return array('time' => 0, 'revalidate' => true, 'cache_age' => 0); } $symlinkAbs = $this->absolutize($symlink); $stat = lstat($symlinkAbs); $now = time(); if (readlink($symlinkAbs) == '/dev/null') { $failed_time = $now - $stat['mtime']; if ($failed_time > binarypool_config::getBadUrlExpiry()) { unlink($symlinkAbs); return array('time' => 0, 'revalidate' => true, 'cache_age' => $failed_time); } $failed_nextfetch = $stat['mtime'] + binarypool_config::getBadUrlExpiry() - $now; throw new binarypool_exception(122, 400, "File download failed {$failed_time} seconds ago. Re-fetching allowed in next time in {$failed_nextfetch} seconds: {$url}"); } $cache_age = $now - $stat['mtime']; $revalidate = false; if ($cache_age > binarypool_config::getCacheRevalidate($bucket)) { $revalidate = true; } return array('time' => filemtime($symlinkAbs), 'revalidate' => $revalidate, 'cache_age' => $cache_age); }
function testGetUrlFailedNoRefetchYet() { $bucket = $this->getS3Bucket(); $s3 = $this->getS3Client(); $storage = new binarypool_storage_driver_s3($bucket['storage'], $s3, $this->getMockCache(), $this->time); $s3->expectOnce('getObjectInfo', array('bin.staticlocal.ch', 'test/downloaded/9f/9fae60fc483eef3a55cbad16b9f13c94eb81a5de.link', false)); $s3->setReturnValue('getObjectInfo', true); $s3->expectAt(0, 'getObject', array('bin.staticlocal.ch', 'test/downloaded/9f/9fae60fc483eef3a55cbad16b9f13c94eb81a5de.link')); $s3->setReturnValueAt(0, 'getObject', $this->prepareGetObjectResponse(json_encode(array('link' => '/dev/null', 'mtime' => $this->time - 10)))); $s3->expectNever('deleteObject'); $interval = binarypool_config::getBadUrlExpiry() - 10; $exception = new binarypool_exception(122, 400, "File download failed 10 seconds ago. Re-fetching allowed in next time in {$interval} seconds: http://www.patrice.ch/"); $this->expectException($exception); $storage->getURLLastModified('http://www.patrice.ch/', 'test/downloaded/9f/9fae60fc483eef3a55cbad16b9f13c94eb81a5de', 'test_s3'); }