From 14e4d05a9f92379d0b14b9934f0fb3e7e0e79db6 Mon Sep 17 00:00:00 2001 From: David Horner Date: Mon, 29 Jan 2024 14:17:04 -0500 Subject: [PATCH] use constant instead of <0 for ls fix (#11642) https://github.com/nushell/nushell/pull/10558#issuecomment-1911076784 more correct than <0. safer check. --- crates/nu-command/src/filesystem/ls.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index a00cab81b2..5a23e25a7c 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -632,7 +632,9 @@ fn try_convert_to_local_date_time(t: SystemTime) -> Option> { } }; - if sec < 0 { + const NEG_UNIX_EPOCH: i64 = -11644473600; // t was invalid 0, UNIX_EPOCH subtracted above. + if sec == NEG_UNIX_EPOCH { + // do not tz lookup invalid SystemTime return None; } match Utc.timestamp_opt(sec, nsec) { @@ -680,14 +682,10 @@ mod windows_helper { let find_data = match find_first_file(filename, span) { Ok(fd) => fd, Err(e) => { - // Sometimes this happens when the file name is not allowed on Windows (ex: ends with a '.') + // Sometimes this happens when the file name is not allowed on Windows (ex: ends with a '.', pipes) // For now, we just log it and give up on returning metadata columns // TODO: find another way to get this data (like cmd.exe, pwsh, and MINGW bash can) - // eprintln!( - // "Failed to read metadata for '{}'. It may have an illegal filename", - // filename.to_string_lossy() - // ); - log::error!("ls: {e}"); + log::error!("ls: '{}' {}", filename.to_string_lossy(), e); return Value::record(record, span); } };