コード例 #1
0
 private function doTestGetFileStat($path, $content, $alreadyExists)
 {
     $backendName = $this->backendClass();
     if ($alreadyExists) {
         $this->prepare(array('dir' => dirname($path)));
         $status = $this->create(array('dst' => $path, 'content' => $content));
         $this->assertGoodStatus($status, "Creation of file at {$path} succeeded ({$backendName}).");
         $size = $this->backend->getFileSize(array('src' => $path));
         $time = $this->backend->getFileTimestamp(array('src' => $path));
         $stat = $this->backend->getFileStat(array('src' => $path));
         $this->assertEquals(strlen($content), $size, "Correct file size of '{$path}'");
         $this->assertTrue(abs(time() - wfTimestamp(TS_UNIX, $time)) < 10, "Correct file timestamp of '{$path}'");
         $size = $stat['size'];
         $time = $stat['mtime'];
         $this->assertEquals(strlen($content), $size, "Correct file size of '{$path}'");
         $this->assertTrue(abs(time() - wfTimestamp(TS_UNIX, $time)) < 10, "Correct file timestamp of '{$path}'");
         $this->backend->clearCache(array($path));
         $size = $this->backend->getFileSize(array('src' => $path));
         $this->assertEquals(strlen($content), $size, "Correct file size of '{$path}'");
         $this->backend->preloadCache(array($path));
         $size = $this->backend->getFileSize(array('src' => $path));
         $this->assertEquals(strlen($content), $size, "Correct file size of '{$path}'");
     } else {
         $size = $this->backend->getFileSize(array('src' => $path));
         $time = $this->backend->getFileTimestamp(array('src' => $path));
         $stat = $this->backend->getFileStat(array('src' => $path));
         $this->assertFalse($size, "Correct file size of '{$path}'");
         $this->assertFalse($time, "Correct file timestamp of '{$path}'");
         $this->assertFalse($stat, "Correct file stat of '{$path}'");
     }
 }
コード例 #2
0
	/**
	 * @param FileBackend $src
	 * @param FileBackend $dst
	 * @param string $sPath
	 * @param string $dPath
	 * @return bool
	 */
	protected function filesAreSame( FileBackend $src, FileBackend $dst, $sPath, $dPath ) {
		$skipHash = $this->hasOption( 'skiphash' );
		$srcStat = $src->getFileStat( array( 'src' => $sPath ) );
		$dPathSha1 = sha1( $dPath );
		$dstStat = isset( $this->statCache[$dPathSha1] )
			? $this->statCache[$dPathSha1]
			: $dst->getFileStat( array( 'src' => $dPath ) );
		return (
			is_array( $srcStat ) // sanity check that source exists
			&& is_array( $dstStat ) // dest exists
			&& $srcStat['size'] === $dstStat['size']
			&& ( !$skipHash || $srcStat['mtime'] <= $dstStat['mtime'] )
			&& ( $skipHash || $src->getFileSha1Base36( array( 'src' => $sPath, 'latest' => 1 ) )
				=== $dst->getFileSha1Base36( array( 'src' => $dPath, 'latest' => 1 ) )
			)
		);
	}
コード例 #3
0
ファイル: copyFileBackend.php プロジェクト: paladox/mediawiki
 /**
  * @param FileBackend $src
  * @param FileBackend $dst
  * @param string $sPath
  * @param string $dPath
  * @return bool
  */
 protected function filesAreSame(FileBackend $src, FileBackend $dst, $sPath, $dPath)
 {
     $skipHash = $this->hasOption('skiphash');
     $srcStat = $src->getFileStat(['src' => $sPath]);
     $dPathSha1 = sha1($dPath);
     if ($this->statCache !== null) {
         // All dst files are already in stat cache
         $dstStat = isset($this->statCache[$dPathSha1]) ? $this->statCache[$dPathSha1] : false;
     } else {
         $dstStat = $dst->getFileStat(['src' => $dPath]);
     }
     // Initial fast checks to see if files are obviously different
     $sameFast = is_array($srcStat) && is_array($dstStat) && $srcStat['size'] === $dstStat['size'];
     // More thorough checks against files
     if (!$sameFast) {
         $same = false;
         // no need to look farther
     } elseif (isset($srcStat['md5']) && isset($dstStat['md5'])) {
         // If MD5 was already in the stat info, just use it.
         // This is useful as many objects stores can return this in object listing,
         // so we can use it to avoid slow per-file HEADs.
         $same = $srcStat['md5'] === $dstStat['md5'];
     } elseif ($skipHash) {
         // This mode is good for copying to a backup location or resyncing clone
         // backends in FileBackendMultiWrite (since they get writes second, they have
         // higher timestamps). However, when copying the other way, this hits loads of
         // false positives (possibly 100%) and wastes a bunch of time on GETs/PUTs.
         $same = $srcStat['mtime'] <= $dstStat['mtime'];
     } else {
         // This is the slowest method which does many per-file HEADs (unless an object
         // store tracks SHA-1 in listings).
         $same = $src->getFileSha1Base36(['src' => $sPath, 'latest' => 1]) === $dst->getFileSha1Base36(['src' => $dPath, 'latest' => 1]);
     }
     return $same;
 }