uutils / util-linux

Rust reimplementation of the util-linux project
MIT License
17 stars 10 forks source link

Add last Utility #65

Closed Puffy1215 closed 1 month ago

Puffy1215 commented 3 months ago

I implemented the last utility in https://github.com/uutils/util-linux/issues/18.

Limitations

Tests I added some tests too to go along with the PR. They are kind of simplistic though in that they only do a check to verify there was some output. The timestamp checks only do a simplistic regex check on the output.

sylvestre commented 3 months ago

i guess you saw it but the builds are failing

Puffy1215 commented 3 months ago

i guess you saw it but the builds are failing

Windows and macOS is still broken. I'll work on fixing those. I will also fix the still existing linting issues.

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 63.01370% with 135 lines in your changes missing coverage. Please review.

Project coverage is 58.08%. Comparing base (a87683f) to head (633aea3). Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
src/uu/last/src/platform/unix.rs 56.65% 127 Missing :warning:
src/uu/last/src/platform/windows.rs 0.00% 5 Missing :warning:
tests/by-util/test_last.rs 93.47% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #65 +/- ## ========================================== + Coverage 55.36% 58.08% +2.71% ========================================== Files 17 21 +4 Lines 1472 1849 +377 Branches 243 313 +70 ========================================== + Hits 815 1074 +259 - Misses 641 773 +132 + Partials 16 2 -14 ``` | [Flag](https://app.codecov.io/gh/uutils/util-linux/pull/65/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uutils) | Coverage Δ | | |---|---|---| | [macos_latest](https://app.codecov.io/gh/uutils/util-linux/pull/65/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uutils) | `57.56% <54.06%> (+0.22%)` | :arrow_up: | | [ubuntu_latest](https://app.codecov.io/gh/uutils/util-linux/pull/65/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uutils) | `58.13% <57.50%> (+7.39%)` | :arrow_up: | | [windows_latest](https://app.codecov.io/gh/uutils/util-linux/pull/65/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uutils) | `0.16% <0.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uutils#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Puffy1215 commented 3 months ago

It looks like I have everything working now. The existing errors appear to be from other utilities.

failures:
    test_mountpoint::test_invalid_arg
    test_rev::test_invalid_arg
sylvestre commented 3 months ago

dunno if it is hard to do but could you please add tests with an invalid /var/log/wtmp to check that the error management is properly done ? thanks

Puffy1215 commented 3 months ago

dunno if it is hard to do but could you please add tests with an invalid /var/log/wtmp to check that the error management is properly done ? thanks

Added one test so far that matches the behavior with the linux org implementation. That seems like the only test I could get working so far. There were some discrepancies I noticed that I think are beyond my implementation, and involve the UtmpxIter code.

For example, if you have a file of arbitrary bytes (Say a file of one long string of all 'a' characters) which can fit into Utmpx struct, the linux org implementation is able to read it into the fields and display it. However, with our implementation, it does not load any of them into a struct, and so displays nothing.

sylvestre commented 3 months ago

a bunch of jobs are failing, could you please have a look?

Like:


error: length comparison to zero
   --> src/uu/last/src/platform/unix.rs:190:16
    |
190 |             if ut_stack.len() == 0 {
    |                ^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `ut_stack.is_empty()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
    = note: `-D clippy::len-zero` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::len_zero)]`

error: useless conversion to the same type: `i64`
   --> src/uu/last/src/platform/unix.rs:275:62
    |
275 |         let time = time::OffsetDateTime::from_unix_timestamp(secs.into())
    |                                                              ^^^^^^^^^^^ help: consider removing `.into()`: `secs`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
    = note: `-D clippy::useless-conversion` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::useless_conversion)]`

error: useless conversion to the same type: `u64`
   --> src/uu/last/src/platform/unix.rs:277:36
    |
277 |             + Duration::from_nanos(nsecs.into());
    |                                    ^^^^^^^^^^^^ help: consider removing `.into()`: `nsecs`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion

error: useless conversion to the same type: `uucore::utmpx::time::OffsetDateTime`
   --> src/uu/last/src/platform/unix.rs:284:13
    |
284 |             OffsetDateTime::from(time).replace_offset(offset) + Duration::from_secs(offset_secs);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `OffsetDateTime::from()`: `time`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
cakebaker commented 1 month ago

@Puffy1215 ping?