/** * Constructor * * @param FRSFile $file The file that triggered the exception * @param Integer $code Numeric code */ public function __construct($file, $code = 0) { parent::__construct($GLOBALS['Language']->getText('file_admin_editreleases', 'illegal_file_name') . ': ' . $file->getFileName(), $code); }
/** * 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; }
/** * file_to_soap : return the soap FRSFile structure giving a PHP FRSFile Object. * @access private * * WARNING : We check the permissions here : only the readable files are returned. * * @param Object{FRSFile} $file the file to convert. * @return array the SOAPFRSFile corresponding to the FRSFile Object */ function file_to_soap(FRSFile $file) { $return = null; if ($file->isError()) { //skip if error } else { // for the moment, no permissions on files $return = array('file_id' => $file->getFileID(), 'release_id' => $file->getReleaseID(), 'file_name' => $file->getFileName(), 'file_size' => $file->getFileSize(), 'type_id' => $file->getTypeID(), 'processor_id' => $file->getProcessorID(), 'release_time' => $file->getReleaseTime(), 'post_date' => $file->getPostDate(), 'computed_md5' => $file->getComputedMd5(), 'reference_md5' => $file->getReferenceMd5(), 'user_id' => $file->getUserID(), 'comment' => $file->getComment()); } return $return; }
function testCreateFileCompareMD5Checksums() { $r = new FRSRelease(); $r->setReleaseID(456); $r->setPackageID(123); $r->setGroupID(111); $ff = new FRSFileFactoryTestCreateFiles(); $f = new FRSFile(); $f->setRelease($r); $f->setFileName('toto.txt'); touch($GLOBALS['ftp_incoming_dir'] . '/toto.txt'); $path = $GLOBALS['ftp_incoming_dir'] . '/' . $f->getFileName(); $f->setReferenceMd5('d41d8cd98f00b204e9800998ecf8427e'); try { $ff->createFile($f, FRSFileFactory::COMPUTE_MD5); } catch (Exception $e) { $this->assertIsA($e, 'FRSFileMD5SumException'); } $this->assertNotNull($f->getComputedMd5()); $this->assertTrue(FRSFileFactory::compareMd5Checksums($f->getComputedMd5(), $f->getReferenceMd5())); unlink($GLOBALS['ftp_incoming_dir'] . '/toto.txt'); }