rename module entry -> dir_entry
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jonathan Goren · committed by Jonathan Goren · parent 1153e3e · Browse files · 8 files·+70 added−70 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+70 added−70 removed
- other:+70 added−70 removed
Provenance
- Commit
3dc61b5- Tree
1dc282b- Author
Jonathan Goren <jonagn@gmail.com>- Committer
Jonathan Goren <jonagn@gmail.com>- Parent
1153e3e
8 files changed+70 added−70 removed
modified:src/exec/job.rs+1 added-1 removed
1 use std::sync::{Arc, Mutex};2 3 use crossbeam_channel::Receiver;4 5-use crate::entry::DirEntry;5+use crate::dir_entry::DirEntry;6 use crate::error::print_error;7 use crate::exit_codes::{merge_exitcodes, ExitCode};8 use crate::walk::WorkerResult;9 69 unmodified linesadded:src/dir_entry.rs+62 added
1+use std::{2+ fs::{FileType, Metadata},3+ path::{Path, PathBuf},4+};5+6+use once_cell::unsync::OnceCell;7+8+enum DirEntryInner {9+ Normal(ignore::DirEntry),10+ BrokenSymlink(PathBuf),11+}12+13+pub struct DirEntry {14+ inner: DirEntryInner,15+ metadata: OnceCell<Option<Metadata>>,16+}17+18+impl DirEntry {19+ pub fn normal(e: ignore::DirEntry) -> Self {20+ Self {21+ inner: DirEntryInner::Normal(e),22+ metadata: OnceCell::new(),23+ }24+ }25+26+ pub fn broken_symlink(path: PathBuf) -> Self {27+ Self {28+ inner: DirEntryInner::BrokenSymlink(path),29+ metadata: OnceCell::new(),30+ }31+ }32+33+ pub fn path(&self) -> &Path {34+ match &self.inner {35+ DirEntryInner::Normal(e) => e.path(),36+ DirEntryInner::BrokenSymlink(pathbuf) => pathbuf.as_path(),37+ }38+ }39+40+ pub fn file_type(&self) -> Option<FileType> {41+ match &self.inner {42+ DirEntryInner::Normal(e) => e.file_type(),43+ DirEntryInner::BrokenSymlink(_) => self.metadata().map(|m| m.file_type()),44+ }45+ }46+47+ pub fn metadata(&self) -> Option<&Metadata> {48+ self.metadata49+ .get_or_init(|| match &self.inner {50+ DirEntryInner::Normal(e) => e.metadata().ok(),51+ DirEntryInner::BrokenSymlink(path) => path.symlink_metadata().ok(),52+ })53+ .as_ref()54+ }55+56+ pub fn depth(&self) -> Option<usize> {57+ match &self.inner {58+ DirEntryInner::Normal(e) => Some(e.depth()),59+ DirEntryInner::BrokenSymlink(_) => None,60+ }61+ }62+}deleted:src/entry.rs-62 removed
1-use std::{2- fs::{FileType, Metadata},3- path::{Path, PathBuf},4-};5-6-use once_cell::unsync::OnceCell;7-8-enum DirEntryInner {9- Normal(ignore::DirEntry),10- BrokenSymlink(PathBuf),11-}12-13-pub struct DirEntry {14- inner: DirEntryInner,15- metadata: OnceCell<Option<Metadata>>,16-}17-18-impl DirEntry {19- pub fn normal(e: ignore::DirEntry) -> Self {20- Self {21- inner: DirEntryInner::Normal(e),22- metadata: OnceCell::new(),23- }24- }25-26- pub fn broken_symlink(path: PathBuf) -> Self {27- Self {28- inner: DirEntryInner::BrokenSymlink(path),29- metadata: OnceCell::new(),30- }31- }32-33- pub fn path(&self) -> &Path {34- match &self.inner {35- DirEntryInner::Normal(e) => e.path(),36- DirEntryInner::BrokenSymlink(pathbuf) => pathbuf.as_path(),37- }38- }39-40- pub fn file_type(&self) -> Option<FileType> {41- match &self.inner {42- DirEntryInner::Normal(e) => e.file_type(),43- DirEntryInner::BrokenSymlink(_) => self.metadata().map(|m| m.file_type()),44- }45- }46-47- pub fn metadata(&self) -> Option<&Metadata> {48- self.metadata49- .get_or_init(|| match &self.inner {50- DirEntryInner::Normal(e) => e.metadata().ok(),51- DirEntryInner::BrokenSymlink(path) => path.symlink_metadata().ok(),52- })53- .as_ref()54- }55-56- pub fn depth(&self) -> Option<usize> {57- match &self.inner {58- DirEntryInner::Normal(e) => Some(e.depth()),59- DirEntryInner::BrokenSymlink(_) => None,60- }61- }62-}modified:src/filesystem.rs+2 added-2 removed
7 unmodified lines8 use std::path::{Path, PathBuf};9 10 use normpath::PathExt;11 12-use crate::entry;12+use crate::dir_entry;13 14 pub fn path_absolute_form(path: &Path) -> io::Result<PathBuf> {15 if path.is_absolute() {16 return Ok(path.to_path_buf());33 unmodified lines50 pub fn is_executable(_: &fs::Metadata) -> bool {51 false52 }53 54-pub fn is_empty(entry: &entry::DirEntry) -> bool {54+pub fn is_empty(entry: &dir_entry::DirEntry) -> bool {55 if let Some(file_type) = entry.file_type() {56 if file_type.is_dir() {57 if let Ok(mut entries) = fs::read_dir(entry.path()) {58 entries.next().is_none()90 unmodified linesmodified:src/filetypes.rs+2 added-2 removed
1-use crate::entry;1+use crate::dir_entry;2 use crate::filesystem;3 4 /// Whether or not to show5 #[derive(Default)]7 unmodified lines13 pub empty_only: bool,14 }15 16 impl FileTypes {17- pub fn should_ignore(&self, entry: &entry::DirEntry) -> bool {17+ pub fn should_ignore(&self, entry: &dir_entry::DirEntry) -> bool {18 if let Some(ref entry_type) = entry.file_type() {19 (!self.files && entry_type.is_file())20 || (!self.directories && entry_type.is_dir())21 || (!self.symlinks && entry_type.is_symlink())18 unmodified linesmodified:src/main.rs+1 added-1 removed
1 mod app;2 mod config;3-mod entry;3+mod dir_entry;4 mod error;5 mod exec;6 mod exit_codes;7 mod filesystem;563 unmodified linesmodified:src/output.rs+1 added-1 removed
4 unmodified lines5 use lscolors::{Indicator, LsColors, Style};6 use once_cell::sync::Lazy;7 8 use crate::config::Config;9-use crate::entry::DirEntry;9+use crate::dir_entry::DirEntry;10 use crate::error::print_error;11 use crate::exit_codes::ExitCode;12 use crate::filesystem::strip_current_dir;13 165 unmodified linesmodified:src/walk.rs+1 added-1 removed
13 unmodified lines14 use ignore::{self, WalkBuilder};15 use regex::bytes::Regex;16 17 use crate::config::Config;18-use crate::entry::DirEntry;18+use crate::dir_entry::DirEntry;19 use crate::error::print_error;20 use crate::exec;21 use crate::exit_codes::{merge_exitcodes, ExitCode};22 use crate::filesystem;548 unmodified lines