Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let BLS_ENTRIES = "/some/prefix/";
- let entry = String::new("../../../some/prefix/foobar.conf");
- let path = std::path::Path::new(&entry);
- let abs_path = path.canonicalize();
- // We try to ensure that the path exists, that it's a file in BLS_ENTRIES and that it's suffix is .conf
- match abs_path {
- Ok(abs_path) => {
- if abs_path.exists() {
- if abs_path.parent() != Some(Path::new(BLS_ENTRIES)) {
- return Err(format!("entry argument {} is not in bootloader entry directory {}", entry, BLS_ENTRIES));
- }
- if !abs_path.ends_with(".conf") {
- return Err(format!("entry argument {:?} does not have .conf suffix", abs_path));
- }
- match abs_path.file_stem() {
- Some(file_stem) => {
- match file_stem.to_str() {
- Some(file_stem) => {
- return Ok(BLSEntry::new(String::from(file_stem)));
- }
- _ => {}
- }
- }
- _ => {}
- }
- }
- },
- _ => {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement