Skip to content

Commit 00e2fa4

Browse files
Use 'pipefail' feature
In order to determine if a command in a command pipeline failed the 'set -o pipefail' option has to be set. Sadly not all shells support it. But the most public ones do and since nothing breaks if it is not available we should be fine using it. Issue #180
1 parent 27e043c commit 00e2fa4

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"ext-json": "*",
4242
"ext-spl": "*",
4343
"sebastian/environment": "~1.1|~2.0|~3.0|~4.0",
44-
"sebastianfeldmann/cli": "~2.0",
44+
"sebastianfeldmann/cli": "~2.2",
4545
"phpmailer/phpmailer": "~6.0",
4646
"symfony/event-dispatcher": "~2.6|~3.0|~4.0"
4747
},

src/Cli/Executable/Abstraction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ protected function setup(string $cmd, string $path = '')
6464
*/
6565
public function getCommandLine() : CommandLine
6666
{
67-
return $this->createCommandLine();
67+
$process = $this->createCommandLine();
68+
$process->pipeFail(true);
69+
70+
return $process;
6871
}
6972

7073
/**

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public function testPipeCompression()
6565
$executable = $mysqldump->getExecutable($target);
6666

6767
$this->assertEquals(
68-
PHPBU_TEST_BIN . '/mysqldump --all-databases | ' . PHPBU_TEST_BIN . '/gzip > /tmp/foo.sql.gz',
68+
'set -o pipefail; '
69+
. PHPBU_TEST_BIN . '/mysqldump --all-databases | '
70+
. PHPBU_TEST_BIN . '/gzip > /tmp/foo.sql.gz',
6971
$executable->getCommand()
7072
);
7173
}

tests/phpbu/Backup/Source/TarTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ public function testThrottle()
182182
$exec = $tar->getExecutable($target);
183183

184184
$this->assertEquals(
185-
PHPBU_TEST_BIN . '/tar -c -C \''
185+
'set -o pipefail; '
186+
. PHPBU_TEST_BIN . '/tar -c -C \''
186187
. dirname(__DIR__) . '\' \''
187188
. basename(__DIR__) . '\''
188189
. ' | pv -qL \'1m\' > /tmp/backup.tar',

tests/phpbu/Cli/Executable/MysqldumpTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function testCompressor()
252252
$mysqldump->compressOutput($compression)->dumpTo('/tmp/foo.mysql');
253253

254254
$this->assertEquals(
255-
$path . '/mysqldump --all-databases | ' . $path . '/gzip > /tmp/foo.mysql.gz',
255+
'set -o pipefail; ' . $path . '/mysqldump --all-databases | ' . $path . '/gzip > /tmp/foo.mysql.gz',
256256
$mysqldump->getCommand()
257257
);
258258
}

tests/phpbu/Cli/Executable/TarTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ public function testThrottle()
169169
->throttle('1m');
170170

171171
$this->assertEquals(
172-
PHPBU_TEST_BIN . '/tar -jc -C \'' . $tarC . '\' \'' . $tarD . '\'' .
173-
' | pv -qL \'1m\' > /tmp/foo.tar.bzip2',
172+
'set -o pipefail; '
173+
. PHPBU_TEST_BIN . '/tar -jc -C \'' . $tarC . '\' \'' . $tarD . '\''
174+
. ' | pv -qL \'1m\' > /tmp/foo.tar.bzip2',
174175
$tar->getCommand()
175176
);
176177
}
@@ -191,7 +192,8 @@ public function testThrottleAndRemoveSourceDir()
191192
->throttle('1m');
192193

193194
$this->assertEquals(
194-
'(' . PHPBU_TEST_BIN . '/tar -jc -C \'' . $tarC . '\' \'' . $tarD . '\''
195+
'set -o pipefail; '
196+
. '(' . PHPBU_TEST_BIN . '/tar -jc -C \'' . $tarC . '\' \'' . $tarD . '\''
195197
. ' && rm -rf \'' . $dir . '\')'
196198
. ' | pv -qL \'1m\' > /tmp/foo.tar.bzip2',
197199
$tar->getCommand()

0 commit comments

Comments
 (0)