Move strip_current_dir

This commit is contained in:
sharkdp 2020-04-03 19:01:29 +02:00 committed by David Peter
parent b415d7234b
commit 556c40e1f4
2 changed files with 16 additions and 15 deletions

View file

@ -5,7 +5,7 @@ use std::fs;
use std::io;
#[cfg(any(unix, target_os = "redox"))]
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use std::path::{Component, Path, PathBuf};
use crate::walk;
@ -82,3 +82,13 @@ pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> {
Cow::Borrowed(string) => Cow::Borrowed(string.as_bytes()),
}
}
/// Remove the `./` prefix from a path.
pub fn strip_current_dir(pathbuf: &PathBuf) -> &Path {
let mut iter = pathbuf.components();
let mut iter_next = iter.clone();
if iter_next.next() == Some(Component::CurDir) {
iter.next();
}
iter.as_path()
}

View file

@ -1,25 +1,16 @@
use crate::exit_codes::ExitCode;
use crate::options::Options;
use lscolors::{LsColors, Style};
use std::borrow::Cow;
use std::io::{self, StdoutLock, Write};
use std::path::{Component, Path, PathBuf};
use std::path::{Path, PathBuf};
use std::process;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use ansi_term;
use lscolors::{LsColors, Style};
/// Remove the `./` prefix from a path.
fn strip_current_dir(pathbuf: &PathBuf) -> &Path {
let mut iter = pathbuf.components();
let mut iter_next = iter.clone();
if iter_next.next() == Some(Component::CurDir) {
iter.next();
}
iter.as_path()
}
use crate::exit_codes::ExitCode;
use crate::filesystem::strip_current_dir;
use crate::options::Options;
pub fn print_entry(
stdout: &mut StdoutLock,