Skip to content

Commit

Permalink
fix: capture needed stdout for sever commands (#149)
Browse files Browse the repository at this point in the history
* Fix several command fail because of stdout isn't captured

* Use read instead
  • Loading branch information
wusyong authored Apr 26, 2023
1 parent 8f6c122 commit 489d812
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-capture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-mobile": patch
---

Fix several commands fail because stdout isn't captured.

5 changes: 2 additions & 3 deletions src/apple/deps/xcode_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ pub fn xcode_user_dir() -> Result<PathBuf, Error> {

pub fn xcode_developer_dir() -> Result<PathBuf, Error> {
duct::cmd("xcode-select", ["-p"])
.run()
.read()
.map(|output| {
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
// This output is expected to end with a newline, but we'll err on
// the safe side and proceed gracefully if it doesn't.
PathBuf::from(stdout.strip_suffix('\n').unwrap_or(&stdout))
PathBuf::from(output.strip_suffix('\n').unwrap_or(&output))
})
.map_err(Error::XcodeSelectFailed)
}
Expand Down
1 change: 1 addition & 0 deletions src/apple/teams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn get_pem_list(name_substr: &str) -> std::io::Result<std::process::Output>
"security",
["find-certificate", "-p", "-a", "-c", name_substr],
)
.stdout_capture()
.run()
}

Expand Down
2 changes: 2 additions & 0 deletions src/util/git/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ impl Repo {
.map_err(Error::FetchFailed)?;
let local = git
.command_parse("rev-parse HEAD")
.stdout_capture()
.run()
.map_err(Error::RevParseLocalFailed)?;
let remote = git
.command_parse("rev-parse @{u}")
.stdout_capture()
.run()
.map_err(Error::RevParseRemoteFailed)?;
if local.stdout != remote.stdout {
Expand Down
10 changes: 3 additions & 7 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,9 @@ pub fn prepend_to_path(path: impl Display, base_path: impl Display) -> String {
}

pub fn command_present(name: &str) -> Result<bool, std::io::Error> {
command_path(name).map(|_path| true).or_else(|err| {
if err.raw_os_error().is_some() {
Ok(false)
} else {
Err(err)
}
})
command_path(name)
.map(|_path| true)
.or_else(|_err| Ok(false))
}

#[derive(Debug)]
Expand Down

0 comments on commit 489d812

Please sign in to comment.