From 3b1fe8a2a0dfe0b188e5fca9ef8ce68efbb05927 Mon Sep 17 00:00:00 2001 From: Sandro-Alessio Gierens Date: Fri, 11 Aug 2023 22:44:11 +0200 Subject: [PATCH] Revise File::ext to extract "so" extension from versioned shared libraries Resolves #1105 --- src/fs/file.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index bccc6550..7c6009fe 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -132,9 +132,30 @@ impl<'dir> File<'dir> { fn ext(path: &Path) -> Option { let name = path.file_name().map(|f| f.to_string_lossy().to_string())?; - name.rfind('.') + match name.rfind('.') .map(|p| name[p + 1 ..] .to_ascii_lowercase()) + { + Some(ext) => { + if ext.chars().all(char::is_numeric) { + for word in name.split('.').rev().skip(1) { + if !word.chars().all(char::is_numeric) { + if word == "so" { + return Some("so".into()); + } + else { + break; + } + } + } + Some(ext) + } + else { + Some(ext) + } + }, + _ => None, + } } /// Whether this file is a directory on the filesystem.