aya: `construct_debuglink_path()` should be infallible

`construct_debuglink_path()` returns a `Result`, but it doesn't actually
do anything that can fail. This means callers must do a useless
`unwrap()` to get at the return value.

This fixes the signature to reflect that the function is infallible.
main
Thomas Bertschinger 7 days ago committed by Tamir Duberstein
parent 0b1fbe1cd3
commit ab182be622

@ -617,14 +617,11 @@ enum ResolveSymbolError {
BuildIdMismatch(String), BuildIdMismatch(String),
} }
fn construct_debuglink_path( fn construct_debuglink_path(filename: &[u8], main_path: &Path) -> PathBuf {
filename: &[u8],
main_path: &Path,
) -> Result<PathBuf, ResolveSymbolError> {
let filename_str = OsStr::from_bytes(filename); let filename_str = OsStr::from_bytes(filename);
let debuglink_path = Path::new(filename_str); let debuglink_path = Path::new(filename_str);
let resolved_path = if debuglink_path.is_relative() { if debuglink_path.is_relative() {
// If the debug path is relative, resolve it against the parent of the main path // If the debug path is relative, resolve it against the parent of the main path
main_path.parent().map_or_else( main_path.parent().map_or_else(
|| PathBuf::from(debuglink_path), // Use original if no parent || PathBuf::from(debuglink_path), // Use original if no parent
@ -633,9 +630,7 @@ fn construct_debuglink_path(
} else { } else {
// If the path is not relative, just use original // If the path is not relative, just use original
PathBuf::from(debuglink_path) PathBuf::from(debuglink_path)
}; }
Ok(resolved_path)
} }
fn verify_build_ids<'a>( fn verify_build_ids<'a>(
@ -664,7 +659,7 @@ fn find_debug_path_in_object<'a>(
symbol: &str, symbol: &str,
) -> Result<PathBuf, ResolveSymbolError> { ) -> Result<PathBuf, ResolveSymbolError> {
match obj.gnu_debuglink() { match obj.gnu_debuglink() {
Ok(Some((filename, _))) => construct_debuglink_path(filename, main_path), Ok(Some((filename, _))) => Ok(construct_debuglink_path(filename, main_path)),
Ok(None) => Err(ResolveSymbolError::Unknown(symbol.to_string())), Ok(None) => Err(ResolveSymbolError::Unknown(symbol.to_string())),
Err(err) => Err(ResolveSymbolError::Object(err)), Err(err) => Err(ResolveSymbolError::Object(err)),
} }
@ -737,7 +732,7 @@ mod tests {
let main_path = Path::new("/usr/lib/main_binary"); let main_path = Path::new("/usr/lib/main_binary");
let expected = Path::new("/usr/lib/debug_info"); let expected = Path::new("/usr/lib/debug_info");
let result = construct_debuglink_path(filename, main_path).unwrap(); let result = construct_debuglink_path(filename, main_path);
assert_eq!( assert_eq!(
result, expected, result, expected,
"The debug path should resolve relative to the main path's parent" "The debug path should resolve relative to the main path's parent"
@ -750,7 +745,7 @@ mod tests {
let main_path = Path::new("main_binary"); let main_path = Path::new("main_binary");
let expected = Path::new("debug_info"); let expected = Path::new("debug_info");
let result = construct_debuglink_path(filename, main_path).unwrap(); let result = construct_debuglink_path(filename, main_path);
assert_eq!( assert_eq!(
result, expected, result, expected,
"The debug path should be the original path as there is no parent" "The debug path should be the original path as there is no parent"
@ -763,7 +758,7 @@ mod tests {
let main_path = Path::new("/usr/lib/main_binary"); let main_path = Path::new("/usr/lib/main_binary");
let expected = Path::new("/absolute/path/to/debug_info"); let expected = Path::new("/absolute/path/to/debug_info");
let result = construct_debuglink_path(filename, main_path).unwrap(); let result = construct_debuglink_path(filename, main_path);
assert_eq!( assert_eq!(
result, expected, result, expected,
"The debug path should be the same as the input absolute path" "The debug path should be the same as the input absolute path"

Loading…
Cancel
Save