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:
+329
-3
@@ -1064,6 +1064,169 @@
|
||||
<a href="#1064" id="1064">1064</a>
|
||||
<a href="#1065" id="1065">1065</a>
|
||||
<a href="#1066" id="1066">1066</a>
|
||||
<a href="#1067" id="1067">1067</a>
|
||||
<a href="#1068" id="1068">1068</a>
|
||||
<a href="#1069" id="1069">1069</a>
|
||||
<a href="#1070" id="1070">1070</a>
|
||||
<a href="#1071" id="1071">1071</a>
|
||||
<a href="#1072" id="1072">1072</a>
|
||||
<a href="#1073" id="1073">1073</a>
|
||||
<a href="#1074" id="1074">1074</a>
|
||||
<a href="#1075" id="1075">1075</a>
|
||||
<a href="#1076" id="1076">1076</a>
|
||||
<a href="#1077" id="1077">1077</a>
|
||||
<a href="#1078" id="1078">1078</a>
|
||||
<a href="#1079" id="1079">1079</a>
|
||||
<a href="#1080" id="1080">1080</a>
|
||||
<a href="#1081" id="1081">1081</a>
|
||||
<a href="#1082" id="1082">1082</a>
|
||||
<a href="#1083" id="1083">1083</a>
|
||||
<a href="#1084" id="1084">1084</a>
|
||||
<a href="#1085" id="1085">1085</a>
|
||||
<a href="#1086" id="1086">1086</a>
|
||||
<a href="#1087" id="1087">1087</a>
|
||||
<a href="#1088" id="1088">1088</a>
|
||||
<a href="#1089" id="1089">1089</a>
|
||||
<a href="#1090" id="1090">1090</a>
|
||||
<a href="#1091" id="1091">1091</a>
|
||||
<a href="#1092" id="1092">1092</a>
|
||||
<a href="#1093" id="1093">1093</a>
|
||||
<a href="#1094" id="1094">1094</a>
|
||||
<a href="#1095" id="1095">1095</a>
|
||||
<a href="#1096" id="1096">1096</a>
|
||||
<a href="#1097" id="1097">1097</a>
|
||||
<a href="#1098" id="1098">1098</a>
|
||||
<a href="#1099" id="1099">1099</a>
|
||||
<a href="#1100" id="1100">1100</a>
|
||||
<a href="#1101" id="1101">1101</a>
|
||||
<a href="#1102" id="1102">1102</a>
|
||||
<a href="#1103" id="1103">1103</a>
|
||||
<a href="#1104" id="1104">1104</a>
|
||||
<a href="#1105" id="1105">1105</a>
|
||||
<a href="#1106" id="1106">1106</a>
|
||||
<a href="#1107" id="1107">1107</a>
|
||||
<a href="#1108" id="1108">1108</a>
|
||||
<a href="#1109" id="1109">1109</a>
|
||||
<a href="#1110" id="1110">1110</a>
|
||||
<a href="#1111" id="1111">1111</a>
|
||||
<a href="#1112" id="1112">1112</a>
|
||||
<a href="#1113" id="1113">1113</a>
|
||||
<a href="#1114" id="1114">1114</a>
|
||||
<a href="#1115" id="1115">1115</a>
|
||||
<a href="#1116" id="1116">1116</a>
|
||||
<a href="#1117" id="1117">1117</a>
|
||||
<a href="#1118" id="1118">1118</a>
|
||||
<a href="#1119" id="1119">1119</a>
|
||||
<a href="#1120" id="1120">1120</a>
|
||||
<a href="#1121" id="1121">1121</a>
|
||||
<a href="#1122" id="1122">1122</a>
|
||||
<a href="#1123" id="1123">1123</a>
|
||||
<a href="#1124" id="1124">1124</a>
|
||||
<a href="#1125" id="1125">1125</a>
|
||||
<a href="#1126" id="1126">1126</a>
|
||||
<a href="#1127" id="1127">1127</a>
|
||||
<a href="#1128" id="1128">1128</a>
|
||||
<a href="#1129" id="1129">1129</a>
|
||||
<a href="#1130" id="1130">1130</a>
|
||||
<a href="#1131" id="1131">1131</a>
|
||||
<a href="#1132" id="1132">1132</a>
|
||||
<a href="#1133" id="1133">1133</a>
|
||||
<a href="#1134" id="1134">1134</a>
|
||||
<a href="#1135" id="1135">1135</a>
|
||||
<a href="#1136" id="1136">1136</a>
|
||||
<a href="#1137" id="1137">1137</a>
|
||||
<a href="#1138" id="1138">1138</a>
|
||||
<a href="#1139" id="1139">1139</a>
|
||||
<a href="#1140" id="1140">1140</a>
|
||||
<a href="#1141" id="1141">1141</a>
|
||||
<a href="#1142" id="1142">1142</a>
|
||||
<a href="#1143" id="1143">1143</a>
|
||||
<a href="#1144" id="1144">1144</a>
|
||||
<a href="#1145" id="1145">1145</a>
|
||||
<a href="#1146" id="1146">1146</a>
|
||||
<a href="#1147" id="1147">1147</a>
|
||||
<a href="#1148" id="1148">1148</a>
|
||||
<a href="#1149" id="1149">1149</a>
|
||||
<a href="#1150" id="1150">1150</a>
|
||||
<a href="#1151" id="1151">1151</a>
|
||||
<a href="#1152" id="1152">1152</a>
|
||||
<a href="#1153" id="1153">1153</a>
|
||||
<a href="#1154" id="1154">1154</a>
|
||||
<a href="#1155" id="1155">1155</a>
|
||||
<a href="#1156" id="1156">1156</a>
|
||||
<a href="#1157" id="1157">1157</a>
|
||||
<a href="#1158" id="1158">1158</a>
|
||||
<a href="#1159" id="1159">1159</a>
|
||||
<a href="#1160" id="1160">1160</a>
|
||||
<a href="#1161" id="1161">1161</a>
|
||||
<a href="#1162" id="1162">1162</a>
|
||||
<a href="#1163" id="1163">1163</a>
|
||||
<a href="#1164" id="1164">1164</a>
|
||||
<a href="#1165" id="1165">1165</a>
|
||||
<a href="#1166" id="1166">1166</a>
|
||||
<a href="#1167" id="1167">1167</a>
|
||||
<a href="#1168" id="1168">1168</a>
|
||||
<a href="#1169" id="1169">1169</a>
|
||||
<a href="#1170" id="1170">1170</a>
|
||||
<a href="#1171" id="1171">1171</a>
|
||||
<a href="#1172" id="1172">1172</a>
|
||||
<a href="#1173" id="1173">1173</a>
|
||||
<a href="#1174" id="1174">1174</a>
|
||||
<a href="#1175" id="1175">1175</a>
|
||||
<a href="#1176" id="1176">1176</a>
|
||||
<a href="#1177" id="1177">1177</a>
|
||||
<a href="#1178" id="1178">1178</a>
|
||||
<a href="#1179" id="1179">1179</a>
|
||||
<a href="#1180" id="1180">1180</a>
|
||||
<a href="#1181" id="1181">1181</a>
|
||||
<a href="#1182" id="1182">1182</a>
|
||||
<a href="#1183" id="1183">1183</a>
|
||||
<a href="#1184" id="1184">1184</a>
|
||||
<a href="#1185" id="1185">1185</a>
|
||||
<a href="#1186" id="1186">1186</a>
|
||||
<a href="#1187" id="1187">1187</a>
|
||||
<a href="#1188" id="1188">1188</a>
|
||||
<a href="#1189" id="1189">1189</a>
|
||||
<a href="#1190" id="1190">1190</a>
|
||||
<a href="#1191" id="1191">1191</a>
|
||||
<a href="#1192" id="1192">1192</a>
|
||||
<a href="#1193" id="1193">1193</a>
|
||||
<a href="#1194" id="1194">1194</a>
|
||||
<a href="#1195" id="1195">1195</a>
|
||||
<a href="#1196" id="1196">1196</a>
|
||||
<a href="#1197" id="1197">1197</a>
|
||||
<a href="#1198" id="1198">1198</a>
|
||||
<a href="#1199" id="1199">1199</a>
|
||||
<a href="#1200" id="1200">1200</a>
|
||||
<a href="#1201" id="1201">1201</a>
|
||||
<a href="#1202" id="1202">1202</a>
|
||||
<a href="#1203" id="1203">1203</a>
|
||||
<a href="#1204" id="1204">1204</a>
|
||||
<a href="#1205" id="1205">1205</a>
|
||||
<a href="#1206" id="1206">1206</a>
|
||||
<a href="#1207" id="1207">1207</a>
|
||||
<a href="#1208" id="1208">1208</a>
|
||||
<a href="#1209" id="1209">1209</a>
|
||||
<a href="#1210" id="1210">1210</a>
|
||||
<a href="#1211" id="1211">1211</a>
|
||||
<a href="#1212" id="1212">1212</a>
|
||||
<a href="#1213" id="1213">1213</a>
|
||||
<a href="#1214" id="1214">1214</a>
|
||||
<a href="#1215" id="1215">1215</a>
|
||||
<a href="#1216" id="1216">1216</a>
|
||||
<a href="#1217" id="1217">1217</a>
|
||||
<a href="#1218" id="1218">1218</a>
|
||||
<a href="#1219" id="1219">1219</a>
|
||||
<a href="#1220" id="1220">1220</a>
|
||||
<a href="#1221" id="1221">1221</a>
|
||||
<a href="#1222" id="1222">1222</a>
|
||||
<a href="#1223" id="1223">1223</a>
|
||||
<a href="#1224" id="1224">1224</a>
|
||||
<a href="#1225" id="1225">1225</a>
|
||||
<a href="#1226" id="1226">1226</a>
|
||||
<a href="#1227" id="1227">1227</a>
|
||||
<a href="#1228" id="1228">1228</a>
|
||||
<a href="#1229" id="1229">1229</a>
|
||||
</pre><pre class="rust"><code><span class="comment">// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// (c) Tyler Steele <tyler.steele@protonmail.com>
|
||||
@@ -1071,7 +1234,7 @@
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, behaviour, bmax, bremain, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rremain, rsofar, rstat, sigusr, wlen, wstat seekable oconv canonicalized
|
||||
// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, behaviour, bmax, bremain, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, iseek, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, oseek, outfile, parseargs, rlen, rmax, rremain, rsofar, rstat, sigusr, wlen, wstat seekable oconv canonicalized fadvise Fadvise FADV DONTNEED ESPIPE
|
||||
|
||||
</span><span class="kw">mod </span>datastructures;
|
||||
<span class="kw">use </span>datastructures::<span class="kw-2">*</span>;
|
||||
@@ -1108,9 +1271,16 @@
|
||||
|
||||
<span class="kw">use </span>clap::{crate_version, Arg, Command};
|
||||
<span class="kw">use </span>gcd::Gcd;
|
||||
<span class="attr">#[cfg(target_os = <span class="string">"linux"</span>)]
|
||||
</span><span class="kw">use </span>nix::{
|
||||
errno::Errno,
|
||||
fcntl::{posix_fadvise, PosixFadviseAdvice},
|
||||
};
|
||||
<span class="kw">use </span>uucore::display::Quotable;
|
||||
<span class="kw">use </span>uucore::error::{FromIo, UResult};
|
||||
<span class="kw">use </span>uucore::{format_usage, help_about, help_section, help_usage, show_error};
|
||||
<span class="attr">#[cfg(target_os = <span class="string">"linux"</span>)]
|
||||
</span><span class="kw">use </span>uucore::{show, show_if_err};
|
||||
|
||||
<span class="kw">const </span>ABOUT: <span class="kw-2">&</span>str = <span class="macro">help_about!</span>(<span class="string">"dd.md"</span>);
|
||||
<span class="kw">const </span>AFTER_HELP: <span class="kw-2">&</span>str = <span class="macro">help_section!</span>(<span class="string">"after help"</span>, <span class="string">"dd.md"</span>);
|
||||
@@ -1197,6 +1367,16 @@
|
||||
<span class="self">Self</span>::StdinFile(f)
|
||||
}
|
||||
|
||||
<span class="doccomment">/// The length of the data source in number of bytes.
|
||||
///
|
||||
/// If it cannot be determined, then this function returns 0.
|
||||
</span><span class="kw">fn </span>len(<span class="kw-2">&</span><span class="self">self</span>) -> std::io::Result<i64> {
|
||||
<span class="kw">match </span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::File(f) => <span class="prelude-val">Ok</span>(f.metadata()<span class="question-mark">?</span>.len().try_into().unwrap_or(i64::MAX)),
|
||||
<span class="kw">_ </span>=> <span class="prelude-val">Ok</span>(<span class="number">0</span>),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>skip(<span class="kw-2">&mut </span><span class="self">self</span>, n: u64) -> io::Result<u64> {
|
||||
<span class="kw">match </span><span class="self">self </span>{
|
||||
<span class="attr">#[cfg(not(unix))]
|
||||
@@ -1222,6 +1402,23 @@
|
||||
</span><span class="self">Self</span>::Fifo(f) => io::copy(<span class="kw-2">&mut </span>f.take(n), <span class="kw-2">&mut </span>io::sink()),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Discard the system file cache for the given portion of the data source.
|
||||
///
|
||||
/// `offset` and `len` specify a contiguous portion of the data
|
||||
/// source. This function informs the kernel that the specified
|
||||
/// portion of the source is no longer needed. If not possible,
|
||||
/// then this function returns an error.
|
||||
</span><span class="attr">#[cfg(target_os = <span class="string">"linux"</span>)]
|
||||
</span><span class="kw">fn </span>discard_cache(<span class="kw-2">&</span><span class="self">self</span>, offset: libc::off_t, len: libc::off_t) -> nix::Result<()> {
|
||||
<span class="kw">match </span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::File(f) => {
|
||||
<span class="kw">let </span>advice = PosixFadviseAdvice::POSIX_FADV_DONTNEED;
|
||||
posix_fadvise(f.as_raw_fd(), offset, len, advice)
|
||||
}
|
||||
<span class="kw">_ </span>=> <span class="prelude-val">Err</span>(Errno::ESPIPE), <span class="comment">// "Illegal seek"
|
||||
</span>}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Read <span class="kw">for </span>Source {
|
||||
@@ -1362,6 +1559,29 @@
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><<span class="lifetime">'a</span>> Input<<span class="lifetime">'a</span>> {
|
||||
<span class="doccomment">/// Discard the system file cache for the given portion of the input.
|
||||
///
|
||||
/// `offset` and `len` specify a contiguous portion of the input.
|
||||
/// This function informs the kernel that the specified portion of
|
||||
/// the input file is no longer needed. If not possible, then this
|
||||
/// function prints an error message to stderr and sets the exit
|
||||
/// status code to 1.
|
||||
</span><span class="attr">#[allow(unused_variables)]
|
||||
</span><span class="kw">fn </span>discard_cache(<span class="kw-2">&</span><span class="self">self</span>, offset: libc::off_t, len: libc::off_t) {
|
||||
<span class="attr">#[cfg(target_os = <span class="string">"linux"</span>)]
|
||||
</span>{
|
||||
<span class="macro">show_if_err!</span>(<span class="self">self
|
||||
</span>.src
|
||||
.discard_cache(offset, len)
|
||||
.map_err_context(|| <span class="string">"failed to discard cache for: 'standard input'"</span>.to_string()));
|
||||
}
|
||||
<span class="attr">#[cfg(not(target_os = <span class="string">"linux"</span>))]
|
||||
</span>{
|
||||
<span class="comment">// TODO Is there a way to discard filesystem cache on
|
||||
// these other operating systems?
|
||||
</span>}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Fills a given buffer.
|
||||
/// Reads in increments of 'self.ibs'.
|
||||
/// The start of each ibs-sized read follows the previous one.
|
||||
@@ -1383,13 +1603,13 @@
|
||||
<span class="kw">_ </span>=> <span class="kw">break</span>,
|
||||
}
|
||||
}
|
||||
|
||||
buf.truncate(bytes_total);
|
||||
<span class="prelude-val">Ok</span>(ReadStat {
|
||||
reads_complete,
|
||||
reads_partial,
|
||||
<span class="comment">// Records are not truncated when filling.
|
||||
</span>records_truncated: <span class="number">0</span>,
|
||||
bytes_total: bytes_total.try_into().unwrap(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1400,6 +1620,7 @@
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>reads_complete = <span class="number">0</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>reads_partial = <span class="number">0</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>base_idx = <span class="number">0</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>bytes_total = <span class="number">0</span>;
|
||||
|
||||
<span class="kw">while </span>base_idx < buf.len() {
|
||||
<span class="kw">let </span>next_blk = cmp::min(base_idx + <span class="self">self</span>.settings.ibs, buf.len());
|
||||
@@ -1408,11 +1629,13 @@
|
||||
<span class="kw">match </span><span class="self">self</span>.read(<span class="kw-2">&mut </span>buf[base_idx..next_blk])<span class="question-mark">? </span>{
|
||||
<span class="number">0 </span>=> <span class="kw">break</span>,
|
||||
rlen <span class="kw">if </span>rlen < target_len => {
|
||||
bytes_total += rlen;
|
||||
reads_partial += <span class="number">1</span>;
|
||||
<span class="kw">let </span>padding = <span class="macro">vec!</span>[pad; target_len - rlen];
|
||||
buf.splice(base_idx + rlen..next_blk, padding.into_iter());
|
||||
}
|
||||
<span class="kw">_ </span>=> {
|
||||
rlen => {
|
||||
bytes_total += rlen;
|
||||
reads_complete += <span class="number">1</span>;
|
||||
}
|
||||
}
|
||||
@@ -1425,6 +1648,7 @@
|
||||
reads_complete,
|
||||
reads_partial,
|
||||
records_truncated: <span class="number">0</span>,
|
||||
bytes_total: bytes_total.try_into().unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1513,6 +1737,33 @@
|
||||
<span class="kw">_ </span>=> <span class="prelude-val">Ok</span>(()),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Discard the system file cache for the given portion of the destination.
|
||||
///
|
||||
/// `offset` and `len` specify a contiguous portion of the
|
||||
/// destination. This function informs the kernel that the
|
||||
/// specified portion of the destination is no longer needed. If
|
||||
/// not possible, then this function returns an error.
|
||||
</span><span class="attr">#[cfg(target_os = <span class="string">"linux"</span>)]
|
||||
</span><span class="kw">fn </span>discard_cache(<span class="kw-2">&</span><span class="self">self</span>, offset: libc::off_t, len: libc::off_t) -> nix::Result<()> {
|
||||
<span class="kw">match </span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::File(f, <span class="kw">_</span>) => {
|
||||
<span class="kw">let </span>advice = PosixFadviseAdvice::POSIX_FADV_DONTNEED;
|
||||
posix_fadvise(f.as_raw_fd(), offset, len, advice)
|
||||
}
|
||||
<span class="kw">_ </span>=> <span class="prelude-val">Err</span>(Errno::ESPIPE), <span class="comment">// "Illegal seek"
|
||||
</span>}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// The length of the data destination in number of bytes.
|
||||
///
|
||||
/// If it cannot be determined, then this function returns 0.
|
||||
</span><span class="kw">fn </span>len(<span class="kw-2">&</span><span class="self">self</span>) -> std::io::Result<i64> {
|
||||
<span class="kw">match </span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::File(f, <span class="kw">_</span>) => <span class="prelude-val">Ok</span>(f.metadata()<span class="question-mark">?</span>.len().try_into().unwrap_or(i64::MAX)),
|
||||
<span class="kw">_ </span>=> <span class="prelude-val">Ok</span>(<span class="number">0</span>),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Decide whether the given buffer is all zeros.
|
||||
@@ -1646,6 +1897,29 @@
|
||||
<span class="prelude-val">Ok</span>(<span class="self">Self </span>{ dst, settings })
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Discard the system file cache for the given portion of the output.
|
||||
///
|
||||
/// `offset` and `len` specify a contiguous portion of the output.
|
||||
/// This function informs the kernel that the specified portion of
|
||||
/// the output file is no longer needed. If not possible, then
|
||||
/// this function prints an error message to stderr and sets the
|
||||
/// exit status code to 1.
|
||||
</span><span class="attr">#[allow(unused_variables)]
|
||||
</span><span class="kw">fn </span>discard_cache(<span class="kw-2">&</span><span class="self">self</span>, offset: libc::off_t, len: libc::off_t) {
|
||||
<span class="attr">#[cfg(target_os = <span class="string">"linux"</span>)]
|
||||
</span>{
|
||||
<span class="macro">show_if_err!</span>(<span class="self">self
|
||||
</span>.dst
|
||||
.discard_cache(offset, len)
|
||||
.map_err_context(|| <span class="string">"failed to discard cache for: 'standard output'"</span>.to_string()));
|
||||
}
|
||||
<span class="attr">#[cfg(target_os = <span class="string">"linux"</span>)]
|
||||
</span>{
|
||||
<span class="comment">// TODO Is there a way to discard filesystem cache on
|
||||
// these other operating systems?
|
||||
</span>}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Write the given bytes one block at a time.
|
||||
///
|
||||
/// This may write partial blocks (for example, if the underlying
|
||||
@@ -1740,6 +2014,27 @@
|
||||
<span class="comment">// Optimization: if no blocks are to be written, then don't
|
||||
// bother allocating any buffers.
|
||||
</span><span class="kw">if let </span><span class="prelude-val">Some</span>(Num::Blocks(<span class="number">0</span>) | Num::Bytes(<span class="number">0</span>)) = i.settings.count {
|
||||
<span class="comment">// Even though we are not reading anything from the input
|
||||
// file, we still need to honor the `nocache` flag, which
|
||||
// requests that we inform the system that we no longer
|
||||
// need the contents of the input file in a system cache.
|
||||
//
|
||||
// TODO Better error handling for overflowing `len`.
|
||||
</span><span class="kw">if </span>i.settings.iflags.nocache {
|
||||
<span class="kw">let </span>offset = <span class="number">0</span>;
|
||||
<span class="attr">#[allow(clippy::useless_conversion)]
|
||||
</span><span class="kw">let </span>len = i.src.len()<span class="question-mark">?</span>.try_into().unwrap();
|
||||
i.discard_cache(offset, len);
|
||||
}
|
||||
<span class="comment">// Similarly, discard the system cache for the output file.
|
||||
//
|
||||
// TODO Better error handling for overflowing `len`.
|
||||
</span><span class="kw">if </span>i.settings.oflags.nocache {
|
||||
<span class="kw">let </span>offset = <span class="number">0</span>;
|
||||
<span class="attr">#[allow(clippy::useless_conversion)]
|
||||
</span><span class="kw">let </span>len = o.dst.len()<span class="question-mark">?</span>.try_into().unwrap();
|
||||
o.discard_cache(offset, len);
|
||||
}
|
||||
<span class="kw">return </span>finalize(<span class="kw-2">&mut </span>o, rstat, wstat, start, <span class="kw-2">&</span>prog_tx, output_thread);
|
||||
};
|
||||
|
||||
@@ -1747,6 +2042,13 @@
|
||||
// This is the max size needed.
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = <span class="macro">vec!</span>[BUF_INIT_BYTE; bsize];
|
||||
|
||||
<span class="comment">// Index in the input file where we are reading bytes and in
|
||||
// the output file where we are writing bytes.
|
||||
//
|
||||
// These are updated on each iteration of the main loop.
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>read_offset = <span class="number">0</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>write_offset = <span class="number">0</span>;
|
||||
|
||||
<span class="comment">// The main read/write loop.
|
||||
//
|
||||
// Each iteration reads blocks from the input and writes
|
||||
@@ -1766,6 +2068,30 @@
|
||||
}
|
||||
<span class="kw">let </span>wstat_update = o.write_blocks(<span class="kw-2">&</span>buf)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// Discard the system file cache for the read portion of
|
||||
// the input file.
|
||||
//
|
||||
// TODO Better error handling for overflowing `offset` and `len`.
|
||||
</span><span class="kw">let </span>read_len = rstat_update.bytes_total;
|
||||
<span class="kw">if </span>i.settings.iflags.nocache {
|
||||
<span class="kw">let </span>offset = read_offset.try_into().unwrap();
|
||||
<span class="kw">let </span>len = read_len.try_into().unwrap();
|
||||
i.discard_cache(offset, len);
|
||||
}
|
||||
read_offset += read_len;
|
||||
|
||||
<span class="comment">// Discard the system file cache for the written portion
|
||||
// of the output file.
|
||||
//
|
||||
// TODO Better error handling for overflowing `offset` and `len`.
|
||||
</span><span class="kw">let </span>write_len = wstat_update.bytes_total;
|
||||
<span class="kw">if </span>o.settings.oflags.nocache {
|
||||
<span class="kw">let </span>offset = write_offset.try_into().unwrap();
|
||||
<span class="kw">let </span>len = write_len.try_into().unwrap();
|
||||
o.discard_cache(offset, len);
|
||||
}
|
||||
write_offset += write_len;
|
||||
|
||||
<span class="comment">// Update the read/write stats and inform the progress thread once per second.
|
||||
//
|
||||
// If the receiver is disconnected, `send()` returns an
|
||||
|
||||
@@ -951,7 +951,7 @@
|
||||
<span class="string">"directory" </span>=> <span class="macro">linux_only!</span>(f, i.directory = <span class="bool-val">true</span>),
|
||||
<span class="string">"dsync" </span>=> <span class="macro">linux_only!</span>(f, i.dsync = <span class="bool-val">true</span>),
|
||||
<span class="string">"sync" </span>=> <span class="macro">linux_only!</span>(f, i.sync = <span class="bool-val">true</span>),
|
||||
<span class="string">"nocache" </span>=> <span class="kw">return </span><span class="prelude-val">Err</span>(ParseError::Unimplemented(f.to_string())),
|
||||
<span class="string">"nocache" </span>=> <span class="macro">linux_only!</span>(f, i.nocache = <span class="bool-val">true</span>),
|
||||
<span class="string">"nonblock" </span>=> <span class="macro">linux_only!</span>(f, i.nonblock = <span class="bool-val">true</span>),
|
||||
<span class="string">"noatime" </span>=> <span class="macro">linux_only!</span>(f, i.noatime = <span class="bool-val">true</span>),
|
||||
<span class="string">"noctty" </span>=> <span class="macro">linux_only!</span>(f, i.noctty = <span class="bool-val">true</span>),
|
||||
@@ -983,7 +983,7 @@
|
||||
<span class="string">"directory" </span>=> <span class="macro">linux_only!</span>(f, o.directory = <span class="bool-val">true</span>),
|
||||
<span class="string">"dsync" </span>=> <span class="macro">linux_only!</span>(f, o.dsync = <span class="bool-val">true</span>),
|
||||
<span class="string">"sync" </span>=> <span class="macro">linux_only!</span>(f, o.sync = <span class="bool-val">true</span>),
|
||||
<span class="string">"nocache" </span>=> <span class="kw">return </span><span class="prelude-val">Err</span>(ParseError::Unimplemented(f.to_string())),
|
||||
<span class="string">"nocache" </span>=> <span class="macro">linux_only!</span>(f, o.nocache = <span class="bool-val">true</span>),
|
||||
<span class="string">"nonblock" </span>=> <span class="macro">linux_only!</span>(f, o.nonblock = <span class="bool-val">true</span>),
|
||||
<span class="string">"noatime" </span>=> <span class="macro">linux_only!</span>(f, o.noatime = <span class="bool-val">true</span>),
|
||||
<span class="string">"noctty" </span>=> <span class="macro">linux_only!</span>(f, o.noctty = <span class="bool-val">true</span>),
|
||||
|
||||
@@ -656,6 +656,11 @@
|
||||
<a href="#656" id="656">656</a>
|
||||
<a href="#657" id="657">657</a>
|
||||
<a href="#658" id="658">658</a>
|
||||
<a href="#659" id="659">659</a>
|
||||
<a href="#660" id="660">660</a>
|
||||
<a href="#661" id="661">661</a>
|
||||
<a href="#662" id="662">662</a>
|
||||
<a href="#663" id="663">663</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
|
||||
@@ -737,9 +742,9 @@
|
||||
/// ```rust,ignore
|
||||
/// use std::io::Cursor;
|
||||
/// use std::time::Duration;
|
||||
/// use crate::progress::{ProgUpdate, ReadState, WriteStat};
|
||||
/// use crate::progress::{ProgUpdate, ReadStat, WriteStat};
|
||||
///
|
||||
/// let read_stat = ReadStat::new(1, 2, 3);
|
||||
/// let read_stat = ReadStat::new(1, 2, 3, 999);
|
||||
/// let write_stat = WriteStat::new(4, 5, 6);
|
||||
/// let duration = Duration::new(789, 0);
|
||||
/// let prog_update = ProgUpdate {
|
||||
@@ -779,7 +784,7 @@
|
||||
/// ```rust,ignore
|
||||
/// use std::io::Cursor;
|
||||
/// use std::time::Duration;
|
||||
/// use crate::progress::{ProgUpdate, ReadState, WriteStat};
|
||||
/// use crate::progress::ProgUpdate;
|
||||
///
|
||||
/// let prog_update = ProgUpdate {
|
||||
/// read_stat: Default::default(),
|
||||
@@ -849,7 +854,7 @@
|
||||
/// ```rust,ignore
|
||||
/// use std::io::Cursor;
|
||||
/// use std::time::Duration;
|
||||
/// use crate::progress::{ProgUpdate, ReadState, WriteStat};
|
||||
/// use crate::progress::ProgUpdate;
|
||||
///
|
||||
/// let prog_update = ProgUpdate {
|
||||
/// read_stat: Default::default(),
|
||||
@@ -934,16 +939,20 @@
|
||||
///
|
||||
/// A truncated record can only occur in `conv=block` mode.
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) records_truncated: u32,
|
||||
|
||||
<span class="doccomment">/// The total number of bytes read.
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) bytes_total: u64,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>ReadStat {
|
||||
<span class="doccomment">/// Create a new instance.
|
||||
</span><span class="attr">#[allow(dead_code)]
|
||||
</span><span class="kw">fn </span>new(complete: u64, partial: u64, truncated: u32) -> <span class="self">Self </span>{
|
||||
</span><span class="kw">fn </span>new(complete: u64, partial: u64, truncated: u32, bytes_total: u64) -> <span class="self">Self </span>{
|
||||
<span class="self">Self </span>{
|
||||
reads_complete: complete,
|
||||
reads_partial: partial,
|
||||
records_truncated: truncated,
|
||||
bytes_total,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -973,6 +982,7 @@
|
||||
reads_complete: <span class="self">self</span>.reads_complete + other.reads_complete,
|
||||
reads_partial: <span class="self">self</span>.reads_partial + other.reads_partial,
|
||||
records_truncated: <span class="self">self</span>.records_truncated + other.records_truncated,
|
||||
bytes_total: <span class="self">self</span>.bytes_total + other.bytes_total,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1172,7 +1182,7 @@
|
||||
|
||||
<span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>test_read_stat_report() {
|
||||
<span class="kw">let </span>read_stat = ReadStat::new(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>);
|
||||
<span class="kw">let </span>read_stat = ReadStat::new(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>cursor = Cursor::new(<span class="macro">vec!</span>[]);
|
||||
read_stat.report(<span class="kw-2">&mut </span>cursor).unwrap();
|
||||
<span class="macro">assert_eq!</span>(cursor.get_ref(), <span class="string">b"1+2 records in\n"</span>);
|
||||
@@ -1188,7 +1198,7 @@
|
||||
|
||||
<span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>test_prog_update_write_io_lines() {
|
||||
<span class="kw">let </span>read_stat = ReadStat::new(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>);
|
||||
<span class="kw">let </span>read_stat = ReadStat::new(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>);
|
||||
<span class="kw">let </span>write_stat = WriteStat::new(<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>);
|
||||
<span class="kw">let </span>duration = Duration::new(<span class="number">789</span>, <span class="number">0</span>);
|
||||
<span class="kw">let </span>complete = <span class="bool-val">false</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
Reference in New Issue
Block a user