Example #1
0
 /**
  * @param string $tar_filename
  * @param string $tar_dir
  * @param string $filename
  * @return bool
  */
 private function _archive($tar_filename, $tar_dir, $filename)
 {
     //Archive the backup to DIR_BACKUP, delete tmp files in directory $this->backup_dir
     //And create record in the database for created archive.
     //generate errors: No space on device (log to message as error too), No permissons, Others
     //return Success or failed.
     $command = 'tar -C ' . $tar_dir . ' -czvf ' . $tar_filename . ' ' . $filename . ' > /dev/null';
     if (isFunctionAvailable('system')) {
         system($command, $exit_code);
     } else {
         $exit_code = 1;
     }
     if ($exit_code) {
         $this->load->library('targz');
         $targz = new Atargz();
         $targz->makeTar($tar_dir . $filename, $tar_filename);
     }
     if (!file_exists($tar_filename)) {
         $this->processError('Archive error', 'Error: cannot to pack ' . $tar_filename . "\n Exit code:" . $exit_code);
         return false;
     }
     @chmod($tar_filename, 0777);
     $this->_removeDir($tar_dir . $filename);
     return true;
 }
 /**
  * @param string $tar_filename
  * @param string $dst_dir
  * @return boolean
  */
 public function unpack($tar_filename, $dst_dir)
 {
     if (!file_exists($tar_filename)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because it does not exists.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     if (!file_exists($dst_dir) || !is_dir($dst_dir)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because destination directory "' . $dst_dir . '" does not exists.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     if (!is_writable($dst_dir)) {
         $this->error = 'Error: Can\'t unpack file "' . $tar_filename . '" because destination directory "' . $dst_dir . '" have no write permission.';
         $error = new AError($this->error);
         $error->toLog()->toDebug();
         return false;
     }
     $command = 'tar -C ' . $dst_dir . ' -xzvf ' . $tar_filename . ' > /dev/null';
     if (isFunctionAvailable('system')) {
         system($command, $exit_code);
     } else {
         $exit_code = 1;
     }
     if ($exit_code) {
         if (class_exists('PharData')) {
             //remove destination folder first
             $this->removeDir($dst_dir . $this->session->data['package_info']['tmp_dir']);
             try {
                 $phar = new PharData($tar_filename);
                 $phar->extractTo($dst_dir);
             } catch (Exception $e) {
             }
         } else {
             $this->load->library('targz');
             $targz = new Atargz();
             $targz->extractTar($tar_filename, $dst_dir);
         }
     }
     $this->chmod_R($dst_dir . $this->session->data['package_info']['tmp_dir'], 0777, 0777);
     return true;
 }