lib/TOGoS/Fetcher.php
public function cache( $urn ) {
		$base32Sha1 = TOGoS_Fetcher_HashUtil::extractBase32Sha1($urn);
		$psp = substr($base32Sha1,0,2)."/".$base32Sha1;
		$dataDir = "{$this->cacheRepoDir}/data";
		if( is_dir($dataDir) ) {
			foreach( scandir($dataDir) as $sector ) {
				if( $sector[0] == '.' ) continue;
				$existing = "{$dataDir}/{$sector}/{$psp}";
				if( file_exists($existing) ) return $existing;
			}
			// For compatibility with some buggy systems...
			$existing = "{$dataDir}/{$psp}";
			if( file_exists($existing) ) return $existing;
		}
		
		$destFile = "{$dataDir}/{$this->cacheSector}/{$psp}";
		$tempFile = $this->tempFile($destFile);
		try {
			$size = $this->download( $urn, $tempFile );
		} catch( Exception $e ) {
			unlink($tempFile);
			throw $e;
		}
		
		return $this->completeDownload( $tempFile, $destFile, $size );
	}
public function cache( $urn ) {
		$base32Sha1 = TOGoS_Fetcher_HashUtil::extractBase32Sha1($urn);
		$psp = substr($base32Sha1,0,2)."/".$base32Sha1;
		$dataDir = "{$this->cacheRepoDir}/data";
		if( is_dir($dataDir) ) {
			foreach( scandir($dataDir) as $sector ) {
				if( $sector[0] == '.' ) continue;
				$existing = "{$dataDir}/{$sector}/{$psp}";
				if( file_exists($existing) ) return $existing;
			}
			// For compatibility with some buggy systems...
			$existing = "{$dataDir}/{$psp}";
			if( file_exists($existing) ) return $existing;
		}
		
		$destFile = "{$dataDir}/{$this->cacheSector}/{$psp}";
		$tempFile = $this->tempFile($destFile);
		try {
			$size = $this->download( $urn, $tempFile );
		} catch( Exception $e ) {
			unlink($tempFile);
			throw $e;
		}
		
		return $this->completeDownload( $tempFile, $destFile, $size );
	}
public function cache ( $ urn ) { $ base32Sha1 = TOGoS_Fetcher_HashUtil :: extractBase32Sha1 ( $ urn ) ; $ psp = substr ( $ base32Sha1 , 0 , 2 ) . "/" . $ base32Sha1 ; $ dataDir = "{$this->cacheRepoDir}/data" ; if ( is_dir ( $ dataDir ) ) { foreach ( scandir ( $ dataDir ) as $ sector ) { if ( $ sector [ 0 ] == '.' ) continue ; $ existing = "{$dataDir}/{$sector}/{$psp}" ; if ( file_exists ( $ existing ) ) return $ existing ; } // For compatibility with some buggy systems... $ existing = "{$dataDir}/{$psp}" ; if ( file_exists ( $ existing ) ) return $ existing ; } $ destFile = "{$dataDir}/{$this->cacheSector}/{$psp}" ; $ tempFile = $ this -> tempFile ( $ destFile ) ; try { $ size = $ this -> download ( $ urn , $ tempFile ) ; } catch ( Exception $ e ) { unlink ( $ tempFile ) ; throw $ e ; } return $ this -> completeDownload ( $ tempFile , $ destFile , $ size ) ; }
Returns the path of the file, if successfully cached
Returns the path of the file if successfully cached