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
//! Owner-only filesystem helpers.
//!
//! moadim's on-disk tree under `~/.config/moadim/` (and the run workbenches under
//! `~/.moadim/workbenches/`) is effectively a secret/transcript store: `agent.log`
//! holds the full agent transcript, `prompt.md` the operating instructions, and
//! routine state can reference tokens sourced via the login shell. Created with
//! the process's default umask those land at world-readable `0644`/`0755` — a
//! local information-disclosure vector on a shared host. This helper creates the
//! daemon's own directories owner-only (`0700`).
//!
//! Unix-only behaviour; on other platforms the call falls back to the standard
//! library with no mode tightening (the project's permission model is unix).
use io;
use Path;
/// Create `path` and any missing parent directories, owner-only (`0700`) on unix.
///
/// Mirrors [`std::fs::create_dir_all`] but sets mode `0700` on every directory it
/// creates. An already-existing directory is left as-is (not re-chmodded),
/// matching `create_dir_all`'s idempotent contract.
/// Returns `path`'s parent directory, or an [`io::Error`] naming `what` (e.g. `"pid file"`) if
/// `path` has no parent (i.e. `path` is `/` or empty) — a condition none of this crate's
/// generated config/log/history paths hit in practice, but every writer needs an error arm for
/// it rather than a panic. Centralized here so that arm is tested once instead of once per
/// call site.