Skip to content

Commit 581bc4e

Browse files
committed
fix: use tokio::process::spawn() for pc_ctl on Windows
1 parent 01977bd commit 581bc4e

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

postgresql_commands/src/traits.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,34 +183,38 @@ impl AsyncCommandExecutor for tokio::process::Command {
183183
/// Execute the command and return the stdout and stderr
184184
async fn execute(&mut self, timeout: Option<Duration>) -> Result<(String, String)> {
185185
debug!("Executing command: {}", self.to_command_string());
186-
let output = match timeout {
187-
Some(duration) => tokio::time::timeout(duration, self.output()).await?,
188-
None => self.output().await,
189-
}?;
190186
let program = self.as_std().get_program().to_string_lossy().to_string();
191187
let stdout: String;
192188
let stderr: String;
189+
let status: ExitStatus;
193190

194191
if OS == "windows" && program.as_str().ends_with("pg_ctl") {
195192
// The pg_ctl process can hang on Windows when attempting to get stdout/stderr.
193+
let mut process = self
194+
.stdout(std::process::Stdio::piped())
195+
.stderr(std::process::Stdio::piped())
196+
.spawn()?;
196197
stdout = String::new();
197198
stderr = String::new();
199+
status = process.wait().await?;
198200
} else {
201+
let output = match timeout {
202+
Some(duration) => tokio::time::timeout(duration, self.output()).await?,
203+
None => self.output().await,
204+
}?;
199205
stdout = String::from_utf8_lossy(&output.stdout).into_owned();
200206
stderr = String::from_utf8_lossy(&output.stderr).into_owned();
207+
status = output.status;
201208
}
202209

203210
debug!(
204211
"Result: {}\nstdout: {}\nstderr: {}",
205-
output
206-
.status
207-
.code()
208-
.map_or("None".to_string(), |c| c.to_string()),
212+
status.code().map_or("None".to_string(), |c| c.to_string()),
209213
stdout,
210214
stderr
211215
);
212216

213-
if output.status.success() {
217+
if status.success() {
214218
Ok((stdout, stderr))
215219
} else {
216220
Err(Error::CommandError { stdout, stderr })

postgresql_extensions/src/repository/model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
#[async_trait]
1010
pub trait Repository: Debug + Send + Sync {
1111
/// Gets the name of the repository.
12-
fn name(&self) -> &str;
12+
fn name(&self) -> &'static str;
1313

1414
/// Gets the available extensions.
1515
///

0 commit comments

Comments
 (0)