Example #1
0
 function testGetfilePath()
 {
     $file = new FRSFile();
     $filepath = 'path';
     $file->setFilePath($filepath);
     $filename = 'name';
     $file->setFileName($filename);
     $this->assertequal($filepath, $file->getFilePath());
     $file->setFilePath(null);
     $this->assertequal($filename, $file->getFilePath());
 }
 /**
  * Force the upload directory creation, and move the file $file_name in the good directory
  *
  * @global $GLOBALS['codendi_bin_prefix']
  *
  * @param int    $group_id       the ID of the project we want to upload the file
  * @param string $file_name      the name of the file we want to upload
  * @param string $upload_sub_dir the name of the sub-directory the file will be moved in
  *
  * @return Boolean True if file is moved to it's final location (false otherwise)
  */
 public function moveFileForge(FRSFile $file)
 {
     $release = $file->getRelease();
     $project = $release->getProject();
     $unixName = $project->getUnixName(false);
     $upload_sub_dir = $this->getUploadSubDirectory($release);
     $fileName = $file->getFileName();
     $filePath = $this->getResolvedFileName($file->getFileName());
     if (!file_exists($GLOBALS['ftp_frs_dir_prefix'] . '/' . $unixName . '/' . $upload_sub_dir . '/' . escapeshellarg($filePath))) {
         $fileName = escapeshellarg($fileName);
         $cmdFilePath = escapeshellarg($filePath);
         $ret_val = null;
         $exec_res = null;
         $src_dir = $this->getSrcDir($project);
         $cmd = $this->fileforge . " {$fileName} " . $unixName . "/" . $upload_sub_dir . '/' . $cmdFilePath . " {$src_dir} 2>&1";
         exec($cmd, $exec_res, $ret_val);
         // Warning. Posix common value for success is 0 (zero), but in php 0 == false.
         // So "convert" the unix "success" value to the php one (basically 0 => true).
         if ($ret_val == 0) {
             $file->setFileName($upload_sub_dir . '/' . $file->getFileName());
             $file->setFilePath($upload_sub_dir . '/' . $filePath);
             return true;
         }
     }
     return false;
 }
Example #3
0
 /**
  * We should not be able to create a file with the same name,
  * even if the restored one has not yet been moved to the corresponding  pi_rj.
  */
 function testCreateFileAlreadyMarkedToBeRestoredNotYetMoved()
 {
     // Create toto.txt in the release directory
     touch($GLOBALS['ftp_incoming_dir'] . '/toto.txt');
     mkdir($GLOBALS['ftp_frs_dir_prefix'] . '/prj/p123_r456');
     $p = new MockProject($this);
     $p->setReturnValue('getUnixName', 'prj');
     $r = new FRSRelease();
     $r->setReleaseID(456);
     $r->setPackageID(123);
     $r->setGroupID(111);
     $r->setProject($p);
     $f = new FRSFile();
     $f->setFileName('toto.txt');
     $f->setFilePath('toto.txt_1299584210');
     $f->setRelease($r);
     $f->setFileLocation($GLOBALS['ftp_frs_dir_prefix'] . '/prj/p123_r456');
     $ff = new FRSFileFactoryTestCreateFiles();
     $ff->setReturnValue('isFileBaseNameExists', False);
     $ff->setReturnValue('isSameFileMarkedToBeRestored', True);
     try {
         $ff->createFile($f, ~FRSFileFactory::COMPUTE_MD5);
     } catch (Exception $e) {
         $this->assertIsA($e, 'FRSFileToBeRestoredException');
     }
     unlink($GLOBALS['ftp_incoming_dir'] . '/toto.txt');
     rmdir($GLOBALS['ftp_frs_dir_prefix'] . '/prj/p123_r456');
 }