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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use std::path::{Path, PathBuf};
pub fn default_config_path(filename: impl AsRef<Path>) -> PathBuf {
dirs::config_dir()
.unwrap_or_else(|| panic!("Cannot determine default config path"))
.join("dt")
.join(filename)
}
pub fn host_specific_suffix(hostname_sep: &str) -> String {
hostname_sep.to_owned()
+ gethostname::gethostname()
.to_str()
.expect("Failed getting hostname")
}
#[cfg(test)]
pub(crate) mod testing {
use std::{
fs::Permissions, os::unix::prelude::PermissionsExt, path::PathBuf,
};
use color_eyre::Report;
const TESTROOT: &str = "/tmp/dt-testing/syncing";
pub fn get_testroot() -> PathBuf {
TESTROOT.into()
}
pub fn prepare_directory(
abspath: PathBuf,
mode: u32,
) -> Result<PathBuf, Report> {
std::fs::create_dir_all(&abspath)?;
std::fs::set_permissions(&abspath, Permissions::from_mode(mode))?;
Ok(abspath)
}
pub fn prepare_file(
abspath: PathBuf,
mode: u32,
) -> Result<PathBuf, Report> {
if let Some(parent) = abspath.parent() {
std::fs::create_dir_all(parent)?;
}
std::fs::write(
&abspath,
"Created by: `dt_core::syncing::tests::prepare_file`\n",
)?;
std::fs::set_permissions(&abspath, Permissions::from_mode(mode))?;
Ok(abspath)
}
}