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
use crate::{err, util};
use std::{
env::{current_dir, set_current_dir, var},
fs::create_dir_all,
path::{Path, PathBuf},
};
#[inline]
pub fn root() -> Result<PathBuf, std::env::VarError> {
Ok(Path::new(&var("ARCTK_DIR")?).to_path_buf())
}
#[inline]
fn input_dir(dir: &PathBuf) -> Result<PathBuf, std::io::Error> {
set_current_dir(dir)?;
current_dir()
}
#[inline]
fn output_dir(dir: &PathBuf) -> Result<PathBuf, std::io::Error> {
create_dir_all(dir)?;
Ok(dir.to_path_buf())
}
#[inline]
pub fn io_dirs(
input: Option<PathBuf>,
output: Option<PathBuf>,
) -> Result<(PathBuf, PathBuf), err::Error> {
let exec_name = util::exec::name()?;
let in_dir = if let Some(input) = input {
input
} else {
root()?.join("input").join(&exec_name)
};
let out_dir = if let Some(output) = output {
output
} else {
root()?.join("output").join(exec_name)
};
let in_dir = input_dir(&in_dir)?;
let out_dir = output_dir(&out_dir)?;
Ok((in_dir, out_dir))
}