Example #1
0
 function testWithBigFile()
 {
     //$this->assertTrue(is_writeable($this->writePath), "$this->writePath should be writable");
     $writeFile = fopen(PHP_BigFile::stream($this->writePath), 'wb');
     $this->assertTrue($writeFile);
     $file = new FRSFile();
     $file->file_location = $this->readPath;
     $fileSize = PHP_BigFile::getSize($this->readPath);
     $chunkSize = 8 * 1024 * 1024;
     $nbChunks = ceil($fileSize / $chunkSize);
     for ($i = 0; $i < $nbChunks; $i++) {
         $data = $file->getContent($i * $chunkSize, $chunkSize);
         $written = fwrite($writeFile, $data);
         $this->assertEqual(strlen($data), $written);
     }
     $this->assertIdentical(md5_file($this->readPath), md5_file($this->writePath));
 }
Example #2
0
 function getIncomingFileSize($name)
 {
     return PHP_BigFile::getSize($GLOBALS['ftp_incoming_dir'] . '/' . $name);
 }
 /**
  * Create a new file based on given objects
  *
  * Given a "transient" file object, physically move the file from it's landing zone to
  * it's release area and create the corresponding entry in the database.
  *
  * @param FRSFile    $file    File to create
  *
  * @return FRSFile
  */
 public function createFile(FRSFile $file, $extraFlags = self::COMPUTE_MD5)
 {
     $rule = new Rule_FRSFileName();
     if (!$rule->isValid($file->getFileName())) {
         throw new FRSFileIllegalNameException($file);
     }
     $rel = $file->getRelease();
     if ($this->isFileBaseNameExists($file->getFileName(), $rel->getReleaseID(), $rel->getGroupID())) {
         throw new FRSFileExistsException($file);
     }
     if ($this->isSameFileMarkedToBeRestored($file->getFileName(), $rel->getReleaseID(), $rel->getGroupID())) {
         throw new FRSFileToBeRestoredException($file);
     }
     clearstatcache();
     $filePath = $this->getSrcDir($rel->getProject()) . '/' . $file->getFileName();
     if (!file_exists($filePath)) {
         throw new FRSFileInvalidNameException($file);
     }
     if (0 != ($extraFlags & self::COMPUTE_MD5)) {
         $file->setComputedMd5(PHP_BigFile::getMd5Sum($filePath));
         if (!$this->compareMd5Checksums($file->getComputedMd5(), $file->getReferenceMd5())) {
             throw new FRSFileMD5SumException($file);
         }
     }
     $file->setFileSize(PHP_BigFile::getSize($filePath));
     $file->setStatus('A');
     if ($this->moveFileForge($file)) {
         $fileId = $this->create($file->toArray());
         if ($fileId) {
             $file->setFileID($fileId);
             return $file;
         } else {
             throw new FRSFileDbException($file);
         }
     } else {
         throw new FRSFileForgeException($file);
     }
 }