Beispiel #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;
 }
function compressTarGZ($tar_filename, $tar_dir, $compress_level = 5)
{
    $compress_level = $compress_level < 1 || $compress_level > 9 ? 5 : $compress_level;
    $exit_code = 0;
    if (pathinfo($tar_filename, PATHINFO_EXTENSION) == 'gz') {
        $filename = rtrim($tar_filename, '.gz');
    } else {
        $filename = $tar_filename . '.tar.gz';
    }
    $tar = rtrim($tar_filename, '.gz');
    //remove archive if exists
    if (is_file($tar_filename)) {
        unlink($tar_filename);
    }
    if (is_file($filename)) {
        unlink($filename);
    }
    if (is_file($tar)) {
        unlink($tar);
    }
    if (class_exists('PharData')) {
        try {
            $a = new PharData($tar);
            $a->buildFromDirectory($tar_dir);
            // this code creates tar-file
            if (file_exists($tar)) {
                // remove tar-file after zipping
                gzip($tar, $compress_level);
                unlink($tar);
            }
        } catch (Exception $e) {
            $error = new AError($e->getMessage());
            $error->toLog()->toDebug();
            $exit_code = 1;
        }
    } else {
        $exit_code = 1;
    }
    if ($exit_code) {
        $registry = Registry::getInstance();
        $registry->get('load')->library('targz');
        $targz = new Atargz();
        return $targz->makeTar($tar_dir . $tar_filename, $filename, $compress_level);
    } else {
        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;
     }
     $exit_code = 0;
     if (class_exists('PharData')) {
         //remove destination folder first
         //run pathinfo twice for tar.gz. files
         $this->removeDir($dst_dir . pathinfo(pathinfo($tar_filename, PATHINFO_FILENAME), PATHINFO_FILENAME));
         try {
             $phar = new PharData($tar_filename);
             $phar->extractTo($dst_dir, null, true);
         } catch (Exception $e) {
             $error = new AError($e->getMessage());
             $error->toLog()->toDebug();
             $this->error = 'Error: Cannot to unpack file "' . $tar_filename . '". Please, see error log for details. ';
             return false;
         }
     } else {
         $exit_code = 1;
     }
     if ($exit_code) {
         $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;
 }