コード例 #1
0
ファイル: FileRepo.php プロジェクト: whysasse/kmwiki
 /**
  * Concatenate a list of temporary files into a target file location.
  *
  * @param array $srcPaths Ordered list of source virtual URLs/storage paths
  * @param string $dstPath Target file system path
  * @param int $flags Bitwise combination of the following flags:
  *   self::DELETE_SOURCE     Delete the source files
  * @return FileRepoStatus
  */
 public function concatenate(array $srcPaths, $dstPath, $flags = 0)
 {
     $this->assertWritableRepo();
     // fail out if read-only
     $status = $this->newGood();
     $sources = array();
     foreach ($srcPaths as $srcPath) {
         // Resolve source to a storage path if virtual
         $source = $this->resolveToStoragePath($srcPath);
         $sources[] = $source;
         // chunk to merge
     }
     // Concatenate the chunks into one FS file
     $params = array('srcs' => $sources, 'dst' => $dstPath);
     $status->merge($this->backend->concatenate($params));
     if (!$status->isOK()) {
         return $status;
     }
     // Delete the sources if required
     if ($flags & self::DELETE_SOURCE) {
         $status->merge($this->quickPurgeBatch($srcPaths));
     }
     // Make sure status is OK, despite any quickPurgeBatch() fatals
     $status->setResult(true);
     return $status;
 }
コード例 #2
0
ファイル: FileRepo.php プロジェクト: Tjorriemorrie/app
 /**
  * Concatenate a list of files into a target file location.
  *
  * @param $srcPaths Array Ordered list of source virtual URLs/storage paths
  * @param $dstPath String Target file system path
  * @param $flags Integer: bitwise combination of the following flags:
  *     self::DELETE_SOURCE     Delete the source files
  * @return FileRepoStatus
  */
 function concatenate($srcPaths, $dstPath, $flags = 0)
 {
     $status = $this->newGood();
     $sources = array();
     $deleteOperations = array();
     // post-concatenate ops
     foreach ($srcPaths as $srcPath) {
         // Resolve source to a storage path if virtual
         $source = $this->resolveToStoragePath($srcPath);
         $sources[] = $source;
         // chunk to merge
         if ($flags & self::DELETE_SOURCE) {
             $deleteOperations[] = array('op' => 'delete', 'src' => $source);
         }
     }
     // Concatenate the chunks into one FS file
     $params = array('srcs' => $sources, 'dst' => $dstPath);
     $status->merge($this->backend->concatenate($params));
     if (!$status->isOK()) {
         return $status;
     }
     // Delete the sources if required
     if ($deleteOperations) {
         $opts = array('force' => true);
         $status->merge($this->backend->doOperations($deleteOperations, $opts));
     }
     // Make sure status is OK, despite any $deleteOperations fatals
     $status->setResult(true);
     return $status;
 }
コード例 #3
0
 private function doTestConcatenate($params, $srcs, $srcsContent, $alreadyExists, $okStatus)
 {
     $backendName = $this->backendClass();
     $expContent = '';
     // Create sources
     $ops = array();
     foreach ($srcs as $i => $source) {
         $this->prepare(array('dir' => dirname($source)));
         $ops[] = array('op' => 'create', 'dst' => $source, 'content' => $srcsContent[$i]);
         $expContent .= $srcsContent[$i];
     }
     $status = $this->backend->doOperations($ops);
     $this->assertGoodStatus($status, "Creation of source files succeeded ({$backendName}).");
     $dest = $params['dst'];
     if ($alreadyExists) {
         $ok = file_put_contents($dest, 'blah...blah...waahwaah') !== false;
         $this->assertEquals(true, $ok, "Creation of file at {$dest} succeeded ({$backendName}).");
     } else {
         $ok = file_put_contents($dest, '') !== false;
         $this->assertEquals(true, $ok, "Creation of 0-byte file at {$dest} succeeded ({$backendName}).");
     }
     // Combine the files into one
     $status = $this->backend->concatenate($params);
     if ($okStatus) {
         $this->assertGoodStatus($status, "Creation of concat file at {$dest} succeeded without warnings ({$backendName}).");
         $this->assertEquals(true, $status->isOK(), "Creation of concat file at {$dest} succeeded ({$backendName}).");
     } else {
         $this->assertEquals(false, $status->isOK(), "Creation of concat file at {$dest} failed ({$backendName}).");
     }
     if ($okStatus) {
         $this->assertEquals(true, is_file($dest), "Dest concat file {$dest} exists after creation ({$backendName}).");
     } else {
         $this->assertEquals(true, is_file($dest), "Dest concat file {$dest} exists after failed creation ({$backendName}).");
     }
     $contents = file_get_contents($dest);
     $this->assertNotEquals(false, $contents, "File at {$dest} exists ({$backendName}).");
     if ($okStatus) {
         $this->assertEquals($expContent, $contents, "Concat file at {$dest} has correct contents ({$backendName}).");
     } else {
         $this->assertNotEquals($expContent, $contents, "Concat file at {$dest} has correct contents ({$backendName}).");
     }
 }