Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
c2ef996
Initial commit
kimono-koans Sep 19, 2025
4f16995
Fix first test
kimono-koans Sep 19, 2025
d8dc0cb
Fix 2nd test for broken links
kimono-koans Sep 19, 2025
3918da7
Cleanup
kimono-koans Sep 19, 2025
6127017
Fix lints
kimono-koans Sep 19, 2025
ba59811
Cleanup
kimono-koans Sep 19, 2025
2355369
Remove the need to pass around out bufwriter
kimono-koans Sep 19, 2025
3c42725
Cleanup
kimono-koans Sep 19, 2025
f8fc4a9
Cleanup
kimono-koans Sep 19, 2025
18ab2e0
Cleanup
kimono-koans Sep 19, 2025
0914fca
Do not re request metadata for coloring
kimono-koans Sep 19, 2025
106dfd2
Using DirEntry forces more metadata syscalls
kimono-koans Sep 19, 2025
70cf0b1
Cleanup
kimono-koans Sep 19, 2025
a97cadd
Cleanup lints
kimono-koans Sep 19, 2025
1c4d108
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 19, 2025
97d7d47
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 20, 2025
8bd40c8
Lazily obtain security context
kimono-koans Sep 21, 2025
7a95cb3
Cleanup
kimono-koans Sep 21, 2025
cd15f48
Cleanup
kimono-koans Sep 21, 2025
2625cfe
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 21, 2025
c42295a
Fix lints
kimono-koans Sep 21, 2025
758022a
Fix lints
kimono-koans Sep 22, 2025
34cbcb3
Perhaps fix GNU test
kimono-koans Sep 22, 2025
264a431
Revert "Perhaps fix GNU test"
kimono-koans Sep 22, 2025
1b85fd8
Fix GNU test
kimono-koans Sep 22, 2025
c9fa581
Try again to pass GNU test
kimono-koans Sep 22, 2025
025136a
Cleanup
kimono-koans Sep 22, 2025
e347761
Merge branch 'uutils:main' into lazily_obtain_file_type
kimono-koans Sep 22, 2025
aed0445
Cleanup
kimono-koans Sep 22, 2025
ba222c4
Cleanup
kimono-koans Sep 22, 2025
1a7ead9
Reduce unnecessary metadata calls re: symlink targets
kimono-koans Sep 22, 2025
c1446dd
No need to call functions twice
kimono-koans Sep 22, 2025
16bca97
Reduce size of PathData struct by more than 1000 bytes
kimono-koans Sep 22, 2025
51ede86
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 22, 2025
fdd99f6
Fix lints
kimono-koans Sep 22, 2025
a56e6b4
Fix GNU test?
kimono-koans Sep 22, 2025
8cc6772
Fix lints
kimono-koans Sep 22, 2025
5cfc351
Cleanup
kimono-koans Sep 23, 2025
313b8d6
Fix lint
kimono-koans Sep 23, 2025
c10a6f8
Cleanup
kimono-koans Sep 23, 2025
924e183
Never make a syscall when some non-deref metadata is available
kimono-koans Sep 23, 2025
e72dd91
Lazily wait for file_type and metadata
kimono-koans Sep 23, 2025
41afd56
Cleanup
kimono-koans Sep 23, 2025
3360ae4
Cleanup
kimono-koans Sep 23, 2025
ed63bf5
Cleanup
kimono-koans Sep 23, 2025
e504572
Cleanup
kimono-koans Sep 23, 2025
1970a94
Fix lints
kimono-koans Sep 23, 2025
c316a16
Fix lints
kimono-koans Sep 23, 2025
290e8b4
Fix lints
kimono-koans Sep 23, 2025
3b90412
Fix lints
kimono-koans Sep 23, 2025
dd78a35
Fix lints
kimono-koans Sep 23, 2025
c1623e1
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 23, 2025
9c37a8e
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 24, 2025
958f950
Fix GNU test?
kimono-koans Sep 24, 2025
476c0cf
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 24, 2025
3c0e32f
Cleanup
kimono-koans Sep 24, 2025
4775608
Remove dep for non-Windows platforms which causes additional statx calls
kimono-koans Sep 24, 2025
6bb52bb
Fix lints
kimono-koans Sep 24, 2025
77fa475
Fix lints
kimono-koans Sep 24, 2025
20ffda3
Fix lints
kimono-koans Sep 24, 2025
1254352
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 24, 2025
dac83bd
Fix lints
kimono-koans Sep 24, 2025
acf6635
Merge branch 'lazily_obtain_file_type' of https://github.com/kimono-k…
kimono-koans Sep 24, 2025
1eb4193
Revert "Fix lints"
kimono-koans Sep 24, 2025
99f0fed
Revert "Fix lints"
kimono-koans Sep 24, 2025
d064a9f
Revert "Fix lints"
kimono-koans Sep 24, 2025
e9447a4
Revert "Fix lints"
kimono-koans Sep 24, 2025
cb90d1d
Revert "Remove dep for non-Windows platforms which causes additional …
kimono-koans Sep 24, 2025
70929d1
Merge branch 'main' into lazily_obtain_file_type
kimono-koans Sep 25, 2025
f2db26c
Revert to fix silly test
kimono-koans Sep 26, 2025
ef9c819
Revert "Revert to fix silly test"
kimono-koans Sep 26, 2025
d65868f
Lazily obtain security context
kimono-koans Sep 27, 2025
13c2091
From() was the wrong method to set a OnceCell
kimono-koans Sep 27, 2025
e3f6036
Fix PathData
kimono-koans Sep 27, 2025
cd27894
Working
kimono-koans Sep 27, 2025
7400d3a
Fix lints
kimono-koans Sep 27, 2025
c40c0fe
Reduce struct size
kimono-koans Sep 27, 2025
29924fd
Cleanup
kimono-koans Sep 27, 2025
1c1a829
Merge branch 'uutils:main' into lazily_obtain_file_type
kimono-koans Sep 27, 2025
0223a3e
Cleanup obtaining metadata for sorting
kimono-koans Sep 28, 2025
831e426
Don't get unneeded metadata
kimono-koans Sep 28, 2025
b51b672
No need to create string when str will do
kimono-koans Sep 28, 2025
71b85c6
Use fnv as hasher
kimono-koans Sep 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/uu/ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ansi-width = { workspace = true }
clap = { workspace = true, features = ["env"] }
glob = { workspace = true }
hostname = { workspace = true }
fnv = { workspace = true }
lscolors = { workspace = true }
selinux = { workspace = true, optional = true }
terminal_size = { workspace = true }
Expand Down
37 changes: 15 additions & 22 deletions src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use super::PathData;
use super::get_metadata_with_deref_opt;
use lscolors::{Indicator, LsColors, Style};
use lscolors::{Colorable, Indicator, LsColors, Style};
use std::ffi::OsString;
use std::fs::{DirEntry, Metadata};
use std::io::{BufWriter, Stdout};
use std::fs::Metadata;

