This commit is contained in:
sylvestre
2023-06-03 02:48:40 +00:00
parent f61bd3b102
commit 70df8ed633
25 changed files with 147 additions and 75 deletions
+34 -18
View File
@@ -1985,6 +1985,14 @@
<a href="#1985" id="1985">1985</a>
<a href="#1986" id="1986">1986</a>
<a href="#1987" id="1987">1987</a>
<a href="#1988" id="1988">1988</a>
<a href="#1989" id="1989">1989</a>
<a href="#1990" id="1990">1990</a>
<a href="#1991" id="1991">1991</a>
<a href="#1992" id="1992">1992</a>
<a href="#1993" id="1993">1993</a>
<a href="#1994" id="1994">1994</a>
<a href="#1995" id="1995">1995</a>
</pre></div><pre class="rust"><code><span class="attr">#![allow(clippy::missing_safety_doc)]
#![allow(clippy::extra_unused_lifetimes)]
@@ -2030,7 +2038,8 @@
};
<span class="kw">use </span>uucore::update_control::{<span class="self">self</span>, UpdateMode};
<span class="kw">use </span>uucore::{
crash, format_usage, help_about, help_section, help_usage, prompt_yes, show_error, show_warning,
crash, format_usage, help_about, help_section, help_usage, prompt_yes, show_error,
show_warning, util_name,
};
<span class="kw">use </span><span class="kw">crate</span>::copydir::copy_directory;
@@ -3089,24 +3098,22 @@
}
<span class="doccomment">/// When handling errors, we don&#39;t always want to show them to the user. This function handles that.
/// If the error is printed, returns true, false otherwise.
</span><span class="kw">fn </span>show_error_if_needed(error: <span class="kw-2">&amp;</span>Error) -&gt; bool {
</span><span class="kw">fn </span>show_error_if_needed(error: <span class="kw-2">&amp;</span>Error) {
<span class="kw">match </span>error {
<span class="comment">// When using --no-clobber, we don&#39;t want to show
// an error message
</span>Error::NotAllFilesCopied =&gt; (),
</span>Error::NotAllFilesCopied =&gt; {
<span class="comment">// Need to return an error code
</span>}
Error::Skipped =&gt; {
<span class="comment">// touch a b &amp;&amp; echo &quot;n&quot;|cp -i a b &amp;&amp; echo $?
// should return an error from GNU 9.2
</span><span class="kw">return </span><span class="bool-val">true</span>;
}
</span>}
<span class="kw">_ </span>=&gt; {
<span class="macro">show_error!</span>(<span class="string">&quot;{}&quot;</span>, error);
<span class="kw">return </span><span class="bool-val">true</span>;
}
}
<span class="bool-val">false
</span>}
}
<span class="doccomment">/// Copy all `sources` to `target`. Returns an
/// `Err(Error::NotAllFilesCopied)` if at least one non-fatal error was
@@ -3162,9 +3169,8 @@
options,
<span class="kw-2">&amp;mut </span>symlinked_files,
) {
<span class="kw">if </span>show_error_if_needed(<span class="kw-2">&amp;</span>error) {
non_fatal_errors = <span class="bool-val">true</span>;
}
show_error_if_needed(<span class="kw-2">&amp;</span>error);
non_fatal_errors = <span class="bool-val">true</span>;
}
}
seen_sources.insert(source);
@@ -3241,13 +3247,23 @@
}
<span class="kw">impl </span>OverwriteMode {
<span class="kw">fn </span>verify(<span class="kw-2">&amp;</span><span class="self">self</span>, path: <span class="kw-2">&amp;</span>Path) -&gt; CopyResult&lt;()&gt; {
<span class="kw">fn </span>verify(<span class="kw-2">&amp;</span><span class="self">self</span>, path: <span class="kw-2">&amp;</span>Path, verbose: bool) -&gt; CopyResult&lt;()&gt; {
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
<span class="self">Self</span>::NoClobber =&gt; <span class="prelude-val">Err</span>(Error::NotAllFilesCopied),
<span class="self">Self</span>::NoClobber =&gt; {
<span class="kw">if </span>verbose {
<span class="macro">println!</span>(<span class="string">&quot;skipped {}&quot;</span>, path.quote());
} <span class="kw">else </span>{
<span class="macro">eprintln!</span>(<span class="string">&quot;{}: not replacing {}&quot;</span>, util_name(), path.quote());
}
<span class="prelude-val">Err</span>(Error::NotAllFilesCopied)
}
<span class="self">Self</span>::Interactive(<span class="kw">_</span>) =&gt; {
<span class="kw">if </span><span class="macro">prompt_yes!</span>(<span class="string">&quot;overwrite {}?&quot;</span>, path.quote()) {
<span class="prelude-val">Ok</span>(())
} <span class="kw">else </span>{
<span class="kw">if </span>verbose {
<span class="macro">println!</span>(<span class="string">&quot;skipped {}&quot;</span>, path.quote());
}
<span class="prelude-val">Err</span>(Error::Skipped)
}
}
@@ -3455,7 +3471,7 @@
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="macro">format!</span>(<span class="string">&quot;{} and {} are the same file&quot;</span>, source.quote(), dest.quote()).into());
}
options.overwrite.verify(dest)<span class="question-mark">?</span>;
options.overwrite.verify(dest, options.verbose)<span class="question-mark">?</span>;
<span class="kw">let </span>backup_path = backup_control::get_backup_path(options.backup, dest, <span class="kw-2">&amp;</span>options.backup_suffix);
<span class="kw">if let </span><span class="prelude-val">Some</span>(backup_path) = backup_path {
@@ -3813,7 +3829,7 @@
</span>File::create(dest).context(dest.display().to_string())<span class="question-mark">?</span>;
} <span class="kw">else if </span>source_is_fifo &amp;&amp; options.recursive &amp;&amp; !options.copy_contents {
<span class="attr">#[cfg(unix)]
</span>copy_fifo(dest, options.overwrite)<span class="question-mark">?</span>;
</span>copy_fifo(dest, options.overwrite, options.verbose)<span class="question-mark">?</span>;
} <span class="kw">else if </span>source_is_symlink {
copy_link(source, dest, symlinked_files)<span class="question-mark">?</span>;
} <span class="kw">else </span>{
@@ -3838,9 +3854,9 @@
<span class="comment">// &quot;Copies&quot; a FIFO by creating a new one. This workaround is because Rust&#39;s
// built-in fs::copy does not handle FIFOs (see rust-lang/rust/issues/79390).
</span><span class="attr">#[cfg(unix)]
</span><span class="kw">fn </span>copy_fifo(dest: <span class="kw-2">&amp;</span>Path, overwrite: OverwriteMode) -&gt; CopyResult&lt;()&gt; {
</span><span class="kw">fn </span>copy_fifo(dest: <span class="kw-2">&amp;</span>Path, overwrite: OverwriteMode, verbose: bool) -&gt; CopyResult&lt;()&gt; {
<span class="kw">if </span>dest.exists() {
overwrite.verify(dest)<span class="question-mark">?</span>;
overwrite.verify(dest, verbose)<span class="question-mark">?</span>;
fs::remove_file(dest)<span class="question-mark">?</span>;
}
+79 -23
View File
@@ -625,6 +625,34 @@
<a href="#625" id="625">625</a>
<a href="#626" id="626">626</a>
<a href="#627" id="627">627</a>
<a href="#628" id="628">628</a>
<a href="#629" id="629">629</a>
<a href="#630" id="630">630</a>
<a href="#631" id="631">631</a>
<a href="#632" id="632">632</a>
<a href="#633" id="633">633</a>
<a href="#634" id="634">634</a>
<a href="#635" id="635">635</a>
<a href="#636" id="636">636</a>
<a href="#637" id="637">637</a>
<a href="#638" id="638">638</a>
<a href="#639" id="639">639</a>
<a href="#640" id="640">640</a>
<a href="#641" id="641">641</a>
<a href="#642" id="642">642</a>
<a href="#643" id="643">643</a>
<a href="#644" id="644">644</a>
<a href="#645" id="645">645</a>
<a href="#646" id="646">646</a>
<a href="#647" id="647">647</a>
<a href="#648" id="648">648</a>
<a href="#649" id="649">649</a>
<a href="#650" id="650">650</a>
<a href="#651" id="651">651</a>
<a href="#652" id="652">652</a>
<a href="#653" id="653">653</a>
<a href="#654" id="654">654</a>
<a href="#655" id="655">655</a>
</pre></div><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
// *
// * (c) Martin Kysel &lt;code@martinkysel.com&gt;
@@ -641,10 +669,10 @@
time::Duration,
};
<span class="kw">use </span>clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
<span class="kw">use </span>clap::{crate_version, value_parser, Arg, ArgAction, ArgMatches, Command};
<span class="kw">use </span>crossterm::event::KeyEventKind;
<span class="kw">use </span>crossterm::{
cursor::MoveTo,
cursor::{MoveTo, MoveUp},
event::{<span class="self">self</span>, Event, KeyCode, KeyEvent, KeyModifiers},
execute, queue,
style::Attribute,
@@ -680,16 +708,28 @@
<span class="kw">const </span>MULTI_FILE_TOP_PROMPT: <span class="kw-2">&amp;</span>str = <span class="string">&quot;::::::::::::::\n{}\n::::::::::::::\n&quot;</span>;
<span class="kw">struct </span>Options {
silent: bool,
clean_print: bool,
lines: <span class="prelude-ty">Option</span>&lt;u16&gt;,
print_over: bool,
silent: bool,
squeeze: bool,
}
<span class="kw">impl </span>Options {
<span class="kw">fn </span>from(matches: <span class="kw-2">&amp;</span>ArgMatches) -&gt; <span class="self">Self </span>{
<span class="kw">let </span>lines = <span class="kw">match </span>(
matches.get_one::&lt;u16&gt;(options::LINES).copied(),
matches.get_one::&lt;u16&gt;(options::NUMBER).copied(),
) {
<span class="comment">// We add 1 to the number of lines to display because the last line
// is used for the banner
</span>(<span class="prelude-val">Some</span>(number), <span class="kw">_</span>) <span class="kw">if </span>number &gt; <span class="number">0 </span>=&gt; <span class="prelude-val">Some</span>(number + <span class="number">1</span>),
(<span class="prelude-val">None</span>, <span class="prelude-val">Some</span>(number)) <span class="kw">if </span>number &gt; <span class="number">0 </span>=&gt; <span class="prelude-val">Some</span>(number + <span class="number">1</span>),
(<span class="kw">_</span>, <span class="kw">_</span>) =&gt; <span class="prelude-val">None</span>,
};
<span class="self">Self </span>{
clean_print: matches.get_flag(options::CLEAN_PRINT),
lines,
print_over: matches.get_flag(options::PRINT_OVER),
silent: matches.get_flag(options::SILENT),
squeeze: matches.get_flag(options::SQUEEZE),
@@ -794,6 +834,23 @@
.help(<span class="string">&quot;Squeeze multiple blank lines into one&quot;</span>)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::LINES)
.short(<span class="string">&#39;n&#39;</span>)
.long(options::LINES)
.value_name(<span class="string">&quot;number&quot;</span>)
.num_args(<span class="number">1</span>)
.value_parser(<span class="macro">value_parser!</span>(u16).range(<span class="number">0</span>..))
.help(<span class="string">&quot;The number of lines per screen full&quot;</span>),
)
.arg(
Arg::new(options::NUMBER)
.long(options::NUMBER)
.required(<span class="bool-val">false</span>)
.num_args(<span class="number">1</span>)
.value_parser(<span class="macro">value_parser!</span>(u16).range(<span class="number">0</span>..))
.help(<span class="string">&quot;Same as --lines&quot;</span>),
)
<span class="comment">// The commented arguments below are unimplemented:
/*
.arg(
@@ -814,22 +871,6 @@
.long(options::PLAIN)
.help(&quot;Suppress underlining and bold&quot;),
)
.arg(
Arg::new(options::LINES)
.short(&#39;n&#39;)
.long(options::LINES)
.value_name(&quot;number&quot;)
.takes_value(true)
.help(&quot;The number of lines per screen full&quot;),
)
.arg(
Arg::new(options::NUMBER)
.allow_hyphen_values(true)
.long(options::NUMBER)
.required(false)
.takes_value(true)
.help(&quot;Same as --lines&quot;),
)
.arg(
Arg::new(options::FROM_LINE)
.short(&#39;F&#39;)
@@ -890,7 +931,11 @@
next_file: <span class="prelude-ty">Option</span>&lt;<span class="kw-2">&amp;</span>str&gt;,
options: <span class="kw-2">&amp;</span>Options,
) -&gt; UResult&lt;()&gt; {
<span class="kw">let </span>(cols, rows) = terminal::size().unwrap();
<span class="kw">let </span>(cols, <span class="kw-2">mut </span>rows) = terminal::size().unwrap();
<span class="kw">if let </span><span class="prelude-val">Some</span>(number) = options.lines {
rows = number;
}
<span class="kw">let </span>lines = break_buff(buff, usize::from(cols));
<span class="kw">let </span><span class="kw-2">mut </span>pager = Pager::new(rows, lines, next_file, options);
@@ -954,6 +999,7 @@
..
}) =&gt; {
pager.page_up();
paging_add_back_message(options, stdout)<span class="question-mark">?</span>;
}
Event::Key(KeyEvent {
code: KeyCode::Char(<span class="string">&#39;j&#39;</span>),
@@ -974,7 +1020,7 @@
pager.prev_line();
}
Event::Resize(col, row) =&gt; {
pager.page_resize(col, row);
pager.page_resize(col, row, options.lines);
}
Event::Key(KeyEvent {
code: KeyCode::Char(k),
@@ -1074,8 +1120,10 @@
}
<span class="comment">// TODO: Deal with column size changes.
</span><span class="kw">fn </span>page_resize(<span class="kw-2">&amp;mut </span><span class="self">self</span>, <span class="kw">_</span>: u16, row: u16) {
<span class="self">self</span>.content_rows = row.saturating_sub(<span class="number">1</span>);
</span><span class="kw">fn </span>page_resize(<span class="kw-2">&amp;mut </span><span class="self">self</span>, <span class="kw">_</span>: u16, row: u16, option_line: <span class="prelude-ty">Option</span>&lt;u16&gt;) {
<span class="kw">if </span>option_line.is_none() {
<span class="self">self</span>.content_rows = row.saturating_sub(<span class="number">1</span>);
};
}
<span class="kw">fn </span>draw(<span class="kw-2">&amp;mut </span><span class="self">self</span>, stdout: <span class="kw-2">&amp;mut </span>std::io::Stdout, wrong_key: <span class="prelude-ty">Option</span>&lt;char&gt;) {
@@ -1163,6 +1211,14 @@
}
}
<span class="kw">fn </span>paging_add_back_message(options: <span class="kw-2">&amp;</span>Options, stdout: <span class="kw-2">&amp;mut </span>std::io::Stdout) -&gt; UResult&lt;()&gt; {
<span class="kw">if </span>options.lines.is_some() {
<span class="macro">execute!</span>(stdout, MoveUp(<span class="number">1</span>))<span class="question-mark">?</span>;
stdout.write_all(<span class="string">&quot;\n\r...back 1 page\n&quot;</span>.as_bytes())<span class="question-mark">?</span>;
}
<span class="prelude-val">Ok</span>(())
}
<span class="comment">// Break the lines on the cols of the terminal
</span><span class="kw">fn </span>break_buff(buff: <span class="kw-2">&amp;</span>str, cols: usize) -&gt; Vec&lt;String&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>lines = Vec::with_capacity(buff.lines().count());
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
File diff suppressed because one or more lines are too long
+1 -1
View File
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

Some files were not shown because too many files have changed in this diff Show More