Ejemplo n.º 1
0
 /**
  * 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;
 }