/// We need this struct to be able to store the previous style.
/// This because we need to check the previous value in case we don't need
Expand Down Expand Up @@ -135,25 +133,22 @@ impl<'a> StyleManager<'a> {
self.apply_style(style, name, wrap)
}

pub(crate) fn apply_style_based_on_dir_entry(
pub(crate) fn apply_style_based_on_colorable<T: Colorable>(
&mut self,
dir_entry: &DirEntry,
path: &T,
name: OsString,
wrap: bool,
) -> OsString {
let style = self.colors.style_for(dir_entry);
let style = self.colors.style_for(path);
self.apply_style(style, name, wrap)
}
}

/// Colors the provided name based on the style determined for the given path
/// This function is quite long because it tries to leverage [`DirEntry`] to avoid
/// unnecessary calls to stat and manages the symlink errors
pub(crate) fn color_name(
name: OsString,
path: &PathData,
style_manager: &mut StyleManager,
out: &mut BufWriter<Stdout>,
target_symlink: Option<&PathData>,
wrap: bool,
) -> OsString {
Expand All @@ -179,23 +174,21 @@ pub(crate) fn color_name(

if !path.must_dereference {
// If we need to dereference (follow) a symlink, we will need to get the metadata
if let Some(de) = &path.de {
// There is a DirEntry, we don't need to get the metadata for the color
return style_manager.apply_style_based_on_dir_entry(de, name, wrap);
}
// There is a DirEntry, we don't need to get the metadata for the color
return style_manager.apply_style_based_on_colorable(path, name, wrap);
}

if let Some(target) = target_symlink {
// use the optional target_symlink
// Use fn get_metadata_with_deref_opt instead of get_metadata() here because ls
// Use fn symlink_metadata directly instead of get_metadata() here because ls
// should not exit with an err, if we are unable to obtain the target_metadata
let md_res = get_metadata_with_deref_opt(&target.p_buf, path.must_dereference);
let md = md_res.or_else(|_| path.p_buf.symlink_metadata());
style_manager.apply_style_based_on_metadata(path, md.ok().as_ref(), name, wrap)
style_manager.apply_style_based_on_colorable(target, name, wrap)
} else {
let md_option = path.get_metadata(out);
let symlink_metadata = path.p_buf.symlink_metadata().ok();
let md = md_option.or(symlink_metadata.as_ref());
style_manager.apply_style_based_on_metadata(path, md, name, wrap)
let md_option: Option<Metadata> = path
.metadata()
.cloned()
.or_else(|| path.p_buf.symlink_metadata().ok());

style_manager.apply_style_based_on_metadata(path, md_option.as_ref(), name, wrap)
}
}
Loading
Loading