You've already forked uutils.github.io
mirror of
https://github.com/uutils/uutils.github.io.git
synced 2026-06-10 16:12:28 -07:00
deploy: f0e8d44e6e
This commit is contained in:
+2
-2
File diff suppressed because one or more lines are too long
+134
-56
@@ -963,6 +963,45 @@
|
||||
<a href="#963" id="963">963</a>
|
||||
<a href="#964" id="964">964</a>
|
||||
<a href="#965" id="965">965</a>
|
||||
<a href="#966" id="966">966</a>
|
||||
<a href="#967" id="967">967</a>
|
||||
<a href="#968" id="968">968</a>
|
||||
<a href="#969" id="969">969</a>
|
||||
<a href="#970" id="970">970</a>
|
||||
<a href="#971" id="971">971</a>
|
||||
<a href="#972" id="972">972</a>
|
||||
<a href="#973" id="973">973</a>
|
||||
<a href="#974" id="974">974</a>
|
||||
<a href="#975" id="975">975</a>
|
||||
<a href="#976" id="976">976</a>
|
||||
<a href="#977" id="977">977</a>
|
||||
<a href="#978" id="978">978</a>
|
||||
<a href="#979" id="979">979</a>
|
||||
<a href="#980" id="980">980</a>
|
||||
<a href="#981" id="981">981</a>
|
||||
<a href="#982" id="982">982</a>
|
||||
<a href="#983" id="983">983</a>
|
||||
<a href="#984" id="984">984</a>
|
||||
<a href="#985" id="985">985</a>
|
||||
<a href="#986" id="986">986</a>
|
||||
<a href="#987" id="987">987</a>
|
||||
<a href="#988" id="988">988</a>
|
||||
<a href="#989" id="989">989</a>
|
||||
<a href="#990" id="990">990</a>
|
||||
<a href="#991" id="991">991</a>
|
||||
<a href="#992" id="992">992</a>
|
||||
<a href="#993" id="993">993</a>
|
||||
<a href="#994" id="994">994</a>
|
||||
<a href="#995" id="995">995</a>
|
||||
<a href="#996" id="996">996</a>
|
||||
<a href="#997" id="997">997</a>
|
||||
<a href="#998" id="998">998</a>
|
||||
<a href="#999" id="999">999</a>
|
||||
<a href="#1000" id="1000">1000</a>
|
||||
<a href="#1001" id="1001">1001</a>
|
||||
<a href="#1002" id="1002">1002</a>
|
||||
<a href="#1003" id="1003">1003</a>
|
||||
<a href="#1004" id="1004">1004</a>
|
||||
</pre><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
|
||||
// *
|
||||
// * (c) Derek Chiang <derekchiang93@gmail.com>
|
||||
@@ -998,7 +1037,7 @@
|
||||
<span class="kw">use </span>std::{error::Error, fmt::Display};
|
||||
<span class="kw">use </span>uucore::display::{print_verbatim, Quotable};
|
||||
<span class="kw">use </span>uucore::error::FromIo;
|
||||
<span class="kw">use </span>uucore::error::{UError, UResult};
|
||||
<span class="kw">use </span>uucore::error::{set_exit_code, UError, UResult};
|
||||
<span class="kw">use </span>uucore::parse_glob;
|
||||
<span class="kw">use </span>uucore::parse_size::{parse_size, ParseSizeError};
|
||||
<span class="kw">use </span>uucore::{
|
||||
@@ -1033,6 +1072,7 @@
|
||||
<span class="kw">pub const </span>TIME_STYLE: <span class="kw-2">&</span>str = <span class="string">"time-style"</span>;
|
||||
<span class="kw">pub const </span>ONE_FILE_SYSTEM: <span class="kw-2">&</span>str = <span class="string">"one-file-system"</span>;
|
||||
<span class="kw">pub const </span>DEREFERENCE: <span class="kw-2">&</span>str = <span class="string">"dereference"</span>;
|
||||
<span class="kw">pub const </span>DEREFERENCE_ARGS: <span class="kw-2">&</span>str = <span class="string">"dereference-args"</span>;
|
||||
<span class="kw">pub const </span>INODES: <span class="kw-2">&</span>str = <span class="string">"inodes"</span>;
|
||||
<span class="kw">pub const </span>EXCLUDE: <span class="kw-2">&</span>str = <span class="string">"exclude"</span>;
|
||||
<span class="kw">pub const </span>EXCLUDE_FROM: <span class="kw-2">&</span>str = <span class="string">"exclude-from"</span>;
|
||||
@@ -1053,11 +1093,18 @@
|
||||
total: bool,
|
||||
separate_dirs: bool,
|
||||
one_file_system: bool,
|
||||
dereference: bool,
|
||||
dereference: Deref,
|
||||
inodes: bool,
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
<span class="attr">#[derive(PartialEq)]
|
||||
</span><span class="kw">enum </span>Deref {
|
||||
All,
|
||||
Args(Vec<PathBuf>),
|
||||
<span class="prelude-val">None</span>,
|
||||
}
|
||||
|
||||
<span class="attr">#[derive(PartialEq, Eq, Hash, Clone, Copy)]
|
||||
</span><span class="kw">struct </span>FileInfo {
|
||||
file_id: u128,
|
||||
@@ -1077,12 +1124,21 @@
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Stat {
|
||||
<span class="kw">fn </span>new(path: PathBuf, options: <span class="kw-2">&</span>Options) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||||
<span class="kw">let </span>metadata = <span class="kw">if </span>options.dereference {
|
||||
fs::metadata(<span class="kw-2">&</span>path)<span class="question-mark">?
|
||||
</span>} <span class="kw">else </span>{
|
||||
fs::symlink_metadata(<span class="kw-2">&</span>path)<span class="question-mark">?
|
||||
</span>};
|
||||
<span class="kw">fn </span>new(path: <span class="kw-2">&</span>Path, options: <span class="kw-2">&</span>Options) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||||
<span class="comment">// Determine whether to dereference (follow) the symbolic link
|
||||
</span><span class="kw">let </span>should_dereference = <span class="kw">match </span><span class="kw-2">&</span>options.dereference {
|
||||
Deref::All => <span class="bool-val">true</span>,
|
||||
Deref::Args(paths) => paths.contains(<span class="kw-2">&</span>path.to_path_buf()),
|
||||
Deref::None => <span class="bool-val">false</span>,
|
||||
};
|
||||
|
||||
<span class="kw">let </span>metadata = <span class="kw">if </span>should_dereference {
|
||||
<span class="comment">// Get metadata, following symbolic links if necessary
|
||||
</span>fs::metadata(path)
|
||||
} <span class="kw">else </span>{
|
||||
<span class="comment">// Get metadata without following symbolic links
|
||||
</span>fs::symlink_metadata(path)
|
||||
}<span class="question-mark">?</span>;
|
||||
|
||||
<span class="attr">#[cfg(not(windows))]
|
||||
</span><span class="kw">let </span>file_info = FileInfo {
|
||||
@@ -1091,7 +1147,7 @@
|
||||
};
|
||||
<span class="attr">#[cfg(not(windows))]
|
||||
</span><span class="kw">return </span><span class="prelude-val">Ok</span>(<span class="self">Self </span>{
|
||||
path,
|
||||
path: path.to_path_buf(),
|
||||
is_dir: metadata.is_dir(),
|
||||
size: metadata.len(),
|
||||
blocks: metadata.blocks(),
|
||||
@@ -1103,12 +1159,12 @@
|
||||
});
|
||||
|
||||
<span class="attr">#[cfg(windows)]
|
||||
</span><span class="kw">let </span>size_on_disk = get_size_on_disk(<span class="kw-2">&</span>path);
|
||||
</span><span class="kw">let </span>size_on_disk = get_size_on_disk(path);
|
||||
<span class="attr">#[cfg(windows)]
|
||||
</span><span class="kw">let </span>file_info = get_file_info(<span class="kw-2">&</span>path);
|
||||
</span><span class="kw">let </span>file_info = get_file_info(path);
|
||||
<span class="attr">#[cfg(windows)]
|
||||
</span><span class="prelude-val">Ok</span>(<span class="self">Self </span>{
|
||||
path,
|
||||
path: path.to_path_buf(),
|
||||
is_dir: metadata.is_dir(),
|
||||
size: metadata.len(),
|
||||
blocks: size_on_disk / <span class="number">1024 </span>* <span class="number">2</span>,
|
||||
@@ -1261,7 +1317,7 @@
|
||||
<span class="lifetime">'file_loop</span>: <span class="kw">for </span>f <span class="kw">in </span>read {
|
||||
<span class="kw">match </span>f {
|
||||
<span class="prelude-val">Ok</span>(entry) => {
|
||||
<span class="kw">match </span>Stat::new(entry.path(), options) {
|
||||
<span class="kw">match </span>Stat::new(<span class="kw-2">&</span>entry.path(), options) {
|
||||
<span class="prelude-val">Ok</span>(this_stat) => {
|
||||
<span class="comment">// We have an exclude list
|
||||
</span><span class="kw">for </span>pattern <span class="kw">in </span>exclude {
|
||||
@@ -1362,6 +1418,20 @@
|
||||
<span class="macro">format!</span>(<span class="string">"{}"</span>, ((size <span class="kw">as </span>f64) / (block_size <span class="kw">as </span>f64)).ceil())
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>get_convert_size_fn(matches: <span class="kw-2">&</span>ArgMatches) -> Box<<span class="kw">dyn </span>Fn(u64, u64, u64) -> String> {
|
||||
<span class="kw">if </span>matches.get_flag(options::HUMAN_READABLE) || matches.get_flag(options::SI) {
|
||||
Box::new(convert_size_human)
|
||||
} <span class="kw">else if </span>matches.get_flag(options::BYTES) {
|
||||
Box::new(convert_size_b)
|
||||
} <span class="kw">else if </span>matches.get_flag(options::BLOCK_SIZE_1K) {
|
||||
Box::new(convert_size_k)
|
||||
} <span class="kw">else if </span>matches.get_flag(options::BLOCK_SIZE_1M) {
|
||||
Box::new(convert_size_m)
|
||||
} <span class="kw">else </span>{
|
||||
Box::new(convert_size_other)
|
||||
}
|
||||
}
|
||||
|
||||
<span class="attr">#[derive(Debug)]
|
||||
</span><span class="kw">enum </span>DuError {
|
||||
InvalidMaxDepthArg(String),
|
||||
@@ -1455,7 +1525,6 @@ Try '{} --help' for more information."</span>,
|
||||
}
|
||||
|
||||
<span class="attr">#[uucore::main]
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
</span><span class="kw">pub fn </span>uumain(args: <span class="kw">impl </span>uucore::Args) -> UResult<()> {
|
||||
<span class="kw">let </span>args = args.collect_ignore();
|
||||
|
||||
@@ -1470,26 +1539,33 @@ Try '{} --help' for more information."</span>,
|
||||
summarize,
|
||||
)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span>files = <span class="kw">match </span>matches.get_one::<String>(options::FILE) {
|
||||
<span class="prelude-val">Some</span>(<span class="kw">_</span>) => matches
|
||||
.get_many::<String>(options::FILE)
|
||||
.unwrap()
|
||||
.map(PathBuf::from)
|
||||
.collect(),
|
||||
<span class="prelude-val">None </span>=> <span class="macro">vec!</span>[PathBuf::from(<span class="string">"."</span>)],
|
||||
};
|
||||
|
||||
<span class="kw">let </span>options = Options {
|
||||
all: matches.get_flag(options::ALL),
|
||||
max_depth,
|
||||
total: matches.get_flag(options::TOTAL),
|
||||
separate_dirs: matches.get_flag(options::SEPARATE_DIRS),
|
||||
one_file_system: matches.get_flag(options::ONE_FILE_SYSTEM),
|
||||
dereference: matches.get_flag(options::DEREFERENCE),
|
||||
dereference: <span class="kw">if </span>matches.get_flag(options::DEREFERENCE) {
|
||||
Deref::All
|
||||
} <span class="kw">else if </span>matches.get_flag(options::DEREFERENCE_ARGS) {
|
||||
<span class="comment">// We don't care about the cost of cloning as it is rarely used
|
||||
</span>Deref::Args(files.clone())
|
||||
} <span class="kw">else </span>{
|
||||
Deref::None
|
||||
},
|
||||
inodes: matches.get_flag(options::INODES),
|
||||
verbose: matches.get_flag(options::VERBOSE),
|
||||
};
|
||||
|
||||
<span class="kw">let </span>files = <span class="kw">match </span>matches.get_one::<String>(options::FILE) {
|
||||
<span class="prelude-val">Some</span>(<span class="kw">_</span>) => matches
|
||||
.get_many::<String>(options::FILE)
|
||||
.unwrap()
|
||||
.map(|s| s.as_str())
|
||||
.collect(),
|
||||
<span class="prelude-val">None </span>=> <span class="macro">vec!</span>[<span class="string">"."</span>],
|
||||
};
|
||||
|
||||
<span class="kw">if </span>options.inodes
|
||||
&& (matches.get_flag(options::APPARENT_SIZE) || matches.get_flag(options::BYTES))
|
||||
{
|
||||
@@ -1512,19 +1588,9 @@ Try '{} --help' for more information."</span>,
|
||||
</span>} <span class="kw">else </span>{
|
||||
<span class="number">1024
|
||||
</span>};
|
||||
<span class="kw">let </span>convert_size_fn = {
|
||||
<span class="kw">if </span>matches.get_flag(options::HUMAN_READABLE) || matches.get_flag(options::SI) {
|
||||
convert_size_human
|
||||
} <span class="kw">else if </span>matches.get_flag(options::BYTES) {
|
||||
convert_size_b
|
||||
} <span class="kw">else if </span>matches.get_flag(options::BLOCK_SIZE_1K) {
|
||||
convert_size_k
|
||||
} <span class="kw">else if </span>matches.get_flag(options::BLOCK_SIZE_1M) {
|
||||
convert_size_m
|
||||
} <span class="kw">else </span>{
|
||||
convert_size_other
|
||||
}
|
||||
};
|
||||
|
||||
<span class="kw">let </span>convert_size_fn = get_convert_size_fn(<span class="kw-2">&</span>matches);
|
||||
|
||||
<span class="kw">let </span>convert_size = |size: u64| {
|
||||
<span class="kw">if </span>options.inodes {
|
||||
size.to_string()
|
||||
@@ -1545,11 +1611,12 @@ Try '{} --help' for more information."</span>,
|
||||
<span class="kw">let </span>excludes = build_exclude_patterns(<span class="kw-2">&</span>matches)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>grand_total = <span class="number">0</span>;
|
||||
<span class="lifetime">'loop_file</span>: <span class="kw">for </span>path_string <span class="kw">in </span>files {
|
||||
<span class="lifetime">'loop_file</span>: <span class="kw">for </span>path <span class="kw">in </span>files {
|
||||
<span class="comment">// Skip if we don't want to ignore anything
|
||||
</span><span class="kw">if </span>!<span class="kw-2">&</span>excludes.is_empty() {
|
||||
<span class="kw">let </span>path_string = path.to_string_lossy();
|
||||
<span class="kw">for </span>pattern <span class="kw">in </span><span class="kw-2">&</span>excludes {
|
||||
<span class="kw">if </span>pattern.matches(path_string) {
|
||||
<span class="kw">if </span>pattern.matches(<span class="kw-2">&</span>path_string) {
|
||||
<span class="comment">// if the directory is ignored, leave early
|
||||
</span><span class="kw">if </span>options.verbose {
|
||||
<span class="macro">println!</span>(<span class="string">"{} ignored"</span>, path_string.quote());
|
||||
@@ -1559,9 +1626,8 @@ Try '{} --help' for more information."</span>,
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">let </span>path = PathBuf::from(<span class="kw-2">&</span>path_string);
|
||||
<span class="comment">// Check existence of path provided in argument
|
||||
</span><span class="kw">if let </span><span class="prelude-val">Ok</span>(stat) = Stat::new(path, <span class="kw-2">&</span>options) {
|
||||
</span><span class="kw">if let </span><span class="prelude-val">Ok</span>(stat) = Stat::new(<span class="kw-2">&</span>path, <span class="kw-2">&</span>options) {
|
||||
<span class="comment">// Kick off the computation of disk usage from the initial path
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>inodes: HashSet<FileInfo> = HashSet::new();
|
||||
<span class="kw">if let </span><span class="prelude-val">Some</span>(inode) = stat.inode {
|
||||
@@ -1581,20 +1647,11 @@ Try '{} --help' for more information."</span>,
|
||||
|
||||
<span class="kw">if </span>matches.contains_id(options::TIME) {
|
||||
<span class="kw">let </span>tm = {
|
||||
<span class="kw">let </span>secs = {
|
||||
<span class="kw">match </span>matches.get_one::<String>(options::TIME) {
|
||||
<span class="prelude-val">Some</span>(s) => <span class="kw">match </span>s.as_str() {
|
||||
<span class="string">"ctime" </span>| <span class="string">"status" </span>=> stat.modified,
|
||||
<span class="string">"access" </span>| <span class="string">"atime" </span>| <span class="string">"use" </span>=> stat.accessed,
|
||||
<span class="string">"birth" </span>| <span class="string">"creation" </span>=> stat
|
||||
.created
|
||||
.ok_or_else(|| DuError::InvalidTimeArg(s.into()))<span class="question-mark">?</span>,
|
||||
<span class="comment">// below should never happen as clap already restricts the values.
|
||||
</span><span class="kw">_ </span>=> <span class="macro">unreachable!</span>(<span class="string">"Invalid field for --time"</span>),
|
||||
},
|
||||
<span class="prelude-val">None </span>=> stat.modified,
|
||||
}
|
||||
};
|
||||
<span class="kw">let </span>secs = matches
|
||||
.get_one::<String>(options::TIME)
|
||||
.map(|s| get_time_secs(s, <span class="kw-2">&</span>stat))
|
||||
.transpose()<span class="question-mark">?
|
||||
</span>.unwrap_or(stat.modified);
|
||||
DateTime::<Local>::from(UNIX_EPOCH + Duration::from_secs(secs))
|
||||
};
|
||||
<span class="kw">if </span>!summarize || index == len - <span class="number">1 </span>{
|
||||
@@ -1617,9 +1674,10 @@ Try '{} --help' for more information."</span>,
|
||||
} <span class="kw">else </span>{
|
||||
<span class="macro">show_error!</span>(
|
||||
<span class="string">"{}: {}"</span>,
|
||||
path_string.maybe_quote(),
|
||||
path.to_string_lossy().maybe_quote(),
|
||||
<span class="string">"No such file or directory"
|
||||
</span>);
|
||||
set_exit_code(<span class="number">1</span>);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1631,6 +1689,19 @@ Try '{} --help' for more information."</span>,
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>get_time_secs(s: <span class="kw-2">&</span>str, stat: <span class="kw-2">&</span>Stat) -> std::result::Result<u64, DuError> {
|
||||
<span class="kw">let </span>secs = <span class="kw">match </span>s {
|
||||
<span class="string">"ctime" </span>| <span class="string">"status" </span>=> stat.modified,
|
||||
<span class="string">"access" </span>| <span class="string">"atime" </span>| <span class="string">"use" </span>=> stat.accessed,
|
||||
<span class="string">"birth" </span>| <span class="string">"creation" </span>=> stat
|
||||
.created
|
||||
.ok_or_else(|| DuError::InvalidTimeArg(s.into()))<span class="question-mark">?</span>,
|
||||
<span class="comment">// below should never happen as clap already restricts the values.
|
||||
</span><span class="kw">_ </span>=> <span class="macro">unreachable!</span>(<span class="string">"Invalid field for --time"</span>),
|
||||
};
|
||||
<span class="prelude-val">Ok</span>(secs)
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>parse_time_style(s: <span class="prelude-ty">Option</span><<span class="kw-2">&</span>str>) -> UResult<<span class="kw-2">&</span>str> {
|
||||
<span class="kw">match </span>s {
|
||||
<span class="prelude-val">Some</span>(s) => <span class="kw">match </span>s {
|
||||
@@ -1753,6 +1824,13 @@ Try '{} --help' for more information."</span>,
|
||||
.help(<span class="string">"dereference all symbolic links"</span>)
|
||||
.action(ArgAction::SetTrue)
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::DEREFERENCE_ARGS)
|
||||
.short(<span class="string">'D'</span>)
|
||||
.long(options::DEREFERENCE_ARGS)
|
||||
.help(<span class="string">"dereference only symlinks that are listed on the command line"</span>)
|
||||
.action(ArgAction::SetTrue)
|
||||
)
|
||||
<span class="comment">// .arg(
|
||||
// Arg::new("no-dereference")
|
||||
// .short('P')
|
||||
|
||||
@@ -685,6 +685,42 @@
|
||||
<a href="#685" id="685">685</a>
|
||||
<a href="#686" id="686">686</a>
|
||||
<a href="#687" id="687">687</a>
|
||||
<a href="#688" id="688">688</a>
|
||||
<a href="#689" id="689">689</a>
|
||||
<a href="#690" id="690">690</a>
|
||||
<a href="#691" id="691">691</a>
|
||||
<a href="#692" id="692">692</a>
|
||||
<a href="#693" id="693">693</a>
|
||||
<a href="#694" id="694">694</a>
|
||||
<a href="#695" id="695">695</a>
|
||||
<a href="#696" id="696">696</a>
|
||||
<a href="#697" id="697">697</a>
|
||||
<a href="#698" id="698">698</a>
|
||||
<a href="#699" id="699">699</a>
|
||||
<a href="#700" id="700">700</a>
|
||||
<a href="#701" id="701">701</a>
|
||||
<a href="#702" id="702">702</a>
|
||||
<a href="#703" id="703">703</a>
|
||||
<a href="#704" id="704">704</a>
|
||||
<a href="#705" id="705">705</a>
|
||||
<a href="#706" id="706">706</a>
|
||||
<a href="#707" id="707">707</a>
|
||||
<a href="#708" id="708">708</a>
|
||||
<a href="#709" id="709">709</a>
|
||||
<a href="#710" id="710">710</a>
|
||||
<a href="#711" id="711">711</a>
|
||||
<a href="#712" id="712">712</a>
|
||||
<a href="#713" id="713">713</a>
|
||||
<a href="#714" id="714">714</a>
|
||||
<a href="#715" id="715">715</a>
|
||||
<a href="#716" id="716">716</a>
|
||||
<a href="#717" id="717">717</a>
|
||||
<a href="#718" id="718">718</a>
|
||||
<a href="#719" id="719">719</a>
|
||||
<a href="#720" id="720">720</a>
|
||||
<a href="#721" id="721">721</a>
|
||||
<a href="#722" id="722">722</a>
|
||||
<a href="#723" id="723">723</a>
|
||||
</pre><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
|
||||
// *
|
||||
// * (c) Alex Lyon <arcterus@mail.com>
|
||||
@@ -752,7 +788,28 @@
|
||||
<span class="string">"sha256sum" </span>=> (<span class="string">"SHA256"</span>, Box::new(Sha256::new()) <span class="kw">as </span>Box<<span class="kw">dyn </span>Digest>, <span class="number">256</span>),
|
||||
<span class="string">"sha384sum" </span>=> (<span class="string">"SHA384"</span>, Box::new(Sha384::new()) <span class="kw">as </span>Box<<span class="kw">dyn </span>Digest>, <span class="number">384</span>),
|
||||
<span class="string">"sha512sum" </span>=> (<span class="string">"SHA512"</span>, Box::new(Sha512::new()) <span class="kw">as </span>Box<<span class="kw">dyn </span>Digest>, <span class="number">512</span>),
|
||||
<span class="string">"b2sum" </span>=> (<span class="string">"BLAKE2"</span>, Box::new(Blake2b::new()) <span class="kw">as </span>Box<<span class="kw">dyn </span>Digest>, <span class="number">512</span>),
|
||||
<span class="string">"b2sum" </span>=> <span class="kw">match </span>matches.get_one::<usize>(<span class="string">"length"</span>) {
|
||||
<span class="comment">// by default, blake2 uses 64 bytes (512 bits)
|
||||
// --length=0 falls back to default behavior
|
||||
</span><span class="prelude-val">Some</span>(<span class="number">0</span>) | <span class="prelude-val">None </span>=> (<span class="string">"BLAKE2"</span>, Box::new(Blake2b::new()) <span class="kw">as </span>Box<<span class="kw">dyn </span>Digest>, <span class="number">512</span>),
|
||||
<span class="prelude-val">Some</span>(length_in_bits) => {
|
||||
<span class="kw">if </span><span class="kw-2">*</span>length_in_bits > <span class="number">512 </span>{
|
||||
<span class="macro">crash!</span>(<span class="number">1</span>, <span class="string">"Invalid length (maximum digest length is 512 bits)"</span>)
|
||||
}
|
||||
|
||||
<span class="comment">// blake2 output size must be a multiple of 8 bits
|
||||
</span><span class="kw">if </span>length_in_bits % <span class="number">8 </span>== <span class="number">0 </span>{
|
||||
<span class="kw">let </span>length_in_bytes = length_in_bits / <span class="number">8</span>;
|
||||
(
|
||||
<span class="string">"BLAKE2"</span>,
|
||||
Box::new(Blake2b::with_output_bytes(length_in_bytes)),
|
||||
<span class="kw-2">*</span>length_in_bits,
|
||||
)
|
||||
} <span class="kw">else </span>{
|
||||
<span class="macro">crash!</span>(<span class="number">1</span>, <span class="string">"Invalid length (expected a multiple of 8)"</span>)
|
||||
}
|
||||
}
|
||||
},
|
||||
<span class="string">"b3sum" </span>=> (<span class="string">"BLAKE3"</span>, Box::new(Blake3::new()) <span class="kw">as </span>Box<<span class="kw">dyn </span>Digest>, <span class="number">256</span>),
|
||||
<span class="string">"sha3sum" </span>=> <span class="kw">match </span>matches.get_one::<usize>(<span class="string">"bits"</span>) {
|
||||
<span class="prelude-val">Some</span>(<span class="number">224</span>) => (
|
||||
@@ -1066,6 +1123,21 @@
|
||||
)
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>uu_app_length() -> Command {
|
||||
uu_app_opt_length(uu_app_common())
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>uu_app_opt_length(command: Command) -> Command {
|
||||
command.arg(
|
||||
Arg::new(<span class="string">"length"</span>)
|
||||
.short(<span class="string">'l'</span>)
|
||||
.long(<span class="string">"length"</span>)
|
||||
.help(<span class="string">"digest length in bits; must not exceed the max for the blake2 algorithm (512) and must be a multiple of 8"</span>)
|
||||
.value_name(<span class="string">"BITS"</span>)
|
||||
.value_parser(parse_bit_num),
|
||||
)
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>uu_app_b3sum() -> Command {
|
||||
uu_app_b3sum_opts(uu_app_common())
|
||||
}
|
||||
@@ -1141,8 +1213,8 @@
|
||||
uu_app_common()
|
||||
}
|
||||
<span class="comment">// b2sum supports the md5sum options plus -l/--length.
|
||||
</span><span class="string">"b2sum" </span>=> uu_app_common(), <span class="comment">// TODO: Implement -l/--length
|
||||
// These have never been part of GNU Coreutils, but can function with the same
|
||||
</span><span class="string">"b2sum" </span>=> uu_app_length(),
|
||||
<span class="comment">// These have never been part of GNU Coreutils, but can function with the same
|
||||
// options as md5sum.
|
||||
</span><span class="string">"sha3-224sum" </span>| <span class="string">"sha3-256sum" </span>| <span class="string">"sha3-384sum" </span>| <span class="string">"sha3-512sum" </span>=> uu_app_common(),
|
||||
<span class="comment">// These have never been part of GNU Coreutils, and require an additional --bits
|
||||
|
||||
@@ -492,6 +492,21 @@
|
||||
<a href="#492" id="492">492</a>
|
||||
<a href="#493" id="493">493</a>
|
||||
<a href="#494" id="494">494</a>
|
||||
<a href="#495" id="495">495</a>
|
||||
<a href="#496" id="496">496</a>
|
||||
<a href="#497" id="497">497</a>
|
||||
<a href="#498" id="498">498</a>
|
||||
<a href="#499" id="499">499</a>
|
||||
<a href="#500" id="500">500</a>
|
||||
<a href="#501" id="501">501</a>
|
||||
<a href="#502" id="502">502</a>
|
||||
<a href="#503" id="503">503</a>
|
||||
<a href="#504" id="504">504</a>
|
||||
<a href="#505" id="505">505</a>
|
||||
<a href="#506" id="506">506</a>
|
||||
<a href="#507" id="507">507</a>
|
||||
<a href="#508" id="508">508</a>
|
||||
<a href="#509" id="509">509</a>
|
||||
</pre><pre class="rust"><code><span class="comment">// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// (c) Yuan YangHao <yuanyanghau@gmail.com>
|
||||
@@ -532,10 +547,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub struct </span>Blake2b(blake2b_simd::State);
|
||||
<span class="doccomment">/// first element of the tuple is the blake2b state
|
||||
/// second is the number of output bits
|
||||
</span><span class="kw">pub struct </span>Blake2b(blake2b_simd::State, usize);
|
||||
|
||||
<span class="kw">impl </span>Blake2b {
|
||||
<span class="doccomment">/// Return a new Blake2b instance with a custom output bytes length
|
||||
</span><span class="kw">pub fn </span>with_output_bytes(output_bytes: usize) -> <span class="self">Self </span>{
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>params = blake2b_simd::Params::new();
|
||||
params.hash_length(output_bytes);
|
||||
|
||||
<span class="kw">let </span>state = params.to_state();
|
||||
<span class="self">Self</span>(state, output_bytes * <span class="number">8</span>)
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Digest <span class="kw">for </span>Blake2b {
|
||||
<span class="kw">fn </span>new() -> <span class="self">Self </span>{
|
||||
<span class="self">Self</span>(blake2b_simd::State::new())
|
||||
<span class="comment">// by default, Blake2b output is 512 bits long (= 64B)
|
||||
</span><span class="self">Self</span>::with_output_bytes(<span class="number">64</span>)
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>hash_update(<span class="kw-2">&mut </span><span class="self">self</span>, input: <span class="kw-2">&</span>[u8]) {
|
||||
@@ -548,11 +578,11 @@
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>reset(<span class="kw-2">&mut </span><span class="self">self</span>) {
|
||||
<span class="kw-2">*</span><span class="self">self </span>= <span class="self">Self</span>::new();
|
||||
<span class="kw-2">*</span><span class="self">self </span>= <span class="self">Self</span>::with_output_bytes(<span class="self">self</span>.output_bytes());
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>output_bits(<span class="kw-2">&</span><span class="self">self</span>) -> usize {
|
||||
<span class="number">512
|
||||
<span class="self">self</span>.<span class="number">1
|
||||
</span>}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":[["uu_app_b3sum",""],["uu_app_bits",""],["uu_app_common",""],["uu_app_custom",""],["uumain",""]]};
|
||||
window.SIDEBAR_ITEMS = {"fn":[["uu_app_b3sum",""],["uu_app_bits",""],["uu_app_common",""],["uu_app_custom",""],["uu_app_length",""],["uumain",""]]};
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":[["div_ceil",""]],"struct":[["BSD",""],["Blake2b",""],["Blake3",""],["CRC",""],["DigestWriter","A struct that writes to a digest."],["Md5",""],["SYSV",""],["Sha1",""],["Sha224",""],["Sha256",""],["Sha384",""],["Sha3_224",""],["Sha3_256",""],["Sha3_384",""],["Sha3_512",""],["Sha512",""],["Shake128",""],["Shake256",""],["Sm3",""]],"trait":[["Digest",""]]};
|
||||
window.SIDEBAR_ITEMS = {"fn":[["div_ceil",""]],"struct":[["BSD",""],["Blake2b","first element of the tuple is the blake2b state second is the number of output bits"],["Blake3",""],["CRC",""],["DigestWriter","A struct that writes to a digest."],["Md5",""],["SYSV",""],["Sha1",""],["Sha224",""],["Sha256",""],["Sha384",""],["Sha3_224",""],["Sha3_256",""],["Sha3_384",""],["Sha3_512",""],["Sha512",""],["Shake128",""],["Shake256",""],["Sm3",""]],"trait":[["Digest",""]]};
|
||||
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user