コード例 #1
0
 private function doTestDoOperationsFailing()
 {
     $base = self::baseStorePath();
     $fileA = "{$base}/unittest-cont2/a/b/fileA.txt";
     $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
     $fileB = "{$base}/unittest-cont2/a/b/fileB.txt";
     $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
     $fileC = "{$base}/unittest-cont2/a/b/fileC.txt";
     $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
     $fileD = "{$base}/unittest-cont2/a/b/fileD.txt";
     $this->prepare(array('dir' => dirname($fileA)));
     $this->create(array('dst' => $fileA, 'content' => $fileAContents));
     $this->prepare(array('dir' => dirname($fileB)));
     $this->create(array('dst' => $fileB, 'content' => $fileBContents));
     $this->prepare(array('dir' => dirname($fileC)));
     $this->create(array('dst' => $fileC, 'content' => $fileCContents));
     $status = $this->backend->doOperations(array(array('op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1), array('op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1), array('op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1), array('op' => 'move', 'src' => $fileC, 'dst' => $fileD), array('op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1), array('op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1), array('op' => 'delete', 'src' => $fileD), array('op' => 'null')), array('force' => 1));
     $this->assertNotEquals(array(), $status->errors, "Operation had warnings");
     $this->assertEquals(true, $status->isOK(), "Operation batch succeeded");
     $this->assertEquals(8, count($status->success), "Operation batch has correct success array");
     $this->assertEquals(false, $this->backend->fileExists(array('src' => $fileB)), "File does not exist at {$fileB}");
     $this->assertEquals(false, $this->backend->fileExists(array('src' => $fileD)), "File does not exist at {$fileD}");
     $this->assertEquals(true, $this->backend->fileExists(array('src' => $fileA)), "File does not exist at {$fileA}");
     $this->assertEquals(true, $this->backend->fileExists(array('src' => $fileC)), "File exists at {$fileC}");
     $this->assertEquals($fileBContents, $this->backend->getFileContents(array('src' => $fileA)), "Correct file contents of {$fileA}");
     $this->assertEquals(strlen($fileBContents), $this->backend->getFileSize(array('src' => $fileA)), "Correct file size of {$fileA}");
     $this->assertEquals(wfBaseConvert(sha1($fileBContents), 16, 36, 31), $this->backend->getFileSha1Base36(array('src' => $fileA)), "Correct file SHA-1 of {$fileA}");
 }
コード例 #2
0
ファイル: FileRepo.php プロジェクト: nahoj/mediawiki_ynh
	/**
	 * Checks existence of an array of files.
	 *
	 * @param array $files Virtual URLs (or storage paths) of files to check
	 * @return array|bool Either array of files and existence flags, or false
	 */
	public function fileExistsBatch( array $files ) {
		$result = array();
		foreach ( $files as $key => $file ) {
			$file = $this->resolveToStoragePath( $file );
			$result[$key] = $this->backend->fileExists( array( 'src' => $file ) );
		}
		return $result;
	}
コード例 #3
0
ファイル: FileRepo.php プロジェクト: whysasse/kmwiki
 /**
  * Checks existence of an array of files.
  *
  * @param array $files Virtual URLs (or storage paths) of files to check
  * @return array Map of files and existence flags, or false
  */
 public function fileExistsBatch(array $files)
 {
     $paths = array_map(array($this, 'resolveToStoragePath'), $files);
     $this->backend->preloadFileStat(array('srcs' => $paths));
     $result = array();
     foreach ($files as $key => $file) {
         $path = $this->resolveToStoragePath($file);
         $result[$key] = $this->backend->fileExists(array('src' => $path));
     }
     return $result;
 }
コード例 #4
0
ファイル: FileRepo.php プロジェクト: Tjorriemorrie/app
 /**
  * Checks existence of an array of files.
  *
  * @param $files Array: Virtual URLs (or storage paths) of files to check
  * @param $flags Integer: bitwise combination of the following flags:
  *     self::FILES_ONLY     Mark file as existing only if it is a file (not directory)
  * @return array|bool Either array of files and existence flags, or false
  */
 public function fileExistsBatch($files, $flags = 0)
 {
     $result = array();
     foreach ($files as $key => $file) {
         if (self::isVirtualUrl($file)) {
             $file = $this->resolveVirtualUrl($file);
         }
         if (FileBackend::isStoragePath($file)) {
             $result[$key] = $this->backend->fileExists(array('src' => $file));
         } else {
             if ($flags & self::FILES_ONLY) {
                 $result[$key] = is_file($file);
                 // FS only
             } else {
                 $result[$key] = file_exists($file);
                 // FS only
             }
         }
     }
     return $result;
 }
コード例 #5
0
 protected function filesAreSame(FileBackend $src, FileBackend $dst, $sPath, $dPath)
 {
     $skipHash = $this->hasOption('skiphash');
     return $src->fileExists(array('src' => $sPath, 'latest' => 1)) === $dst->fileExists(array('src' => $dPath, 'latest' => 1)) && $src->getFileSize(array('src' => $sPath, 'latest' => 1)) === $dst->getFileSize(array('src' => $dPath, 'latest' => 1)) && ($skipHash || $src->getFileSha1Base36(array('src' => $sPath, 'latest' => 1)) === $dst->getFileSha1Base36(array('src' => $dPath, 'latest' => 1)));
 }