1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use std::fs::{self, File};
use std::io;
use std::io::prelude::*;
use std::path::{Path, PathBuf, StripPrefixError};
pub fn is_symlink(path: &Path) -> bool {
fs::symlink_metadata(path)
.map(|md| md.file_type().is_symlink())
.unwrap_or(false)
}
pub(crate) fn read_path(path: &Path) -> io::Result<String> {
let mut file = File::open(path)?;
read_file(&mut file)
}
pub(crate) fn read_file(file: &mut File) -> io::Result<String> {
let mut contents = String::new();
file.read_to_string(&mut contents)?;
Ok(contents)
}
pub fn join_full_paths(
path_1: &Path,
path_2: &Path,
) -> Result<PathBuf, StripPrefixError> {
if path_2.has_root() && cfg!(target_family = "unix") {
let path_2 = path_2.strip_prefix("/")?;
return Ok(path_1.join(path_2));
};
Ok(path_1.join(path_2))
}