|
440 | 440 | <a href="#440" id="440">440</a>
|
441 | 441 | <a href="#441" id="441">441</a>
|
442 | 442 | <a href="#442" id="442">442</a>
|
| 443 | +<a href="#443" id="443">443</a> |
| 444 | +<a href="#444" id="444">444</a> |
| 445 | +<a href="#445" id="445">445</a> |
| 446 | +<a href="#446" id="446">446</a> |
| 447 | +<a href="#447" id="447">447</a> |
| 448 | +<a href="#448" id="448">448</a> |
| 449 | +<a href="#449" id="449">449</a> |
443 | 450 | </pre><pre class="rust"><code><span class="comment">// This file is part of the uutils coreutils package.
|
444 | 451 | //
|
445 | 452 | // (c) Anthony Deschamps <anthony.j.deschamps@gmail.com>
|
|
464 | 471 | <span class="attr">#[cfg(not(any(target_os = <span class="string">"macos"</span>, target_os = <span class="string">"redox"</span>)))]
|
465 | 472 | </span><span class="kw">use </span>uucore::error::FromIo;
|
466 | 473 | <span class="kw">use </span>uucore::error::{UResult, USimpleError};
|
467 |
| -<span class="kw">use </span>uucore::{format_usage, help_about, help_usage, show_error}; |
| 474 | +<span class="kw">use </span>uucore::{format_usage, help_about, help_usage, show}; |
468 | 475 | <span class="attr">#[cfg(windows)]
|
469 | 476 | </span><span class="kw">use </span>windows_sys::Win32::{Foundation::SYSTEMTIME, System::SystemInformation::SetSystemTime};
|
470 | 477 |
|
|
645 | 652 |
|
646 | 653 | <span class="kw">return </span>set_system_datetime(date);
|
647 | 654 | } <span class="kw">else </span>{
|
648 |
| - <span class="comment">// Declare a file here because it needs to outlive the `dates` iterator. |
649 |
| - </span><span class="kw">let </span>file: File; |
650 |
| - |
651 | 655 | <span class="comment">// Get the current time, either in the local time zone or UTC.
|
652 | 656 | </span><span class="kw">let </span>now: DateTime<FixedOffset> = <span class="kw">if </span>settings.utc {
|
653 | 657 | <span class="kw">let </span>now = Utc::now();
|
|
664 | 668 | <span class="kw">let </span>iter = std::iter::once(date);
|
665 | 669 | Box::new(iter)
|
666 | 670 | }
|
667 |
| - DateSource::File(<span class="kw-2">ref </span>path) => { |
668 |
| - file = File::open(path).unwrap(); |
669 |
| - <span class="kw">let </span>lines = BufReader::new(file).lines(); |
670 |
| - <span class="kw">let </span>iter = lines.filter_map(Result::ok).map(parse_date); |
671 |
| - Box::new(iter) |
672 |
| - } |
| 671 | + DateSource::File(<span class="kw-2">ref </span>path) => <span class="kw">match </span>File::open(path) { |
| 672 | + <span class="prelude-val">Ok</span>(file) => { |
| 673 | + <span class="kw">let </span>lines = BufReader::new(file).lines(); |
| 674 | + <span class="kw">let </span>iter = lines.filter_map(Result::ok).map(parse_date); |
| 675 | + Box::new(iter) |
| 676 | + } |
| 677 | + <span class="prelude-val">Err</span>(_err) => { |
| 678 | + <span class="kw">return </span><span class="prelude-val">Err</span>(USimpleError::new( |
| 679 | + <span class="number">2</span>, |
| 680 | + <span class="macro">format!</span>(<span class="string">"{}: No such file or directory"</span>, path.display()), |
| 681 | + )); |
| 682 | + } |
| 683 | + }, |
673 | 684 | DateSource::Now => {
|
674 | 685 | <span class="kw">let </span>iter = std::iter::once(<span class="prelude-val">Ok</span>(now));
|
675 | 686 | Box::new(iter)
|
|
699 | 710 | .replace(<span class="string">"%f"</span>, <span class="string">"%N"</span>);
|
700 | 711 | <span class="macro">println!</span>(<span class="string">"{formatted}"</span>);
|
701 | 712 | }
|
702 |
| - <span class="prelude-val">Err</span>((input, _err)) => <span class="macro">show_error!</span>(<span class="string">"invalid date {}"</span>, input.quote()), |
| 713 | + <span class="prelude-val">Err</span>((input, _err)) => <span class="macro">show!</span>(USimpleError::new( |
| 714 | + <span class="number">1</span>, |
| 715 | + <span class="macro">format!</span>(<span class="string">"invalid date {}"</span>, input.quote()) |
| 716 | + )), |
703 | 717 | }
|
704 | 718 | }
|
705 | 719 | }
|
|
0 commit comments