Skip to main content

apimock_server/
respond_util.rs

1use std::path::Path;
2
3use console::style;
4
5/// full file path by joining path prefix to file path
6pub fn full_file_path(path: &str, dir_prefix: &str) -> Option<String> {
7    let p = if !dir_prefix.is_empty() {
8        Path::new(dir_prefix).join(path)
9    } else {
10        Path::new(path).to_path_buf()
11    };
12
13    if !p.exists() {
14        return None;
15    }
16
17    match p.to_str() {
18        Some(x) => Some(x.to_owned()),
19        None => {
20            log::error!(
21                "{} to get str from canonicalized url path:\n{} (prefix = {})",
22                style("failed").red(),
23                path,
24                dir_prefix
25            );
26            None
27        }
28    }
29}