From 556c40e1f41ae83131861b45b137fcfd025bb6d9 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Fri, 3 Apr 2020 19:01:29 +0200 Subject: [PATCH] Move strip_current_dir --- src/filesystem.rs | 12 +++++++++++- src/output.rs | 19 +++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/filesystem.rs b/src/filesystem.rs index e4fbd03..1c395fc 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -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() +} diff --git a/src/output.rs b/src/output.rs index 198c3e1..68c9366 100644 --- a/src/output.rs +++ b/src/output.rs @@ -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,