Skip to content

Commit

Permalink
#91 - Support 'directory' as an archive type with rsync as the overwr…
Browse files Browse the repository at this point in the history
…ite method
  • Loading branch information
stackpr committed Mar 29, 2017
1 parent de669a6 commit 847dc45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Configuration/ConfigurationDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function __construct(&$settings) {
"flatten" => 1,
),
),
'pdf->(zip/png)' => array(
'pdf->(zip/png|directory/png)' => array(
'imagemagick:default' => array(
'#engine' => 'Convert\\ImageMagick',
"colorspace" => "sRGB",
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Convert/ImageMagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ImageMagick extends EngineBase {
);

public function convertFile($source, $destination) {
if (preg_match('@zip/(?<ext>.*)$@s', $this->conversion[1], $arr)) {
if (preg_match('@(?:zip|directory)/(?<ext>.*)$@s', $this->conversion[1], $arr)) {
// Create a temp directory and convert the images.
$ext = $arr['ext'];
$imageArchive = new Archive($this);
Expand Down
18 changes: 17 additions & 1 deletion src/Engine/Helper/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,26 @@ public function save($destination) {
Shell::arg($temp, Shell::SHELL_ARG_BASIC),
Shell::arg('.', Shell::SHELL_SAFE),
);
echo $this->engine->shell($cmd);
$this->engine->shell($cmd);
rename($temp, $destination);
break;

case 'directory':
if (!is_dir($destination)) {
mkdir($destination);
if (!is_dir($destination)) {
throw new \ErrorException("Unable to create the destination directory.");
}
}
$cmd = array(
$this->engine->shellWhich('rsync'),
Shell::arg('a', Shell::SHELL_ARG_BOOL_SGL, TRUE),
Shell::arg(rtrim($this->getTempDirectory(), '/') . '/', Shell::SHELL_ARG_BASIC),
Shell::arg(rtrim($destination, '/') . '/', Shell::SHELL_ARG_BASIC),
);
$this->engine->shell($cmd);
break;

default:
throw new \InvalidArgumentException("Invalid archive format spec: $ext");
}
Expand Down

0 comments on commit 847dc45

Please sign in to comment.