Skip to content

Commit b1c9a09

Browse files
committed
deploy: 2ed80ff
1 parent 1dd24ae commit b1c9a09

15 files changed

+170
-102
lines changed

dev/src/uu_cp/copydir.rs.html

+1-3
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@
392392
<span id="392">392</span>
393393
<span id="393">393</span>
394394
<span id="394">394</span>
395-
<span id="395">395</span>
396395
</pre><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
397396
// *
398397
// * For the full copyright and license information, please view the LICENSE
@@ -608,9 +607,8 @@
608607
<span class="comment">// If the source is not a directory, then we need to copy the file.
609608
</span><span class="kw">if </span>!source_absolute.is_dir() {
610609
<span class="kw">if </span>preserve_hard_links {
611-
<span class="kw">let </span><span class="kw-2">mut </span>found_hard_link = <span class="bool-val">false</span>;
612610
<span class="kw">let </span>dest = local_to_target.as_path().to_path_buf();
613-
preserve_hardlinks(hard_links, <span class="kw-2">&amp;</span>source_absolute, <span class="kw-2">&amp;</span>dest, <span class="kw-2">&amp;mut </span>found_hard_link)<span class="question-mark">?</span>;
611+
<span class="kw">let </span>found_hard_link = preserve_hardlinks(hard_links, <span class="kw-2">&amp;</span>source_absolute, <span class="kw-2">&amp;</span>dest)<span class="question-mark">?</span>;
614612
<span class="kw">if </span>!found_hard_link {
615613
<span class="kw">match </span>copy_file(
616614
progress_bar,

dev/src/uu_cp/cp.rs.html

+58-48
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,11 @@
16831683
<span id="1683">1683</span>
16841684
<span id="1684">1684</span>
16851685
<span id="1685">1685</span>
1686+
<span id="1686">1686</span>
1687+
<span id="1687">1687</span>
1688+
<span id="1688">1688</span>
1689+
<span id="1689">1689</span>
1690+
<span id="1690">1690</span>
16861691
</pre><pre class="rust"><code><span class="attribute">#![allow(clippy::missing_safety_doc)]
16871692
#![allow(clippy::extra_unused_lifetimes)]
16881693

@@ -2576,60 +2581,64 @@
25762581
<span class="prelude-val">Ok</span>((paths, target))
25772582
}
25782583

2579-
<span class="kw">fn </span>preserve_hardlinks(
2584+
<span class="doccomment">/// Get the inode information for a file.
2585+
</span><span class="kw">fn </span>get_inode(file_info: <span class="kw-2">&amp;</span>FileInformation) -&gt; u64 {
2586+
<span class="attribute">#[cfg(unix)]
2587+
</span><span class="kw">let </span>result = file_info.inode();
2588+
<span class="attribute">#[cfg(windows)]
2589+
</span><span class="kw">let </span>result = file_info.file_index();
2590+
result
2591+
}
2592+
2593+
<span class="attribute">#[cfg(target_os = <span class="string">&quot;redox&quot;</span>)]
2594+
</span><span class="kw">fn </span>preserve_hardlinks(
25802595
hard_links: <span class="kw-2">&amp;mut </span>Vec&lt;(String, u64)&gt;,
25812596
source: <span class="kw-2">&amp;</span>std::path::Path,
25822597
dest: <span class="kw-2">&amp;</span>std::path::Path,
25832598
found_hard_link: <span class="kw-2">&amp;mut </span>bool,
25842599
) -&gt; CopyResult&lt;()&gt; {
25852600
<span class="comment">// Redox does not currently support hard links
2586-
</span><span class="attribute">#[cfg(not(target_os = <span class="string">&quot;redox&quot;</span>))]
2587-
</span>{
2588-
<span class="kw">if </span>!source.is_dir() {
2589-
<span class="kw">let </span>info = <span class="kw">match </span>FileInformation::from_path(source, <span class="bool-val">false</span>) {
2590-
<span class="prelude-val">Ok</span>(info) =&gt; info,
2591-
<span class="prelude-val">Err</span>(e) =&gt; {
2592-
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="macro">format!</span>(<span class="string">&quot;cannot stat {}: {}&quot;</span>, source.quote(), e,).into());
2593-
}
2594-
};
2595-
2596-
<span class="attribute">#[cfg(unix)]
2597-
</span><span class="kw">let </span>inode = info.inode();
2598-
2599-
<span class="attribute">#[cfg(windows)]
2600-
</span><span class="kw">let </span>inode = info.file_index();
2601-
2602-
<span class="kw">let </span>nlinks = info.number_of_links();
2603-
2604-
<span class="kw">for </span>hard_link <span class="kw">in </span>hard_links.iter() {
2605-
<span class="kw">if </span>hard_link.<span class="number">1 </span>== inode {
2606-
<span class="comment">// Consider the following files:
2607-
//
2608-
// * `src/f` - a regular file
2609-
// * `src/link` - a hard link to `src/f`
2610-
// * `dest/src/f` - a different regular file
2611-
//
2612-
// In this scenario, if we do `cp -a src/ dest/`, it is
2613-
// possible that the order of traversal causes `src/link`
2614-
// to get copied first (to `dest/src/link`). In that case,
2615-
// in order to make sure `dest/src/link` is a hard link to
2616-
// `dest/src/f` and `dest/src/f` has the contents of
2617-
// `src/f`, we delete the existing file to allow the hard
2618-
// linking.
2619-
</span><span class="kw">if </span>file_or_link_exists(dest) &amp;&amp; file_or_link_exists(Path::new(<span class="kw-2">&amp;</span>hard_link.<span class="number">0</span>)) {
2620-
std::fs::remove_file(dest)<span class="question-mark">?</span>;
2621-
}
2601+
</span><span class="prelude-val">Ok</span>(())
2602+
}
26222603

2623-
std::fs::hard_link(hard_link.<span class="number">0</span>.clone(), dest).unwrap();
2624-
<span class="kw-2">*</span>found_hard_link = <span class="bool-val">true</span>;
2625-
}
2626-
}
2627-
<span class="kw">if </span>!(<span class="kw-2">*</span>found_hard_link) &amp;&amp; nlinks &gt; <span class="number">1 </span>{
2628-
hard_links.push((dest.to_str().unwrap().to_string(), inode));
2604+
<span class="doccomment">/// Hard link a pair of files if needed _and_ record if this pair is a new hard link.
2605+
</span><span class="attribute">#[cfg(not(target_os = <span class="string">&quot;redox&quot;</span>))]
2606+
</span><span class="kw">fn </span>preserve_hardlinks(
2607+
hard_links: <span class="kw-2">&amp;mut </span>Vec&lt;(String, u64)&gt;,
2608+
source: <span class="kw-2">&amp;</span>std::path::Path,
2609+
dest: <span class="kw-2">&amp;</span>std::path::Path,
2610+
) -&gt; CopyResult&lt;bool&gt; {
2611+
<span class="kw">let </span>info = FileInformation::from_path(source, <span class="bool-val">false</span>)
2612+
.context(<span class="macro">format!</span>(<span class="string">&quot;cannot stat {}&quot;</span>, source.quote()))<span class="question-mark">?</span>;
2613+
<span class="kw">let </span>inode = get_inode(<span class="kw-2">&amp;</span>info);
2614+
<span class="kw">let </span>nlinks = info.number_of_links();
2615+
<span class="kw">let </span><span class="kw-2">mut </span>found_hard_link = <span class="bool-val">false</span>;
2616+
<span class="kw">for </span>(link, link_inode) <span class="kw">in </span>hard_links.iter() {
2617+
<span class="kw">if </span><span class="kw-2">*</span>link_inode == inode {
2618+
<span class="comment">// Consider the following files:
2619+
//
2620+
// * `src/f` - a regular file
2621+
// * `src/link` - a hard link to `src/f`
2622+
// * `dest/src/f` - a different regular file
2623+
//
2624+
// In this scenario, if we do `cp -a src/ dest/`, it is
2625+
// possible that the order of traversal causes `src/link`
2626+
// to get copied first (to `dest/src/link`). In that case,
2627+
// in order to make sure `dest/src/link` is a hard link to
2628+
// `dest/src/f` and `dest/src/f` has the contents of
2629+
// `src/f`, we delete the existing file to allow the hard
2630+
// linking.
2631+
</span><span class="kw">if </span>file_or_link_exists(dest) &amp;&amp; file_or_link_exists(Path::new(link)) {
2632+
std::fs::remove_file(dest)<span class="question-mark">?</span>;
26292633
}
2634+
std::fs::hard_link(link, dest).unwrap();
2635+
found_hard_link = <span class="bool-val">true</span>;
26302636
}
26312637
}
2632-
<span class="prelude-val">Ok</span>(())
2638+
<span class="kw">if </span>!found_hard_link &amp;&amp; nlinks &gt; <span class="number">1 </span>{
2639+
hard_links.push((dest.to_str().unwrap().to_string(), inode));
2640+
}
2641+
<span class="prelude-val">Ok</span>(found_hard_link)
26332642
}
26342643

26352644
<span class="doccomment">/// Copy all `sources` to `target`. Returns an
@@ -2671,11 +2680,12 @@
26712680
<span class="comment">// FIXME: compare sources by the actual file they point to, not their path. (e.g. dir/file == dir/../dir/file in most cases)
26722681
</span><span class="macro">show_warning!</span>(<span class="string">&quot;source {} specified more than once&quot;</span>, source.quote());
26732682
} <span class="kw">else </span>{
2674-
<span class="kw">let </span><span class="kw-2">mut </span>found_hard_link = <span class="bool-val">false</span>;
2675-
<span class="kw">if </span>preserve_hard_links {
2683+
<span class="kw">let </span>found_hard_link = <span class="kw">if </span>preserve_hard_links &amp;&amp; !source.is_dir() {
26762684
<span class="kw">let </span>dest = construct_dest_path(source, target, <span class="kw-2">&amp;</span>target_type, options)<span class="question-mark">?</span>;
2677-
preserve_hardlinks(<span class="kw-2">&amp;mut </span>hard_links, source, <span class="kw-2">&amp;</span>dest, <span class="kw-2">&amp;mut </span>found_hard_link)<span class="question-mark">?</span>;
2678-
}
2685+
preserve_hardlinks(<span class="kw-2">&amp;mut </span>hard_links, source, <span class="kw-2">&amp;</span>dest)<span class="question-mark">?
2686+
</span>} <span class="kw">else </span>{
2687+
<span class="bool-val">false
2688+
</span>};
26792689
<span class="kw">if </span>!found_hard_link {
26802690
<span class="kw">if let </span><span class="prelude-val">Err</span>(error) = copy_source(
26812691
<span class="kw-2">&amp;</span>progress_bar,

dev/src/uu_factor/cli.rs.html

+14-6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
<span id="83">83</span>
8484
<span id="84">84</span>
8585
<span id="85">85</span>
86+
<span id="86">86</span>
87+
<span id="87">87</span>
88+
<span id="88">88</span>
89+
<span id="89">89</span>
8690
</pre><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
8791
// *
8892
// * (c) 2014 T. Jameson Little &lt;t.jameson.little@gmail.com&gt;
@@ -120,12 +124,16 @@
120124
w: <span class="kw-2">&amp;mut </span>io::BufWriter&lt;<span class="kw">impl </span>io::Write&gt;,
121125
factors_buffer: <span class="kw-2">&amp;mut </span>String,
122126
) -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
123-
num_str.parse::&lt;u64&gt;().map_err(|e| e.into()).and_then(|x| {
124-
factors_buffer.clear();
125-
<span class="macro">writeln!</span>(factors_buffer, <span class="string">&quot;{}:{}&quot;</span>, x, factor(x))<span class="question-mark">?</span>;
126-
w.write_all(factors_buffer.as_bytes())<span class="question-mark">?</span>;
127-
<span class="prelude-val">Ok</span>(())
128-
})
127+
num_str
128+
.trim()
129+
.parse::&lt;u64&gt;()
130+
.map_err(|e| e.into())
131+
.and_then(|x| {
132+
factors_buffer.clear();
133+
<span class="macro">writeln!</span>(factors_buffer, <span class="string">&quot;{}:{}&quot;</span>, x, factor(x))<span class="question-mark">?</span>;
134+
w.write_all(factors_buffer.as_bytes())<span class="question-mark">?</span>;
135+
<span class="prelude-val">Ok</span>(())
136+
})
129137
}
130138

131139
<span class="attribute">#[uucore::main]

0 commit comments

Comments
 (0)