Skip to content

Commit

Permalink
Removed dependence on unstable PathExt.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKeep committed Oct 21, 2015
1 parent 9e640e5 commit 75b29f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ As such, `cargo-script` does two major things:
2. It caches the generated and compiled packages, regenerating them only if the script or its metadata have changed.
*/
#![feature(path_ext)]
#![feature(pattern)]

extern crate clap;
Expand All @@ -34,12 +33,12 @@ use std::borrow::Cow;
use std::error::Error;
use std::ffi::OsString;
use std::fs;
use std::io::prelude::*;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::Command;

use error::{Blame, MainError, Result};
use util::Defer;
use util::{Defer, PathExt};

#[derive(Debug)]
struct Args {
Expand Down Expand Up @@ -599,8 +598,6 @@ fn decide_action_for(
build_only: bool,
force: bool,
) -> InputAction {
use std::fs::PathExt;

let (pkg_path, using_cache) = pkg_path.map(|p| (p.into(), false))
.unwrap_or_else(|| {
// This can't fail. Seriously, we're *fucked* if we can't work this out.
Expand Down
20 changes: 20 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,23 @@ impl SubsliceOffset for str {
}
}
}

use std::path::Path;

/**
Stable replacement for unstable `std::fs::PathExt`.
*/
pub trait PathExt {
/**
Returns whether this metadata is for a regular file.
*/
fn is_file(&self) -> bool;
}

impl PathExt for Path {
fn is_file(&self) -> bool {
::std::fs::metadata(self)
.map(|md| md.is_file())
.unwrap_or(false)
}
}

0 comments on commit 75b29f6

Please sign in to comment.