last: fix some hostnames are not shown properly with --hostname option issue 212 (#246)

* last: fix not all hostnames are shown in the last column with --hostlast option

* last: fix not all hostnames are shown in the last column with --hostlast option

* Added test case related to the hostlast option in last command.

* Change binary input fixture name for last command and Fix format source code.

* feat: add macOS platform & update tests for compatibility

* fix: correct formatting in platform and test files for macOS compatibility

* fix: format

* fix: correct variable name and improve test output handling
This commit is contained in:
Lionel Mendes
2025-05-08 17:32:25 +02:00
committed by GitHub
parent dae500f492
commit 55c8ee013b
5 changed files with 66 additions and 18 deletions

View File

@@ -0,0 +1,17 @@
// This file is part of the uutils util-linux package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// Specific implementation for OpenBSD: tool unsupported (utmpx not supported)
use crate::uu_app;
use uucore::error::UResult;
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let _matches = uu_app().try_get_matches_from(args)?;
println!("unsupported command on macOS");
Ok(())
}

View File

@@ -3,9 +3,9 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "macos")))]
mod unix;
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "macos")))]
pub use self::unix::*;
#[cfg(target_os = "openbsd")]
@@ -17,3 +17,8 @@ pub use self::openbsd::*;
mod windows;
#[cfg(windows)]
pub use self::windows::*;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use self::macos::*;

View File

@@ -369,7 +369,7 @@ impl Last {
.unwrap_or_else(|| time::OffsetDateTime::from_unix_timestamp(0).unwrap());
let time_delta = duration_string(calculate_time_delta(&curr_datetime, &shutdown));
if ut.is_user_process() {
proc_status = Some("- down");
proc_status = Some("- down ");
}
(
self.end_time_string(proc_status, &shutdown),
@@ -520,16 +520,18 @@ impl Last {
write!(buf, " {host_to_print:<16}").unwrap_or_default();
}
let time_size = 3 + 2 + 2 + 1 + 2;
if self.host_last && !self.no_host && self.time_format != "notime" {
write!(buf, " {time:<time_size$}").unwrap_or_default();
write!(buf, " {end_time:<8}").unwrap_or_default();
write!(buf, " {host_to_print}").unwrap_or_default();
} else if self.time_format != "notime" {
write!(buf, " {time:<time_size$}").unwrap_or_default();
write!(buf, " {end_time:<8}").unwrap_or_default();
if self.time_format != "notime" {
let time_fmt = 12;
let end_time_delta = format!("{end_time:<6} {delta}");
let end_time_delta_fmt = 18;
write!(buf, " {time:<time_fmt$}").unwrap_or_default();
write!(buf, " {end_time_delta:<end_time_delta_fmt$}").unwrap_or_default();
}
if self.host_last && !self.no_host {
write!(buf, " {host_to_print:<16}").unwrap_or_default();
}
write!(buf, " {delta:^6}").unwrap_or_default();
println!("{}", buf.trim_end());
}
}