-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
514b837
commit 0fd6a5d
Showing
11 changed files
with
179 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Distill package. | ||
* | ||
* (c) Raul Fraile <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Distill\Method\Command; | ||
|
||
use Distill\Exception; | ||
use Distill\Format; | ||
|
||
/** | ||
* Extracts files from shar archives. | ||
* | ||
* @author Raul Fraile <[email protected]> | ||
*/ | ||
class Unshar extends AbstractCommandMethod | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function extract($file, $target, Format\FormatInterface $format) | ||
{ | ||
$this->checkSupport($format); | ||
|
||
$this->getFilesystem()->mkdir($target); | ||
|
||
$command = sprintf('cd %s && sh %s', escapeshellarg($target), escapeshellarg($file)); | ||
|
||
$exitCode = $this->executeCommand($command); | ||
|
||
return $this->isExitCodeSuccessful($exitCode); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isSupported() | ||
{ | ||
if (null === $this->supported) { | ||
$this->supported = $this->existsCommand('sh'); | ||
} | ||
|
||
return $this->supported; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getClass() | ||
{ | ||
return get_class(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isFormatSupported(Format\FormatInterface $format = null) | ||
{ | ||
return $format instanceof Format\Simple\Shar; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Distill\Tests\Format\Simple; | ||
|
||
use Distill\Format\Simple\Shar; | ||
use Distill\Tests\Format\AbstractFormatTest; | ||
|
||
class SharTest extends AbstractFormatTest | ||
{ | ||
public function setUp() | ||
{ | ||
$this->format = new Shar(); | ||
} | ||
|
||
public function testCompressionRatioLevelIsValid() | ||
{ | ||
$this->assertLevelValid($this->format->getCompressionRatioLevel()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Distill\Tests\Method\Command; | ||
|
||
use Distill\Method; | ||
use Distill\Format; | ||
use Distill\Tests\Method\AbstractMethodTest; | ||
|
||
class UnsharTest extends AbstractMethodTest | ||
{ | ||
public function setUp() | ||
{ | ||
$this->method = new Method\Command\Unshar(); | ||
|
||
if (false === $this->method->isSupported()) { | ||
$this->markTestSkipped('The unshar command is not installed'); | ||
} | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testExtractCorrectSharFile() | ||
{ | ||
$target = $this->getTemporaryPath(); | ||
$this->clearTemporaryPath(); | ||
|
||
$response = $this->extract('file_ok.shar', $target, new Format\Simple\Shar()); | ||
|
||
$this->assertTrue($response); | ||
$this->assertUncompressed($target, 'file_ok.shar'); | ||
$this->clearTemporaryPath(); | ||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This is a shell archive. Save it in a file, remove anything before | ||
# this line, and then unpack it by entering "sh file". Note, it may | ||
# create directories; files and directories will be owned by you and | ||
# have default permissions. | ||
# | ||
# This archive contains: | ||
# | ||
# 1.txt | ||
# 2.txt | ||
# 3.txt | ||
# | ||
echo x - 1.txt | ||
sed 's/^X//' >1.txt << 'END-of-1.txt' | ||
X1.txt file | ||
END-of-1.txt | ||
echo x - 2.txt | ||
sed 's/^X//' >2.txt << 'END-of-2.txt' | ||
X2.txt file | ||
END-of-2.txt | ||
echo x - 3.txt | ||
sed 's/^X//' >3.txt << 'END-of-3.txt' | ||
X3.txt file | ||
END-of-3.txt | ||
exit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/1.txt|1.txt file | ||
/2.txt|2.txt file | ||
/3.txt|3.txt file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,6 @@ $DIR/epub.sh | |
$DIR/jar.sh | ||
$DIR/dmg.sh | ||
$DIR/iso.sh | ||
$DIR/ar+deb.sh | ||
$DIR/ar+deb.sh | ||
$DIR/cpio.sh | ||
$DIR/shar.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
################################################################################ | ||
# Initial configuration | ||
################################################################################ | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
FILES_DIR="$DIR/../files" | ||
|
||
################################################################################ | ||
# Clean files | ||
################################################################################ | ||
rm -f $FILES_DIR/file_ok.shar $FILES_DIR/file_fake.shar | ||
|
||
################################################################################ | ||
# Generate files | ||
################################################################################ | ||
|
||
# shar: fake file | ||
dd if=/dev/urandom of=$FILES_DIR/file_fake.shar bs=1 count=1240 | ||
|
||
# shar: regular file | ||
cd $FILES_DIR/uncompressed | ||
shar 1.txt 2.txt 3.txt > ../file_ok.shar | ||
printf "\1.txt|1.txt file\n\2.txt|2.txt file\n\3.txt|3.txt file" > ../file_ok.shar.key |