fixed matching order so that shelf matches before files in current dir

This commit is contained in:
2026-08-21 16:34:34 +01:00
parent 9c0d92d07c
commit 3a223aa084

View File

@@ -90,26 +90,26 @@ pub fn match_file_name(file_name: &str, shelf: &mut Shelf) -> Result<usize, std:
// Turn given file into string
let match_path = Path::new(file_name);
// If the file path doesnt exist
if !match_path.exists() {
let file_ending = match_path.file_name().expect("Error getting file name");
// For every entry in current shelf
for (i, path) in shelf.content.iter().enumerate() {
// Turn the string back into a path
let shelf_path = Path::new(path).canonicalize()?;
if shelf_path.ends_with(file_ending) {
return Ok(i);
};
}
} // else if it does
let cannonical_path = match_path.canonicalize()?;
// Check if there is a match in the shelf before taking the path verbatim
let file_ending = match_path.file_name().expect("Error getting file name");
// For every entry in current shelf
for (i, path) in shelf.content.iter().enumerate() {
// Turn the string back into a path
let shelf_path = Path::new(path).canonicalize()?;
if cannonical_path == shelf_path {
if shelf_path.ends_with(file_ending) {
return Ok(i);
};
}
if match_path.exists() {
let cannonical_path = match_path.canonicalize()?;
for (i, path) in shelf.content.iter().enumerate() {
let shelf_path = Path::new(path).canonicalize()?;
if cannonical_path == shelf_path {
return Ok(i);
}
}
}