Skip to content

Commit

Permalink
canonicalize file path
Browse files Browse the repository at this point in the history
  • Loading branch information
erfur committed Mar 6, 2024
1 parent 533f35f commit 9eeadf3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,24 @@ pub fn verify_elf_file(file_path: &str) -> Result<(), InjectionError> {
}

pub fn copy_file_to_tmp(file_path: &str) -> Result<String, InjectionError> {
// get absolute path
let file_path_absolute = match std::path::Path::new(file_path).canonicalize() {
Ok(path) => path,
Err(e) => {
error!("Error getting file path: {}", e);
return Err(InjectionError::FileError);
}
};

info!("File path: {}", file_path_absolute.to_str().unwrap());

// skip if the file is already in /dev/local/tmp
if file_path.starts_with(TMP_DIR_PATH) {
if file_path_absolute.starts_with(TMP_DIR_PATH) {
info!("File is already in {}", TMP_DIR_PATH);
return Ok(file_path.to_string());
return Ok(String::from(file_path_absolute.to_str().unwrap()));
}

let file_name = match std::path::Path::new(file_path).file_name() {
let file_name = match file_path_absolute.file_name() {
Some(name) => name.to_str().unwrap(),
None => {
error!("Error getting file name");
Expand Down

0 comments on commit 9eeadf3

Please sign in to comment.