mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-13 07:56:29 +00:00
IO import changes
This commit is contained in:
parent
6f2d8cc26c
commit
ecbe63bf1e
4
build.rs
4
build.rs
@ -12,7 +12,7 @@
|
||||
|
||||
extern crate datetime;
|
||||
use std::env;
|
||||
use std::io::Result as IOResult;
|
||||
use std::io;
|
||||
|
||||
|
||||
fn git_hash() -> String {
|
||||
@ -46,7 +46,7 @@ fn build_date() -> String {
|
||||
format!("{}", now.date().iso())
|
||||
}
|
||||
|
||||
fn write_statics() -> IOResult<()> {
|
||||
fn write_statics() -> io::Result<()> {
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::fs::feature::git::GitCache;
|
||||
use crate::fs::fields::GitStatus;
|
||||
use std::io::{self, Result as IOResult};
|
||||
use std::io;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::slice::Iter as SliceIter;
|
||||
@ -35,7 +35,7 @@ impl Dir {
|
||||
/// The `read_dir` iterator doesn’t actually yield the `.` and `..`
|
||||
/// entries, so if the user wants to see them, we’ll have to add them
|
||||
/// ourselves after the files have been read.
|
||||
pub fn read_dir(path: PathBuf) -> IOResult<Self> {
|
||||
pub fn read_dir(path: PathBuf) -> io::Result<Self> {
|
||||
info!("Reading directory {:?}", &path);
|
||||
|
||||
let contents = fs::read_dir(&path)?
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! Files, and methods and fields to access their metadata.
|
||||
|
||||
use std::io::Error as IOError;
|
||||
use std::io::Result as IOResult;
|
||||
use std::io;
|
||||
use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
@ -67,7 +66,7 @@ pub struct File<'dir> {
|
||||
}
|
||||
|
||||
impl<'dir> File<'dir> {
|
||||
pub fn from_args<PD, FN>(path: PathBuf, parent_dir: PD, filename: FN) -> IOResult<File<'dir>>
|
||||
pub fn from_args<PD, FN>(path: PathBuf, parent_dir: PD, filename: FN) -> io::Result<File<'dir>>
|
||||
where PD: Into<Option<&'dir Dir>>,
|
||||
FN: Into<Option<String>>
|
||||
{
|
||||
@ -82,7 +81,7 @@ impl<'dir> File<'dir> {
|
||||
Ok(File { path, parent_dir, metadata, ext, name, is_all_all })
|
||||
}
|
||||
|
||||
pub fn new_aa_current(parent_dir: &'dir Dir) -> IOResult<File<'dir>> {
|
||||
pub fn new_aa_current(parent_dir: &'dir Dir) -> io::Result<File<'dir>> {
|
||||
let path = parent_dir.path.to_path_buf();
|
||||
let ext = File::ext(&path);
|
||||
|
||||
@ -94,7 +93,7 @@ impl<'dir> File<'dir> {
|
||||
Ok(File { path, parent_dir, metadata, ext, name: ".".into(), is_all_all })
|
||||
}
|
||||
|
||||
pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir) -> IOResult<File<'dir>> {
|
||||
pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir) -> io::Result<File<'dir>> {
|
||||
let ext = File::ext(&path);
|
||||
|
||||
debug!("Statting file {:?}", &path);
|
||||
@ -162,7 +161,7 @@ impl<'dir> File<'dir> {
|
||||
///
|
||||
/// 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) -> IOResult<Dir> {
|
||||
pub fn to_dir(&self) -> io::Result<Dir> {
|
||||
Dir::read_dir(self.path.clone())
|
||||
}
|
||||
|
||||
@ -459,10 +458,10 @@ pub enum FileTarget<'dir> {
|
||||
/// There was an IO error when following the link. This can happen if the
|
||||
/// file isn’t a link to begin with, but also if, say, we don’t have
|
||||
/// permission to follow it.
|
||||
Err(IOError),
|
||||
Err(io::Error),
|
||||
|
||||
// Err is its own variant, instead of having the whole thing be inside an
|
||||
// `IOResult`, because being unable to follow a symlink is not a serious
|
||||
// `io::Result`, because being unable to follow a symlink is not a serious
|
||||
// error — we just display the error message and move on.
|
||||
}
|
||||
|
||||
|
28
src/main.rs
28
src/main.rs
@ -3,7 +3,7 @@
|
||||
|
||||
use std::env;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::io::{stdout, Stdout, stderr, Write, Result as IOResult, ErrorKind};
|
||||
use std::io::{self, Write, ErrorKind};
|
||||
use std::path::{Component, PathBuf};
|
||||
|
||||
use ansi_term::{ANSIStrings, Style};
|
||||
@ -40,7 +40,7 @@ fn main() {
|
||||
}
|
||||
|
||||
let git = git_options(&options, &input_paths);
|
||||
let writer = stdout();
|
||||
let writer = io::stdout();
|
||||
let exa = Exa { options, writer, input_paths, git };
|
||||
|
||||
match exa.run() {
|
||||
@ -88,7 +88,7 @@ pub struct Exa<'args> {
|
||||
pub options: Options,
|
||||
|
||||
/// The output handle that we write to.
|
||||
pub writer: Stdout,
|
||||
pub writer: io::Stdout,
|
||||
|
||||
/// List of the free command-line arguments that should correspond to file
|
||||
/// names (anything that isn’t an option).
|
||||
@ -122,7 +122,7 @@ fn git_options(options: &Options, args: &[&OsStr]) -> Option<GitCache> {
|
||||
}
|
||||
|
||||
impl<'args> Exa<'args> {
|
||||
pub fn run(mut self) -> IOResult<i32> {
|
||||
pub fn run(mut self) -> io::Result<i32> {
|
||||
debug!("Running with options: {:#?}", self.options);
|
||||
|
||||
let mut files = Vec::new();
|
||||
@ -133,14 +133,14 @@ impl<'args> Exa<'args> {
|
||||
match File::from_args(PathBuf::from(file_path), None, None) {
|
||||
Err(e) => {
|
||||
exit_status = 2;
|
||||
writeln!(stderr(), "{:?}: {}", file_path, e)?;
|
||||
writeln!(io::stderr(), "{:?}: {}", file_path, e)?;
|
||||
}
|
||||
|
||||
Ok(f) => {
|
||||
if f.points_to_directory() && ! self.options.dir_action.treat_dirs_as_files() {
|
||||
match f.to_dir() {
|
||||
Ok(d) => dirs.push(d),
|
||||
Err(e) => writeln!(stderr(), "{:?}: {}", file_path, e)?,
|
||||
Err(e) => writeln!(io::stderr(), "{:?}: {}", file_path, e)?,
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -163,7 +163,7 @@ impl<'args> Exa<'args> {
|
||||
self.print_dirs(dirs, no_files, is_only_dir, exit_status)
|
||||
}
|
||||
|
||||
fn print_dirs(&mut self, dir_files: Vec<Dir>, mut first: bool, is_only_dir: bool, exit_status: i32) -> IOResult<i32> {
|
||||
fn print_dirs(&mut self, dir_files: Vec<Dir>, mut first: bool, is_only_dir: bool, exit_status: i32) -> io::Result<i32> {
|
||||
for dir in dir_files {
|
||||
|
||||
// Put a gap between directories, or between the list of files and
|
||||
@ -185,8 +185,8 @@ impl<'args> Exa<'args> {
|
||||
let git_ignore = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
|
||||
for file in dir.files(self.options.filter.dot_filter, self.git.as_ref(), git_ignore) {
|
||||
match file {
|
||||
Ok(file) => children.push(file),
|
||||
Err((path, e)) => writeln!(stderr(), "[{}: {}]", path.display(), e)?,
|
||||
Ok(file) => children.push(file),
|
||||
Err((path, e)) => writeln!(io::stderr(), "[{}: {}]", path.display(), e)?,
|
||||
}
|
||||
};
|
||||
|
||||
@ -200,15 +200,15 @@ impl<'args> Exa<'args> {
|
||||
let mut child_dirs = Vec::new();
|
||||
for child_dir in children.iter().filter(|f| f.is_directory() && ! f.is_all_all) {
|
||||
match child_dir.to_dir() {
|
||||
Ok(d) => child_dirs.push(d),
|
||||
Err(e) => writeln!(stderr(), "{}: {}", child_dir.path.display(), e)?,
|
||||
Ok(d) => child_dirs.push(d),
|
||||
Err(e) => writeln!(io::stderr(), "{}: {}", child_dir.path.display(), e)?,
|
||||
}
|
||||
}
|
||||
|
||||
self.print_files(Some(&dir), children)?;
|
||||
match self.print_dirs(child_dirs, false, false, exit_status) {
|
||||
Ok(_) => (),
|
||||
Err(e) => return Err(e),
|
||||
Ok(_) => (),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -223,7 +223,7 @@ impl<'args> Exa<'args> {
|
||||
/// Prints the list of files using whichever view is selected.
|
||||
/// For various annoying logistical reasons, each one handles
|
||||
/// printing differently...
|
||||
fn print_files(&mut self, dir: Option<&Dir>, files: Vec<File>) -> IOResult<()> {
|
||||
fn print_files(&mut self, dir: Option<&Dir>, files: Vec<File>) -> io::Result<()> {
|
||||
if files.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -60,7 +60,7 @@
|
||||
//! can be displayed, in order to make sure that every column is wide enough.
|
||||
|
||||
|
||||
use std::io::{Write, Error as IOError, Result as IOResult};
|
||||
use std::io::{self, Write};
|
||||
use std::mem::MaybeUninit;
|
||||
use std::path::PathBuf;
|
||||
use std::vec::IntoIter as VecIntoIter;
|
||||
@ -135,7 +135,7 @@ pub struct Render<'a> {
|
||||
struct Egg<'a> {
|
||||
table_row: Option<TableRow>,
|
||||
xattrs: Vec<Attribute>,
|
||||
errors: Vec<(IOError, Option<PathBuf>)>,
|
||||
errors: Vec<(io::Error, Option<PathBuf>)>,
|
||||
dir: Option<Dir>,
|
||||
file: &'a File<'a>,
|
||||
icon: Option<String>,
|
||||
@ -149,7 +149,7 @@ impl<'a> AsRef<File<'a>> for Egg<'a> {
|
||||
|
||||
|
||||
impl<'a> Render<'a> {
|
||||
pub fn render<W: Write>(self, mut git: Option<&'a GitCache>, w: &mut W) -> IOResult<()> {
|
||||
pub fn render<W: Write>(self, mut git: Option<&'a GitCache>, w: &mut W) -> io::Result<()> {
|
||||
let mut pool = Pool::new(num_cpus::get() as u32);
|
||||
let mut rows = Vec::new();
|
||||
|
||||
@ -357,7 +357,7 @@ impl<'a> Render<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_error(&self, error: &IOError, tree: TreeParams, path: Option<PathBuf>) -> Row {
|
||||
fn render_error(&self, error: &io::Error, tree: TreeParams, path: Option<PathBuf>) -> Row {
|
||||
use crate::output::file_name::Colours;
|
||||
|
||||
let error_message = match path {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::io::{Write, Result as IOResult};
|
||||
use std::io::{self, Write};
|
||||
|
||||
use term_grid as tg;
|
||||
|
||||
@ -32,7 +32,7 @@ pub struct Render<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Render<'a> {
|
||||
pub fn render<W: Write>(&self, w: &mut W) -> IOResult<()> {
|
||||
pub fn render<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
||||
let mut grid = tg::Grid::new(tg::GridOptions {
|
||||
direction: self.opts.direction(),
|
||||
filling: tg::Filling::Spaces(2),
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! The grid-details view lists several details views side-by-side.
|
||||
|
||||
use std::io::{Write, Result as IOResult};
|
||||
use std::io::{self, Write};
|
||||
|
||||
use ansi_term::{ANSIGenericString, ANSIStrings};
|
||||
use term_grid as grid;
|
||||
@ -119,7 +119,7 @@ impl<'a> Render<'a> {
|
||||
// This doesn’t take an IgnoreCache even though the details one does
|
||||
// because grid-details has no tree view.
|
||||
|
||||
pub fn render<W: Write>(self, git: Option<&GitCache>, w: &mut W) -> IOResult<()> {
|
||||
pub fn render<W: Write>(self, git: Option<&GitCache>, w: &mut W) -> io::Result<()> {
|
||||
if let Some((grid, width)) = self.find_fitting_grid(git) {
|
||||
write!(w, "{}", grid.fit_into_columns(width))
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::io::{Write, Result as IOResult};
|
||||
use std::io::{self, Write};
|
||||
|
||||
use ansi_term::{ANSIStrings, ANSIGenericString};
|
||||
|
||||
@ -23,7 +23,7 @@ pub struct Render<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Render<'a> {
|
||||
pub fn render<W: Write>(&self, w: &mut W) -> IOResult<()> {
|
||||
pub fn render<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
||||
for file in &self.files {
|
||||
let name_cell = self.render_file(file).paint();
|
||||
if self.opts.icons {
|
||||
|
Loading…
Reference in New Issue
Block a user