Skip to content

Commit

Permalink
fix(rustup): (07560d233 2015-04-20) (built 2015-04-19)
Browse files Browse the repository at this point in the history
* use std::io consistently
* adjust to improved `Command` API

Related to Byron/google-apis-rs#70
  • Loading branch information
Byron committed Apr 21, 2015
1 parent 30c96b1 commit 8b4e155
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "open"
version = "1.0.2"
version = "1.0.3"
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
license = "MIT"
description = "Open a path or URL using the program configured on the system"
Expand Down
37 changes: 21 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(old_io)]
//! Use this library to open a path or URL using the program configured on the system.
//!
//! # Usage
Expand All @@ -19,30 +18,36 @@
//! As an operating system program is used, chances are that the open operation fails.
//! Therfore, you are advised to at least check the result with `.is_err()` and
//! behave accordingly, e.g. by letting the user know what you tried to open, and failed.
use std::old_io::IoResult;
use std::old_io::process::{Command, ProcessExit};
use std::io;
use std::process::{Command, ExitStatus};

#[cfg(not(any(target_os = "windows", target_os = "macos")))]
pub fn that(path: &str) -> IoResult<ProcessExit> {
use std::old_io::IoError;

let mut res = Err(IoError::from_errno(0, false));
pub fn that(path: &str) -> io::Result<ExitStatus> {
let mut last_err: io::Result<ExitStatus> = Err(io::Error::from_raw_os_error(0));
for program in &["xdg-open", "gnome-open", "kde-open"] {
res = Command::new(program).arg(path).detached().status();
match res {
Ok(_) => return res,
Err(_) => continue,
match Command::new(program).arg(path).spawn() {
Ok(mut child) => return child.wait(),
Err(err) => {
last_err = Err(err);
continue;
},
}
}
res
last_err
}

#[cfg(target_os = "windows")]
pub fn that(path: &str) -> IoResult<ProcessExit> {
Command::new("start").arg(path).detached().status()
pub fn that(path: &str) -> io::Result<ExitStatus> {
match Command::new("start").arg(path).spawn() {
Ok(mut child) => child.wait(),
Err(err) => Err(err),
}
}

#[cfg(target_os = "macos")]
pub fn that(path: &str) -> IoResult<ProcessExit> {
Command::new("open").arg(path).detached().status()
pub fn that(path: &str) -> io::Result<ExitStatus> {
match Command::new("open").arg(path).spawn() {
Ok(mut child) => child.wait(),
Err(err) => Err(err),
}
}

0 comments on commit 8b4e155

Please sign in to comment.