Skip to content

Commit

Permalink
Merge branch 'parallel-details'
Browse files Browse the repository at this point in the history
  • Loading branch information
ogham committed Sep 3, 2015
2 parents 456c516 + 10fecbd commit fa51a87
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 280 deletions.
79 changes: 42 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ natord = "1.0.7"
num_cpus = "*"
number_prefix = "0.2.3"
pad = "0.1.1"
scoped_threadpool = "*"
term_grid = "*"
threadpool = "*"
unicode-width = "*"
users = "0.4.0"

Expand Down
12 changes: 10 additions & 2 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ use file::{File, fields};
/// check the existence of surrounding files, then highlight themselves
/// accordingly. (See `File#get_source_files`)
pub struct Dir {

/// A vector of the files that have been read from this directory.
contents: Vec<PathBuf>,
path: PathBuf,

/// The path that was read.
pub path: PathBuf,

/// Holds a `Git` object if scanning for Git repositories is switched on,
/// and this directory happens to contain one.
git: Option<Git>,
}

Expand All @@ -25,7 +32,7 @@ impl Dir {
/// pointed to by the given path. Fails if the directory can't be read, or
/// isn't actually a directory, or if there's an IO error that occurs
/// while scanning.
pub fn readdir(path: &Path, git: bool) -> io::Result<Dir> {
pub fn read_dir(path: &Path, git: bool) -> io::Result<Dir> {
let reader = try!(fs::read_dir(path));
let contents = try!(reader.map(|e| e.map(|e| e.path())).collect());

Expand Down Expand Up @@ -71,6 +78,7 @@ impl Dir {
}


/// Iterator over reading the contents of a directory as `File` objects.
pub struct Files<'dir> {
inner: SliceIter<'dir, PathBuf>,
dir: &'dir Dir,
Expand Down
37 changes: 23 additions & 14 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct File<'dir> {
}

impl<'dir> File<'dir> {

/// Create a new `File` object from the given `Path`, inside the given
/// `Dir`, if appropriate.
///
Expand All @@ -70,11 +71,11 @@ impl<'dir> File<'dir> {
let filename = path_filename(path);

File {
path: path.to_path_buf(),
dir: parent,
metadata: metadata,
ext: ext(&filename),
name: filename.to_string(),
path: path.to_path_buf(),
dir: parent,
metadata: metadata,
ext: ext(&filename),
name: filename.to_string(),
}
}

Expand All @@ -83,8 +84,14 @@ impl<'dir> File<'dir> {
self.metadata.is_dir()
}

pub fn to_dir(&self) -> io::Result<Dir> {
Dir::readdir(&*self.path, false)
/// If this file is a directory on the filesystem, then clone its
/// `PathBuf` for use in one of our own `Dir` objects, and read a list of
/// its contents.
///
/// Returns an IO error upon failure, but this shouldn't be used to check
/// if a `File` is a directory or not! For that, just use `is_directory()`.
pub fn to_dir(&self, scan_for_git: bool) -> io::Result<Dir> {
Dir::read_dir(&*self.path, scan_for_git)
}

/// Whether this file is a regular file on the filesystem - that is, not a
Expand Down Expand Up @@ -178,11 +185,11 @@ impl<'dir> File<'dir> {
// Use plain `metadata` instead of `symlink_metadata` - we *want* to follow links.
if let Ok(metadata) = fs::metadata(&target_path) {
Ok(File {
path: target_path.to_path_buf(),
dir: self.dir,
metadata: metadata,
ext: ext(&filename),
name: filename.to_string(),
path: target_path.to_path_buf(),
dir: self.dir,
metadata: metadata,
ext: ext(&filename),
name: filename.to_string(),
})
}
else {
Expand Down Expand Up @@ -282,6 +289,10 @@ impl<'dir> File<'dir> {
}

/// This file's permissions, with flags for each bit.
///
/// The extended-attribute '@' character that you see in here is in fact
/// added in later, to avoid querying the extended attributes more than
/// once. (Yes, it's a little hacky.)
pub fn permissions(&self) -> f::Permissions {
let bits = self.metadata.permissions().mode();
let has_bit = |bit| { bits & bit == bit };
Expand All @@ -297,7 +308,6 @@ impl<'dir> File<'dir> {
other_read: has_bit(unix::fs::OTHER_READ),
other_write: has_bit(unix::fs::OTHER_WRITE),
other_execute: has_bit(unix::fs::OTHER_EXECUTE),
attribute: false, // !self.xattrs.is_empty()
}
}

Expand Down Expand Up @@ -423,7 +433,6 @@ pub mod fields {
pub other_read: bool,
pub other_write: bool,
pub other_execute: bool,
pub attribute: bool,
}

pub struct Links {
Expand Down
Loading

0 comments on commit fa51a87

Please sign in to comment.