コード例 #1
0
/**
 * Read the Bag, unpack it, drop files into the Dropbox files directory.
 *
 * @param string $filename The name of the uploaded bag.
 *
 * @return boolean $success True if the read succeeds.
 */
function bagithelpers_doReadBagIt($filename)
{
    $success = false;
    $bag = new BagIt(BAGIT_TMP_DIRECTORY . '/' . $filename);
    $bag->fetch->download();
    $bag->update();
    $bag->validate();
    if (count($bag->getBagErrors()) == 0) {
        // Copy each of the files.
        foreach ($bag->getBagContents() as $file) {
            copy($file, BASE_DIR . '/plugins/Dropbox/files/' . basename($file));
        }
        $success = true;
    }
    return $success;
}
コード例 #2
0
ファイル: testbagit.php プロジェクト: Dragonpurse/mediamosa
 public function testValidateChecksum()
 {
     $tmp = tmpdir();
     try {
         mkdir($tmp);
         file_put_contents($tmp . "/manifest-sha1.txt", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa data/missing.txt\n");
         mkdir($tmp . '/data');
         touch($tmp . '/data/missing.txt');
         $bag = new BagIt($tmp);
         $bag->validate();
         $bagErrors = $bag->getBagErrors();
         $this->assertFalse($bag->isValid());
         $this->assertTrue(seenAtKey($bagErrors, 0, 'data/missing.txt'));
         $this->assertTrue(seenAtKey($bagErrors, 1, 'Checksum mismatch.'));
     } catch (Exception $e) {
         rrmdir($tmp);
         throw $e;
     }
     rrmdir($tmp);
 }
コード例 #3
0
 /**
  * This is the use case for consuming a bag from someone else. The user 
  * does these actions:
  *
  * <ol>
  * <li>Open the bag;</li>
  * <li>Validate the downloaded contents;</li>
  * <li>Fetch on-line items in the bag;</li>
  * <li>Validate the bag's contents; and</li>
  * <li>Copy items from the bag onto the local disk.</li>
  * </ol>
  */
 public function testBagConsumer()
 {
     $srcbag = __DIR__ . '/TestBag.tgz';
     // 1. Open the bag;
     $bag = new BagIt($srcbag);
     $this->queueRm($bag->bagDirectory);
     $this->assertTrue($bag->isValid());
     $this->assertTrue($bag->isExtended());
     $bagInfo = $bag->getBagInfo();
     $this->assertEquals('0.96', $bagInfo['version']);
     $this->assertEquals('UTF-8', $bagInfo['encoding']);
     $this->assertEquals('sha1', $bagInfo['hash']);
     $this->assertEquals('sha1', $bag->getHashEncoding());
     $this->assertEquals(7, count($bag->getBagContents()));
     $this->assertEquals(0, count($bag->getBagErrors()));
     // 2. Validate the downloaded contents;
     $bag->validate();
     $this->assertEquals(0, count($bag->getBagErrors()));
     // 3. Fetch on-line items in the bag;
     $bag->fetch->download();
     $bag->update();
     $bag->validate();
     $this->assertEquals(8, count($bag->getBagContents()));
     // 4. Validate the bag's contents; and
     $this->assertEquals(0, count($bag->getBagErrors()));
     // 5. Copy items from the bag onto the local disk.
     $tmpdir = tmpdir();
     mkdir($tmpdir);
     $this->queueRm($tmpdir);
     foreach ($bag->getBagContents() as $bagFile) {
         $basename = basename($bagFile);
         copy($bagFile, "{$tmpdir}/{$basename}");
     }
     $this->assertEquals(count($bag->getBagContents()) + 2, count(scandir($tmpdir)));
     $this->assertEquals(count($bag->manifest->getData()) + 2, count(scandir($tmpdir)));
 }