summaryrefslogtreecommitdiffstats
path: root/src/poem/recite/ps.rs
diff options
context:
space:
mode:
authorRory Dudley2024-04-06 23:32:30 -0600
committerRory Dudley2024-04-06 23:32:30 -0600
commitf5db8d64828db756b80b6022322265a2b4f1c11b (patch)
tree68555331ad4dcab6c571c4016c1e8baa3a351ae7 /src/poem/recite/ps.rs
parent1415c8f9b89699000ef8d864ff8f0e1bebca4a5f (diff)
downloaddwarvish-f5db8d64828db756b80b6022322265a2b4f1c11b.tar.gz
Capture STDOUT as bytes, and convert to string when necessary
Previously, the recite() function created the 'out' variable, which was a String, that got passed to the various incant functions, in order to capture STDOUT in certain situations. In cases where STDOUT was captured, it was first converted to a String, and then appended to the 'out' variable, by means of String::from_utf8_lossy(). This works for basic text, however, does NOT work for binary data. This becomes problematic, when for example, downling a tar file with curl/wget, that is then piped ('|') to the tar program. Using from_utf8_lossy() in this case can corrupt the tar file. This patch makes it so that out is stored as bytes by default, and only converted to a String when necessary.
Diffstat (limited to 'src/poem/recite/ps.rs')
-rw-r--r--src/poem/recite/ps.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/poem/recite/ps.rs b/src/poem/recite/ps.rs
index 61ed66d..5700ae8 100644
--- a/src/poem/recite/ps.rs
+++ b/src/poem/recite/ps.rs
@@ -17,7 +17,7 @@ macro_rules! task {
.spawn()?;
let stdin = child.stdin.as_mut().ok_or(io::ErrorKind::BrokenPipe)?;
- stdin.write_all(&$out.as_bytes())?;
+ stdin.write_all(&$out)?;
$out.clear();
child
@@ -50,7 +50,7 @@ macro_rules! ctask {
.spawn()?;
let stdin = child.stdin.as_mut().ok_or(io::ErrorKind::BrokenPipe)?;
- stdin.write_all(&$out.as_bytes())?;
+ stdin.write_all(&$out)?;
$out.clear();
child
@@ -83,7 +83,7 @@ macro_rules! btask {
.spawn()?;
let stdin = child.stdin.as_mut().ok_or(io::ErrorKind::BrokenPipe)?;
- stdin.write_all(&$out.as_bytes())?;
+ stdin.write_all(&$out)?;
$out.clear();
child
@@ -119,7 +119,7 @@ macro_rules! iobtask {
.spawn()?;
let stdin = child.stdin.as_mut().ok_or(io::ErrorKind::BrokenPipe)?;
- stdin.write_all(&$out.as_bytes())?;
+ stdin.write_all(&$out)?;
$out.clear();
child