summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Sago <ogham@bsago.me>2016-04-16 18:59:25 +0100
committerBenjamin Sago <ogham@bsago.me>2016-04-16 18:59:25 +0100
commitefa372cb3bbb3e09050d4915ae06736d1fd29ffe (patch)
tree34980e20ee2da6d76d512f87315204aec0625d0c
parentb65043d6d9b7bcd8c87ec2a9cf7f6bf826417b47 (diff)
Source file rearrangements
This commit moves file, dir, and the feature modules into one parent 'fs' module. Now there are three main 'areas' of the code: main and options, the filesystem-touching code, and the output-displaying code. It should be the case that nothing in 'output' touches 'std::fs'.
-rw-r--r--src/fs/dir.rs (renamed from src/dir.rs)4
-rw-r--r--src/fs/feature/git.rs (renamed from src/feature/git.rs)40
-rw-r--r--src/fs/feature/mod.rs (renamed from src/feature/mod.rs)0
-rw-r--r--src/fs/feature/xattr.rs (renamed from src/feature/xattr.rs)0
-rw-r--r--src/fs/fields.rs74
-rw-r--r--src/fs/file.rs (renamed from src/file.rs)82
-rw-r--r--src/fs/filetype.rs (renamed from src/filetype.rs)2
-rw-r--r--src/fs/mod.rs9
-rw-r--r--src/main.rs8
-rw-r--r--src/options.rs6
-rw-r--r--src/output/column.rs2
-rw-r--r--src/output/details.rs11
-rw-r--r--src/output/grid.rs2
-rw-r--r--src/output/grid_details.rs5
-rw-r--r--src/output/lines.rs2
-rw-r--r--src/output/mod.rs2
16 files changed, 123 insertions, 126 deletions
diff --git a/src/dir.rs b/src/fs/dir.rs
index 7453745..5d3fb26 100644
--- a/src/dir.rs
+++ b/src/fs/dir.rs
@@ -3,8 +3,8 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::slice::Iter as SliceIter;
-use feature::Git;
-use file::{File, fields};
+use fs::feature::Git;
+use fs::{File, fields};
/// A **Dir** provides a cached list of the file paths in a directory that's
diff --git a/src/feature/git.rs b/src/fs/feature/git.rs
index faa3d51..121e302 100644
--- a/src/feature/git.rs
+++ b/src/fs/feature/git.rs
@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
use git2;
-use file::fields;
+use fs::fields as f;
/// Container of Git statuses for all the files in this folder's Git repository.
@@ -29,48 +29,48 @@ impl Git {
}
/// Get the status for the file at the given path, if present.
- pub fn status(&self, path: &Path) -> fields::Git {
+ pub fn status(&self, path: &Path) -> f::Git {
let status = self.statuses.iter()
.find(|p| p.0.as_path() == path);
match status {
- Some(&(_, s)) => fields::Git { staged: index_status(s), unstaged: working_tree_status(s) },
- None => fields::Git { staged: fields::GitStatus::NotModified, unstaged: fields::GitStatus::NotModified }
+ Some(&(_, s)) => f::Git { staged: index_status(s), unstaged: working_tree_status(s) },
+ None => f::Git { staged: f::GitStatus::NotModified, unstaged: f::GitStatus::NotModified }
}
}
/// Get the combined status for all the files whose paths begin with the
/// path that gets passed in. This is used for getting the status of
/// directories, which don't really have an 'official' status.
- pub fn dir_status(&self, dir: &Path) -> fields::Git {
+ pub fn dir_status(&self, dir: &Path) -> f::Git {
let s = self.statuses.iter()
.filter(|p| p.0.starts_with(dir))
.fold(git2::Status::empty(), |a, b| a | b.1);
- fields::Git { staged: index_status(s), unstaged: working_tree_status(s) }
+ f::Git { staged: index_status(s), unstaged: working_tree_status(s) }
}
}
/// The character to display if the file has been modified, but not staged.
-fn working_tree_status(status: git2::Status) -> fields::GitStatus {
+fn working_tree_status(status: git2::Status) -> f::GitStatus {
match status {
- s if s.contains(git2::STATUS_WT_NEW) => fields::GitStatus::New,
- s if s.contains(git2::STATUS_WT_MODIFIED) => fields::GitStatus::Modified,
- s if s.contains(git2::STATUS_WT_DELETED) => fields::GitStatus::Deleted,
- s if s.contains(git2::STATUS_WT_RENAMED) => fields::GitStatus::Renamed,
- s if s.contains(git2::STATUS_WT_TYPECHANGE) => fields::GitStatus::TypeChange,
- _ => fields::GitStatus::NotModified,
+ s if s.contains(git2::STATUS_WT_NEW) => f::GitStatus::New,
+ s if s.contains(git2::STATUS_WT_MODIFIED) => f::GitStatus::Modified,
+ s if s.contains(git2::STATUS_WT_DELETED) => f::GitStatus::Deleted,
+ s if s.contains(git2::STATUS_WT_RENAMED) => f::GitStatus::Renamed,
+ s if s.contains(git2::STATUS_WT_TYPECHANGE) => f::GitStatus::TypeChange,
+ _ => f::GitStatus::NotModified,
}
}
/// The character to display if the file has been modified, and the change
/// has been staged.
-fn index_status(status: git2::Status) -> fields::GitStatus {
+fn index_status(status: git2::Status) -> f::GitStatus {
match status {
- s if s.contains(git2::STATUS_INDEX_NEW) => fields::GitStatus::New,
- s if s.contains(git2::STATUS_INDEX_MODIFIED) => fields::GitStatus::Modified,
- s if s.contains(git2::STATUS_INDEX_DELETED) => fields::GitStatus::Deleted,
- s if s.contains(git2::STATUS_INDEX_RENAMED) => fields::GitStatus::Renamed,
- s if s.contains(git2::STATUS_INDEX_TYPECHANGE) => fields::GitStatus::TypeChange,
- _ => fields::GitStatus::NotModified,
+ s if s.contains(git2::STATUS_INDEX_NEW) => f::GitStatus::New,
+ s if s.contains(git2::STATUS_INDEX_MODIFIED) => f::GitStatus::Modified,
+ s if s.contains(git2::STATUS_INDEX_DELETED) => f::GitStatus::Deleted,
+ s if s.contains(git2::STATUS_INDEX_RENAMED) => f::GitStatus::Renamed,
+ s if s.contains(git2::STATUS_INDEX_TYPECHANGE) => f::GitStatus::TypeChange,
+ _ => f::GitStatus::NotModified,
}
}
diff --git a/src/feature/mod.rs b/src/fs/feature/mod.rs
index 9fe56f1..9fe56f1 100644
--- a/src/feature/mod.rs
+++ b/src/fs/feature/mod.rs
diff --git a/src/feature/xattr.rs b/src/fs/feature/xattr.rs
index a93f720..a93f720 100644
--- a/src/feature/xattr.rs
+++ b/src/fs/feature/xattr.rs
diff --git a/src/fs/fields.rs b/src/fs/fields.rs
new file mode 100644
index 0000000..a70cb22
--- /dev/null
+++ b/src/fs/fields.rs
@@ -0,0 +1,74 @@
+#![allow(non_camel_case_types)]
+
+/// Wrapper types for the values returned from `File` objects.
+///
+/// The methods of `File` don't return formatted strings; neither do they
+/// return raw numbers representing timestamps or user IDs. Instead, they will
+/// return an object in this `fields` module. These objects are later rendered
+/// into formatted strings in the `output/details` module.
+pub type blkcnt_t = u64;
+pub type gid_t = u32;
+pub type ino_t = u64;
+pub type nlink_t = u64;
+pub type time_t = i64;
+pub type uid_t = u32;
+
+pub enum Type {
+ File, Directory, Pipe, Link, Special,
+}
+
+pub struct Permissions {
+ pub file_type: Type,
+ pub user_read: bool,
+ pub user_write: bool,
+ pub user_execute: bool,
+ pub group_read: bool,
+ pub group_write: bool,
+ pub group_execute: bool,
+ pub other_read: bool,
+ pub other_write: bool,
+ pub other_execute: bool,
+}
+
+pub struct Links {
+ pub count: nlink_t,
+ pub multiple: bool,
+}
+
+pub struct Inode(pub ino_t);
+
+pub enum Blocks {
+ Some(blkcnt_t),
+ None,
+}
+
+pub struct User(pub uid_t);
+
+pub struct Group(pub gid_t);
+
+pub enum Size {
+ Some(u64),
+ None,
+}
+
+pub struct Time(pub time_t);
+
+pub enum GitStatus {
+ NotModified,
+ New,
+ Modified,
+ Deleted,
+ Renamed,
+ TypeChange,
+}
+
+pub struct Git {
+ pub staged: GitStatus,
+ pub unstaged: GitStatus,
+}
+
+impl Git {
+ pub fn empty() -> Git {
+ Git { staged: GitStatus::NotModified, unstaged: GitStatus::NotModified }
+ }
+}
diff --git a/src/file.rs b/src/fs/file.rs
index 7f7c692..24ec77e 100644
--- a/src/file.rs
+++ b/src/fs/file.rs
@@ -7,9 +7,8 @@ use std::io::Result as IOResult;
use std::os::unix::fs::{MetadataExt, PermissionsExt};
use std::path::{Path, PathBuf};
-use dir::Dir;
-
-use self::fields as f;
+use fs::dir::Dir;
+use fs::fields as f;
/// Constant table copied from https://doc.rust-lang.org/src/std/sys/unix/ext/fs.rs.html#11-259
@@ -409,83 +408,6 @@ fn ext(path: &Path) -> Option<String> {
}
-/// Wrapper types for the values returned from `File` objects.
-///
-/// The methods of `File` don't return formatted strings; neither do they
-/// return raw numbers representing timestamps or user IDs. Instead, they will
-/// return an object in this `fields` module. These objects are later rendered
-/// into formatted strings in the `output/details` module.
-#[allow(non_camel_case_types)]
-pub mod fields {
- pub type blkcnt_t = u64;
- pub type gid_t = u32;
- pub type ino_t = u64;
- pub type nlink_t = u64;
- pub type time_t = i64;
- pub type uid_t = u32;
-
- pub enum Type {
- File, Directory, Pipe, Link, Special,
- }
-
- pub struct Permissions {
- pub file_type: Type,
- pub user_read: bool,
- pub user_write: bool,
- pub user_execute: bool,
- pub group_read: bool,
- pub group_write: bool,
- pub group_execute: bool,
- pub other_read: bool,
- pub other_write: bool,
- pub other_execute: bool,
- }
-
- pub struct Links {
- pub count: nlink_t,
- pub multiple: bool,
- }
-
- pub struct Inode(pub ino_t);
-
- pub enum Blocks {
- Some(blkcnt_t),
- None,
- }
-
- pub struct User(pub uid_t);
-
- pub struct Group(pub gid_t);
-
- pub enum Size {
- Some(u64),
- None,
- }
-
- pub struct Time(pub time_t);
-
- pub enum GitStatus {
- NotModified,
- New,
- Modified,
- Deleted,
- Renamed,
- TypeChange,
- }
-
- pub struct Git {
- pub staged: GitStatus,
- pub unstaged: GitStatus,
- }
-
- impl Git {
- pub fn empty() -> Git {
- Git { staged: GitStatus::NotModified, unstaged: GitStatus::NotModified }
- }
- }
-}
-
-
#[cfg(test)]
mod test {
use super::ext;
diff --git a/src/filetype.rs b/src/fs/filetype.rs
index 97f35f7..eff3e58 100644
--- a/src/filetype.rs
+++ b/src/fs/filetype.rs
@@ -1,4 +1,4 @@
-use file::File;
+use fs::File;
impl<'_> File<'_> {
diff --git a/src/fs/mod.rs b/src/fs/mod.rs
new file mode 100644
index 0000000..9ee79c9
--- /dev/null
+++ b/src/fs/mod.rs
@@ -0,0 +1,9 @@
+mod dir;
+pub use self::dir::Dir;
+
+mod file;
+pub mod filetype;
+pub use self::file::File;
+
+pub mod feature;
+pub mod fields; \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 8c76738..c295711 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,14 +23,10 @@ use std::env;
use std::path::{Component, Path};
use std::process;
-use dir::Dir;
-use file::File;
+use fs::{Dir, File};
use options::{Options, View};
-mod dir;
-mod feature;
-mod file;
-mod filetype;
+mod fs;
mod options;
mod output;
mod term;
diff --git a/src/options.rs b/src/options.rs
index 74cbcbb..7add419 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -7,8 +7,8 @@ use std::os::unix::fs::MetadataExt;
use getopts;
use natord;
-use feature::xattr;
-use file::File;
+use fs::feature::xattr;
+use fs::File;
use output::{Grid, Details, GridDetails, Lines};
use output::Colours;
use output::column::{Columns, TimeTypes, SizeFormat};
@@ -759,7 +759,7 @@ static EXTENDED_HELP: &'static str = r##" -@, --extended display extended a
#[cfg(test)]
mod test {
use super::{Options, Misfire, SortField, SortCase};
- use feature::xattr;
+ use fs::feature::xattr;
fn is_helpful<T>(misfire: Result<T, Misfire>) -> bool {
match misfire {
diff --git a/src/output/column.rs b/src/output/column.rs
index cfec1f9..04a6f31 100644
--- a/src/output/column.rs
+++ b/src/output/column.rs
@@ -1,4 +1,4 @@
-use dir::Dir;
+use fs::Dir;
#[derive(PartialEq, Debug, Copy, Clone)]
diff --git a/src/output/details.rs b/src/output/details.rs
index c7ed1e3..f8a7a9b 100644
--- a/src/output/details.rs
+++ b/src/output/details.rs
@@ -88,10 +88,8 @@ use locale;
use users::{Users, Groups, UsersCache};
-use dir::Dir;
-use feature::xattr::{Attribute, FileAttributes};
-use file::fields as f;
-use file::File;
+use fs::{Dir, File, fields as f};
+use fs::feature::xattr::{Attribute, FileAttributes};
use options::{FileFilter, RecurseOptions};
use output::colours::Colours;
use output::column::{Alignment, Column, Columns, SizeFormat};
@@ -224,7 +222,7 @@ impl Details {
use num_cpus;
use scoped_threadpool::Pool;
use std::sync::{Arc, Mutex};
- use feature::xattr;
+ use fs::feature::xattr;
let mut pool = Pool::new(num_cpus::get() as u32);
let mut file_eggs = Vec::new();
@@ -761,8 +759,7 @@ pub mod test {
pub use super::{Table, Environment, Details};
pub use std::sync::Mutex;
- pub use file::File;
- pub use file::fields as f;
+ pub use fs::{File, fields as f};
pub use output::column::{Column, Columns};
pub use output::cell::TextCell;
diff --git a/src/output/grid.rs b/src/output/grid.rs
index f56f6c5..5afec32 100644
--- a/src/output/grid.rs
+++ b/src/output/grid.rs
@@ -1,6 +1,6 @@
use term_grid as grid;
-use file::File;
+use fs::File;
use output::DisplayWidth;
use output::colours::Colours;
use super::filename;
diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs
index 422fc35..2d348a3 100644
--- a/src/output/grid_details.rs
+++ b/src/output/grid_details.rs
@@ -4,9 +4,8 @@ use ansi_term::ANSIStrings;
use users::UsersCache;
use term_grid as grid;
-use dir::Dir;
-use feature::xattr::FileAttributes;
-use file::File;
+use fs::{Dir, File};
+use fs::feature::xattr::FileAttributes;
use output::cell::TextCell;
use output::column::Column;
diff --git a/src/output/lines.rs b/src/output/lines.rs
index 97820cd..81e51d0 100644
--- a/src/output/lines.rs
+++ b/src/output/lines.rs
@@ -1,6 +1,6 @@
use ansi_term::ANSIStrings;
-use file::File;
+use fs::File;
use super::filename;
use super::colours::Colours;
diff --git a/src/output/mod.rs b/src/output/mod.rs
index 3f1fa3d..6464e07 100644
--- a/src/output/mod.rs
+++ b/src/output/mod.rs
@@ -1,6 +1,6 @@
use ansi_term::Style;
-use file::File;
+use fs::File;
pub use self::cell::{TextCell, TextCellContents, DisplayWidth};
pub use self::colours::Colours;