mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-28 14:04:45 -04:00
Shell packaging now uses passthru.
This commit is contained in:
parent
b3ffd4f621
commit
a87500309a
4 changed files with 90 additions and 41 deletions
|
@ -2,11 +2,10 @@
|
|||
|
||||
class Archive {
|
||||
|
||||
private static $TAR_CMD = "$(cd [ROOTDIR] && tar --no-recursion -cf [TARGET] [DIRS] [FILES])";
|
||||
private static $ZIP_CMD = "$(cd [ROOTDIR] && zip [TARGET] [FILES])";
|
||||
private static $TAR_PASSTHRU_CMD = "cd [ROOTDIR] && tar --no-recursion -c -- [DIRS] [FILES]";
|
||||
private static $ZIP_PASSTHRU_CMD = "cd [ROOTDIR] && zip - -- [FILES]";
|
||||
|
||||
|
||||
private $app, $dirs, $files, $sc401;
|
||||
private $app, $dirs, $files;
|
||||
|
||||
|
||||
public function __construct($app) {
|
||||
|
@ -15,7 +14,7 @@ class Archive {
|
|||
}
|
||||
|
||||
|
||||
public function create($execution, $format, $hrefs) {
|
||||
public function create($format, $hrefs) {
|
||||
|
||||
$this->dirs = array();
|
||||
$this->files = array();
|
||||
|
@ -29,33 +28,12 @@ class Archive {
|
|||
$target = $this->app->get_cache_abs_path() . "/package-" . sha1(microtime(true) . rand()) . "." . $format;
|
||||
|
||||
try {
|
||||
if ($execution === "shell") {
|
||||
|
||||
if ($format === "tar") {
|
||||
$cmd = Archive::$TAR_CMD;
|
||||
} else if ($format === "zip") {
|
||||
$cmd = Archive::$ZIP_CMD;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
// $cmd = str_replace("[ROOTDIR]", "\"" . $this->app->get_root_abs_path() . "\"", $cmd);
|
||||
$cmd = str_replace("[ROOTDIR]", "\"" . $this->app->get_abs_path() . "\"", $cmd);
|
||||
$cmd = str_replace("[TARGET]", "\"" . $target . "\"", $cmd);
|
||||
$cmd = str_replace("[DIRS]", count($this->dirs) ? "\"" . implode("\" \"", array_values($this->dirs)) . "\"" : "", $cmd);
|
||||
$cmd = str_replace("[FILES]", count($this->files) ? "\"" . implode("\" \"", array_values($this->files)) . "\"" : "", $cmd);
|
||||
|
||||
shell_exec($cmd);
|
||||
|
||||
} else if ($execution === "php") {
|
||||
|
||||
$archive = new PharData($target);
|
||||
foreach ($this->dirs as $archived_dir) {
|
||||
$archive->addEmptyDir($archived_dir);
|
||||
}
|
||||
foreach ($this->files as $real_file => $archived_file) {
|
||||
$archive->addFile($real_file, $archived_file); // very, very slow :/
|
||||
}
|
||||
|
||||
$archive = new PharData($target);
|
||||
foreach ($this->dirs as $archived_dir) {
|
||||
$archive->addEmptyDir($archived_dir);
|
||||
}
|
||||
foreach ($this->files as $real_file => $archived_file) {
|
||||
$archive->addFile($real_file, $archived_file); // very, very slow :/
|
||||
}
|
||||
} catch (Exeption $err) {
|
||||
return 500;
|
||||
|
@ -65,6 +43,40 @@ class Archive {
|
|||
}
|
||||
|
||||
|
||||
public function shell_passthru($format, $hrefs) {
|
||||
|
||||
$this->dirs = array();
|
||||
$this->files = array();
|
||||
|
||||
$this->add_hrefs($hrefs);
|
||||
|
||||
if (count($this->dirs) === 0 && count($this->files) === 0) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if ($format === "tar") {
|
||||
$cmd = Archive::$TAR_PASSTHRU_CMD;
|
||||
} else if ($format === "zip") {
|
||||
$cmd = Archive::$ZIP_PASSTHRU_CMD;
|
||||
} else {
|
||||
return 500;
|
||||
}
|
||||
$cmd = str_replace("[ROOTDIR]", "\"" . $this->app->get_abs_path() . "\"", $cmd);
|
||||
$cmd = str_replace("[DIRS]", count($this->dirs) ? "\"" . implode("\" \"", array_values($this->dirs)) . "\"" : "", $cmd);
|
||||
$cmd = str_replace("[FILES]", count($this->files) ? "\"" . implode("\" \"", array_values($this->files)) . "\"" : "", $cmd);
|
||||
|
||||
passthru($cmd);
|
||||
|
||||
} catch (Exeption $err) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
private function add_hrefs($hrefs) {
|
||||
|
||||
foreach ($hrefs as $href) {
|
||||
|
@ -77,7 +89,6 @@ class Archive {
|
|||
if ($code == App::$MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
|
||||
|
||||
$real_file = $this->app->get_abs_path($href);
|
||||
// $archived_file = preg_replace("!^" . normalize_path($this->app->get_root_abs_path(), true) . "!", "", $real_file);
|
||||
$archived_file = preg_replace("!^" . normalize_path($this->app->get_abs_path(), true) . "!", "", $real_file);
|
||||
|
||||
if (is_dir($real_file)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue