f19d083362
This adds bindings to the remaining functions provided by libuv, all of which are useful operations on files which need to get exposed somehow. Some highlights: * Dropped `FileReader` and `FileWriter` and `FileStream` for one `File` type * Moved all file-related methods to be static methods under `File` * All directory related methods are still top-level functions * Created `io::FilePermission` types (backed by u32) that are what you'd expect * Created `io::FileType` and refactored `FileStat` to use FileType and FilePermission * Removed the expanding matrix of `FileMode` operations. The mode of reading a file will not have the O_CREAT flag, but a write mode will always have the O_CREAT flag. Closes #10130 Closes #10131 Closes #10121
59 lines
2.0 KiB
Rust
59 lines
2.0 KiB
Rust
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
use std::rt::io;
|
|
use std::rt::io::File;
|
|
use extra::workcache;
|
|
use sha1::{Digest, Sha1};
|
|
|
|
/// Hashes the file contents along with the last-modified time
|
|
pub fn digest_file_with_date(path: &Path) -> ~str {
|
|
use conditions::bad_path::cond;
|
|
|
|
match io::result(|| File::open(path).read_to_end()) {
|
|
Ok(bytes) => {
|
|
let mut sha = Sha1::new();
|
|
sha.input(bytes);
|
|
let st = path.stat();
|
|
sha.input_str(st.modified.to_str());
|
|
sha.result_str()
|
|
}
|
|
Err(e) => {
|
|
cond.raise((path.clone(), format!("Couldn't read file: {}", e.desc)));
|
|
~""
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Hashes only the last-modified time
|
|
pub fn digest_only_date(path: &Path) -> ~str {
|
|
let mut sha = Sha1::new();
|
|
let st = path.stat();
|
|
sha.input_str(st.modified.to_str());
|
|
sha.result_str()
|
|
}
|
|
|
|
/// Adds multiple discovered outputs
|
|
pub fn discover_outputs(e: &mut workcache::Exec, outputs: ~[Path]) {
|
|
debug!("Discovering {:?} outputs", outputs.len());
|
|
for p in outputs.iter() {
|
|
debug!("Discovering output! {}", p.display());
|
|
// For now, assume that all discovered outputs are binaries
|
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
|
e.discover_output("binary", p.as_str().unwrap(), digest_only_date(p));
|
|
}
|
|
}
|
|
|
|
/// Returns the function name for building a crate
|
|
pub fn crate_tag(p: &Path) -> ~str {
|
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
|
p.as_str().unwrap().to_owned() // implicitly, it's "build(p)"...
|
|
}
|