Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions postgresql_archive/tests/zonky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ async fn test_get_archive_and_extract() -> anyhow::Result<()> {

let out_dir = tempfile::tempdir()?.path().to_path_buf();
let files = extract(url, &archive, &out_dir).await?;
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
assert_eq!(1_023, files.len());
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
assert_eq!(1_021, files.len());
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
assert_eq!(1_021, files.len());
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
assert_eq!(1_021, files.len());
assert!(files.len() > 1_000);
remove_dir_all(&out_dir)?;
Ok(())
}
Expand Down
22 changes: 13 additions & 9 deletions postgresql_commands/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,34 +183,38 @@ impl AsyncCommandExecutor for tokio::process::Command {
/// Execute the command and return the stdout and stderr
async fn execute(&mut self, timeout: Option<Duration>) -> Result<(String, String)> {
debug!("Executing command: {}", self.to_command_string());
let output = match timeout {
Some(duration) => tokio::time::timeout(duration, self.output()).await?,
None => self.output().await,
}?;
let program = self.as_std().get_program().to_string_lossy().to_string();
let stdout: String;
let stderr: String;
let status: ExitStatus;

if OS == "windows" && program.as_str().ends_with("pg_ctl") {
// The pg_ctl process can hang on Windows when attempting to get stdout/stderr.
let mut process = self
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
.spawn()?;
stdout = String::new();
stderr = String::new();
status = process.wait().await?;
} else {
let output = match timeout {
Some(duration) => tokio::time::timeout(duration, self.output()).await?,
None => self.output().await,
}?;
stdout = String::from_utf8_lossy(&output.stdout).into_owned();
stderr = String::from_utf8_lossy(&output.stderr).into_owned();
status = output.status;
}

debug!(
"Result: {}\nstdout: {}\nstderr: {}",
output
.status
.code()
.map_or("None".to_string(), |c| c.to_string()),
status.code().map_or("None".to_string(), |c| c.to_string()),
stdout,
stderr
);

if output.status.success() {
if status.success() {
Ok((stdout, stderr))
} else {
Err(Error::CommandError { stdout, stderr })
Expand Down