This commit is contained in:
sylvestre
2023-05-22 02:41:25 +00:00
parent 9ba20bd79c
commit 157e96481a
46 changed files with 187 additions and 59 deletions
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
+26 -4
View File
@@ -152,6 +152,17 @@
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
</pre><pre class="rust"><code><span class="comment">// This file is part of the uutils coreutils package.
//
// (c) Jian Zeng &lt;anonymousknight96@gmail.com&gt;
@@ -164,7 +175,7 @@
</span><span class="kw">use </span>uucore::display::Quotable;
<span class="kw">pub use </span>uucore::entries;
<span class="kw">use </span>uucore::error::{FromIo, UResult, USimpleError};
<span class="kw">use </span>uucore::perms::{chown_base, options, IfFrom};
<span class="kw">use </span>uucore::perms::{chown_base, options, GidUidOwnerFilter, IfFrom};
<span class="kw">use </span>uucore::{format_usage, help_about, help_usage};
<span class="kw">use </span>clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
@@ -175,16 +186,22 @@
<span class="kw">const </span>ABOUT: <span class="kw-2">&amp;</span>str = <span class="macro">help_about!</span>(<span class="string">&quot;chgrp.md&quot;</span>);
<span class="kw">const </span>USAGE: <span class="kw-2">&amp;</span>str = <span class="macro">help_usage!</span>(<span class="string">&quot;chgrp.md&quot;</span>);
<span class="kw">fn </span>parse_gid_and_uid(matches: <span class="kw-2">&amp;</span>ArgMatches) -&gt; UResult&lt;(<span class="prelude-ty">Option</span>&lt;u32&gt;, <span class="prelude-ty">Option</span>&lt;u32&gt;, IfFrom)&gt; {
<span class="kw">fn </span>parse_gid_and_uid(matches: <span class="kw-2">&amp;</span>ArgMatches) -&gt; UResult&lt;GidUidOwnerFilter&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>raw_group: String = String::new();
<span class="kw">let </span>dest_gid = <span class="kw">if let </span><span class="prelude-val">Some</span>(file) = matches.get_one::&lt;String&gt;(options::REFERENCE) {
fs::metadata(file)
.map(|meta| <span class="prelude-val">Some</span>(meta.gid()))
.map(|meta| {
<span class="kw">let </span>gid = meta.gid();
raw_group = entries::gid2grp(gid).unwrap_or_else(|<span class="kw">_</span>| gid.to_string());
<span class="prelude-val">Some</span>(gid)
})
.map_err_context(|| <span class="macro">format!</span>(<span class="string">&quot;failed to get attributes of {}&quot;</span>, file.quote()))<span class="question-mark">?
</span>} <span class="kw">else </span>{
<span class="kw">let </span>group = matches
.get_one::&lt;String&gt;(options::ARG_GROUP)
.map(|s| s.as_str())
.unwrap_or_default();
raw_group = group.to_string();
<span class="kw">if </span>group.is_empty() {
<span class="prelude-val">None
</span>} <span class="kw">else </span>{
@@ -199,7 +216,12 @@
}
}
};
<span class="prelude-val">Ok</span>((dest_gid, <span class="prelude-val">None</span>, IfFrom::All))
<span class="prelude-val">Ok</span>(GidUidOwnerFilter {
dest_gid,
dest_uid: <span class="prelude-val">None</span>,
raw_owner: raw_group,
filter: IfFrom::All,
})
}
<span class="attr">#[uucore::main]
+40 -6
View File
@@ -286,6 +286,23 @@
<a href="#286" id="286">286</a>
<a href="#287" id="287">287</a>
<a href="#288" id="288">288</a>
<a href="#289" id="289">289</a>
<a href="#290" id="290">290</a>
<a href="#291" id="291">291</a>
<a href="#292" id="292">292</a>
<a href="#293" id="293">293</a>
<a href="#294" id="294">294</a>
<a href="#295" id="295">295</a>
<a href="#296" id="296">296</a>
<a href="#297" id="297">297</a>
<a href="#298" id="298">298</a>
<a href="#299" id="299">299</a>
<a href="#300" id="300">300</a>
<a href="#301" id="301">301</a>
<a href="#302" id="302">302</a>
<a href="#303" id="303">303</a>
<a href="#304" id="304">304</a>
<a href="#305" id="305">305</a>
</pre><pre class="rust"><code><span class="comment">// This file is part of the uutils coreutils package.
//
// (c) Jian Zeng &lt;anonymousknight96@gmail.com&gt;
@@ -297,7 +314,7 @@
</span><span class="kw">use </span>uucore::display::Quotable;
<span class="kw">pub use </span>uucore::entries::{<span class="self">self</span>, Group, Locate, Passwd};
<span class="kw">use </span>uucore::perms::{chown_base, options, IfFrom};
<span class="kw">use </span>uucore::perms::{chown_base, options, GidUidOwnerFilter, IfFrom};
<span class="kw">use </span>uucore::{format_usage, help_about, help_usage};
<span class="kw">use </span>uucore::error::{FromIo, UResult, USimpleError};
@@ -311,7 +328,7 @@
<span class="kw">const </span>USAGE: <span class="kw-2">&amp;</span>str = <span class="macro">help_usage!</span>(<span class="string">&quot;chown.md&quot;</span>);
<span class="kw">fn </span>parse_gid_uid_and_filter(matches: <span class="kw-2">&amp;</span>ArgMatches) -&gt; UResult&lt;(<span class="prelude-ty">Option</span>&lt;u32&gt;, <span class="prelude-ty">Option</span>&lt;u32&gt;, IfFrom)&gt; {
<span class="kw">fn </span>parse_gid_uid_and_filter(matches: <span class="kw-2">&amp;</span>ArgMatches) -&gt; UResult&lt;GidUidOwnerFilter&gt; {
<span class="kw">let </span>filter = <span class="kw">if let </span><span class="prelude-val">Some</span>(spec) = matches.get_one::&lt;String&gt;(options::FROM) {
<span class="kw">match </span>parse_spec(spec, <span class="string">&#39;:&#39;</span>)<span class="question-mark">? </span>{
(<span class="prelude-val">Some</span>(uid), <span class="prelude-val">None</span>) =&gt; IfFrom::User(uid),
@@ -325,17 +342,34 @@
<span class="kw">let </span>dest_uid: <span class="prelude-ty">Option</span>&lt;u32&gt;;
<span class="kw">let </span>dest_gid: <span class="prelude-ty">Option</span>&lt;u32&gt;;
<span class="kw">let </span>raw_owner: String;
<span class="kw">if let </span><span class="prelude-val">Some</span>(file) = matches.get_one::&lt;String&gt;(options::REFERENCE) {
<span class="kw">let </span>meta = fs::metadata(file)
.map_err_context(|| <span class="macro">format!</span>(<span class="string">&quot;failed to get attributes of {}&quot;</span>, file.quote()))<span class="question-mark">?</span>;
dest_gid = <span class="prelude-val">Some</span>(meta.gid());
dest_uid = <span class="prelude-val">Some</span>(meta.uid());
<span class="kw">let </span>gid = meta.gid();
<span class="kw">let </span>uid = meta.uid();
dest_gid = <span class="prelude-val">Some</span>(gid);
dest_uid = <span class="prelude-val">Some</span>(uid);
raw_owner = <span class="macro">format!</span>(
<span class="string">&quot;{}:{}&quot;</span>,
entries::uid2usr(uid).unwrap_or_else(|<span class="kw">_</span>| uid.to_string()),
entries::gid2grp(gid).unwrap_or_else(|<span class="kw">_</span>| gid.to_string())
);
} <span class="kw">else </span>{
<span class="kw">let </span>(u, g) = parse_spec(matches.get_one::&lt;String&gt;(options::ARG_OWNER).unwrap(), <span class="string">&#39;:&#39;</span>)<span class="question-mark">?</span>;
raw_owner = matches
.get_one::&lt;String&gt;(options::ARG_OWNER)
.unwrap()
.into();
<span class="kw">let </span>(u, g) = parse_spec(<span class="kw-2">&amp;</span>raw_owner, <span class="string">&#39;:&#39;</span>)<span class="question-mark">?</span>;
dest_uid = u;
dest_gid = g;
}
<span class="prelude-val">Ok</span>((dest_gid, dest_uid, filter))
<span class="prelude-val">Ok</span>(GidUidOwnerFilter {
dest_gid,
dest_uid,
raw_owner,
filter,
})
}
<span class="attr">#[uucore::main]
+49 -5
View File
@@ -529,6 +529,28 @@
<a href="#529" id="529">529</a>
<a href="#530" id="530">530</a>
<a href="#531" id="531">531</a>
<a href="#532" id="532">532</a>
<a href="#533" id="533">533</a>
<a href="#534" id="534">534</a>
<a href="#535" id="535">535</a>
<a href="#536" id="536">536</a>
<a href="#537" id="537">537</a>
<a href="#538" id="538">538</a>
<a href="#539" id="539">539</a>
<a href="#540" id="540">540</a>
<a href="#541" id="541">541</a>
<a href="#542" id="542">542</a>
<a href="#543" id="543">543</a>
<a href="#544" id="544">544</a>
<a href="#545" id="545">545</a>
<a href="#546" id="546">546</a>
<a href="#547" id="547">547</a>
<a href="#548" id="548">548</a>
<a href="#549" id="549">549</a>
<a href="#550" id="550">550</a>
<a href="#551" id="551">551</a>
<a href="#552" id="552">552</a>
<a href="#553" id="553">553</a>
</pre><pre class="rust"><code><span class="comment">// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
@@ -713,7 +735,8 @@
<span class="kw">pub struct </span>ChownExecutor {
<span class="kw">pub </span>dest_uid: <span class="prelude-ty">Option</span>&lt;u32&gt;,
<span class="kw">pub </span>dest_gid: <span class="prelude-ty">Option</span>&lt;u32&gt;,
<span class="kw">pub </span>traverse_symlinks: TraverseSymlinks,
<span class="kw">pub </span>raw_owner: String, <span class="comment">// The owner of the file as input by the user in the command line.
</span><span class="kw">pub </span>traverse_symlinks: TraverseSymlinks,
<span class="kw">pub </span>verbosity: Verbosity,
<span class="kw">pub </span>filter: IfFrom,
<span class="kw">pub </span>files: Vec&lt;String&gt;,
@@ -739,7 +762,16 @@
<span class="kw">let </span>path = root.as_ref();
<span class="kw">let </span>meta = <span class="kw">match </span><span class="self">self</span>.obtain_meta(path, <span class="self">self</span>.dereference) {
<span class="prelude-val">Some</span>(m) =&gt; m,
<span class="kw">_ </span>=&gt; <span class="kw">return </span><span class="number">1</span>,
<span class="kw">_ </span>=&gt; {
<span class="kw">if </span><span class="self">self</span>.verbosity.level == VerbosityLevel::Verbose {
<span class="macro">println!</span>(
<span class="string">&quot;failed to change ownership of {} to {}&quot;</span>,
path.quote(),
<span class="self">self</span>.raw_owner
);
}
<span class="kw">return </span><span class="number">1</span>;
}
};
<span class="comment">// Prohibit only if:
@@ -945,7 +977,13 @@
<span class="kw">pub const </span>ARG_FILES: <span class="kw-2">&amp;</span>str = <span class="string">&quot;FILE&quot;</span>;
}
<span class="kw">type </span>GidUidFilterParser = <span class="kw">fn</span>(<span class="kw-2">&amp;</span>ArgMatches) -&gt; UResult&lt;(<span class="prelude-ty">Option</span>&lt;u32&gt;, <span class="prelude-ty">Option</span>&lt;u32&gt;, IfFrom)&gt;;
<span class="kw">pub struct </span>GidUidOwnerFilter {
<span class="kw">pub </span>dest_gid: <span class="prelude-ty">Option</span>&lt;u32&gt;,
<span class="kw">pub </span>dest_uid: <span class="prelude-ty">Option</span>&lt;u32&gt;,
<span class="kw">pub </span>raw_owner: String,
<span class="kw">pub </span>filter: IfFrom,
}
<span class="kw">type </span>GidUidFilterOwnerParser = <span class="kw">fn</span>(<span class="kw-2">&amp;</span>ArgMatches) -&gt; UResult&lt;GidUidOwnerFilter&gt;;
<span class="doccomment">/// Base implementation for `chgrp` and `chown`.
///
@@ -959,7 +997,7 @@
<span class="kw-2">mut </span>command: Command,
args: <span class="kw">impl </span><span class="kw">crate</span>::Args,
add_arg_if_not_reference: <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span>str,
parse_gid_uid_and_filter: GidUidFilterParser,
parse_gid_uid_and_filter: GidUidFilterOwnerParser,
groups_only: bool,
) -&gt; UResult&lt;()&gt; {
<span class="kw">let </span>args: Vec&lt;<span class="kw">_</span>&gt; = args.collect();
@@ -1042,12 +1080,18 @@
} <span class="kw">else </span>{
VerbosityLevel::Normal
};
<span class="kw">let </span>(dest_gid, dest_uid, filter) = parse_gid_uid_and_filter(<span class="kw-2">&amp;</span>matches)<span class="question-mark">?</span>;
<span class="kw">let </span>GidUidOwnerFilter {
dest_gid,
dest_uid,
raw_owner,
filter,
} = parse_gid_uid_and_filter(<span class="kw-2">&amp;</span>matches)<span class="question-mark">?</span>;
<span class="kw">let </span>executor = ChownExecutor {
traverse_symlinks,
dest_gid,
dest_uid,
raw_owner,
verbosity: Verbosity {
groups_only,
level: verbosity_level,
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
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../uucore/perms/struct.GidUidOwnerFilter.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../uucore/perms/struct.GidUidOwnerFilter.html">../../../uucore/perms/struct.GidUidOwnerFilter.html</a>...</p>
<script>location.replace("../../../uucore/perms/struct.GidUidOwnerFilter.html" + location.search + location.hash);</script>
</body>
</html>
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