Skip to content

Commit

Permalink
add TODOs and always print file list
Browse files Browse the repository at this point in the history
  • Loading branch information
taminob committed Feb 6, 2024
1 parent e599c45 commit 7bb11c7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
16 changes: 13 additions & 3 deletions src/fs/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ impl Filelike for ArchiveEntry {
}

fn absolute_path(&self) -> Option<&PathBuf> {
// TODO: join with archive path
// TODO: could be argued that this should also include path to archive;
// but that would be kind of ugly to implement since every ArchiveEntry
// either needs to store the entire path or keep a reference to the
// archive which would then have to have mutable content (since it has
// to be constructed before any entry is created); thus, I think this
// behavior is sufficient
Some(&self.path)
}

Expand Down Expand Up @@ -145,7 +150,8 @@ impl Filelike for ArchiveEntry {

#[cfg(unix)]
fn inode(&self) -> f::Inode {
f::Inode(0) // TODO
// inode 0 can be used to indicate that there is no inode
f::Inode(0)
}

#[cfg(unix)]
Expand Down Expand Up @@ -180,7 +186,9 @@ impl Filelike for ArchiveEntry {
}

fn is_empty_dir(&self) -> bool {
false // TODO
// TODO: could check if there is any other entry in archive with "{path}/" as prefix;
// but kind of expensive for very little benefit
false
}

fn modified_time(&self) -> Option<NaiveDateTime> {
Expand Down Expand Up @@ -460,6 +468,8 @@ impl Archive {
))
}
}?;
// TODO: could check if any in `contents` is Err and then
// return Err for silent fail
Ok(Archive {
format,
path,
Expand Down
2 changes: 2 additions & 0 deletions src/fs/filelike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ pub trait Filelike {
/// instead.
fn deref_links(&self) -> bool;

/// Get the extended attributes of a file
fn extended_attributes(&self) -> &[Attribute];

/// Metadata for file in filesystem
fn metadata(&self) -> Option<&Metadata>;

/// A reference to the directory that contains this file, if any.
Expand Down
46 changes: 16 additions & 30 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,13 @@ impl<'args> Exa<'args> {

let no_files = files.is_empty();
let no_archives = archives.is_empty();
let is_only_archive = archives.len() == 1 && files.len() == 1 && dirs.is_empty();
let is_only_dir = dirs.len() == 1 && no_files && no_archives;

self.options.filter.filter_argument_files(&mut files);
if !is_only_archive {
self.print_files(None, files)?;
}
self.print_files(None, files)?;

for archive in archives {
self.print_archive(&archive, &PathBuf::new(), is_only_archive, is_only_archive)?;
self.print_archive(&archive, &PathBuf::new())?;
}
self.print_dirs(dirs, is_only_dir, is_only_dir, exit_status)
}
Expand Down Expand Up @@ -520,36 +517,25 @@ impl<'args> Exa<'args> {
}
}

fn print_archive(
&mut self,
archive: &Archive,
root: &PathBuf,
mut is_first: bool,
is_only_archive: bool,
) -> io::Result<()> {
fn print_archive(&mut self, archive: &Archive, root: &PathBuf) -> io::Result<()> {
let View {
file_style: file_name::Options { quote_style, .. },
..
} = self.options.view;

// Put a gap between directories, or between the list of files and
// Put a gap between directory listings and between the list of files and
// the first directory.
if is_first {
is_first = false;
} else {
writeln!(&mut self.writer)?;
}

if !is_only_archive {
let parent_path = archive.path.join(root).display().to_string();
self.print_dir_marker(
parent_path
.strip_suffix(std::path::is_separator)
.map(str::to_string)
.unwrap_or(parent_path),
quote_style,
)?;
}
// Before an archive, there will always be a list of files.
writeln!(&mut self.writer)?;

let parent_path = archive.path.join(root).display().to_string();
self.print_dir_marker(
parent_path
.strip_suffix(std::path::is_separator)
.map(str::to_string)
.unwrap_or(parent_path),
quote_style,
)?;

let mut children = Vec::<ArchiveEntry>::new();
for entry in archive.files(root.clone()) {
Expand All @@ -568,7 +554,7 @@ impl<'args> Exa<'args> {
if !recurse_opts.tree && !recurse_opts.is_too_deep(depth) {
self.print_files(Some(root), children.clone())?;
for child_dir in children.iter().filter(|f| f.is_directory()) {
self.print_archive(archive, child_dir.path(), is_first, false)?;
self.print_archive(archive, child_dir.path())?;
}
return Ok(());
}
Expand Down
1 change: 1 addition & 0 deletions src/options/archive_inspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::options::{flags, OptionsError};
pub enum ArchiveInspection {
Always,
Never,
// TODO: option to limit file size (especially for compressed archives)
}

impl ArchiveInspection {
Expand Down

0 comments on commit 7bb11c7

Please sign in to comment.