(root: &Path, record: &T)
| 1501 | } |
| 1502 | |
| 1503 | fn append_journal_record<T: Serialize>(root: &Path, record: &T) -> CliResult<()> { |
| 1504 | let path = root.join(EVENT_JOURNAL_RELATIVE); |
| 1505 | let parent = path |
| 1506 | .parent() |
| 1507 | .ok_or_else(|| git_error("event journal has no parent directory"))?; |
| 1508 | fs::create_dir_all(parent).map_err(|error| { |
| 1509 | git_error(format!( |
| 1510 | "cannot create event journal directory '{}': {error}", |
| 1511 | parent.display() |
| 1512 | )) |
| 1513 | })?; |
| 1514 | let mut line = serde_json::to_vec(record) |
| 1515 | .map_err(|error| git_error(format!("cannot encode Git event evidence: {error}")))?; |
| 1516 | line.push(b'\n'); |
| 1517 | |
| 1518 | let mut file = OpenOptions::new() |
| 1519 | .create(true) |
| 1520 | .append(true) |
| 1521 | .open(&path) |
| 1522 | .map_err(|error| { |
| 1523 | git_error(format!( |
| 1524 | "cannot open append-only event journal '{}': {error}", |
| 1525 | path.display() |
| 1526 | )) |
| 1527 | })?; |
| 1528 | file.write_all(&line).map_err(|error| { |
| 1529 | git_error(format!( |
| 1530 | "cannot append event evidence to '{}': {error}", |
| 1531 | path.display() |
| 1532 | )) |
| 1533 | })?; |
| 1534 | file.sync_data().map_err(|error| { |
| 1535 | git_error(format!( |
| 1536 | "cannot sync event evidence in '{}': {error}", |
| 1537 | path.display() |
| 1538 | )) |
| 1539 | })?; |
| 1540 | log_evidence(record); |
| 1541 | Ok(()) |
| 1542 | } |
| 1543 | |
| 1544 | /// Log target of the evidence the hooks journal. |
| 1545 | const HOOK_EVIDENCE_LOG_TARGET: &str = "atomic::git::hook"; |
no test coverage detected