From a7f95d5a23826ad5bcdd4d2b8fbbb0b622295010 Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Wed, 28 Jun 2023 21:38:13 -0700 Subject: [PATCH] hashsum: use file_stem() instead of file_name() This program matches the binary name to determine which algorithm to use. On Windows, `file_name()` was matching against a string with `.exe`, causing binaries like `sha256sum.exe` to not properly detect the algorithm. By using `file_stem()`, we exclude the `.exe` from matching, achieving similar and correct behavior on Windows. --- src/uu/hashsum/src/hashsum.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 7b571efcd5..cc1b050fd1 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -306,7 +306,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { // if there is no program name for some reason, default to "hashsum" let program = args.next().unwrap_or_else(|| OsString::from(NAME)); let binary_name = Path::new(&program) - .file_name() + .file_stem() .unwrap_or_else(|| OsStr::new(NAME)) .to_string_lossy();