(root: &Path, record: &T)
| 1532 | } |
| 1533 | |
| 1534 | fn append_journal_record<T: Serialize>(root: &Path, record: &T) -> CliResult<()> { |
| 1535 | let path = root.join(EVENT_JOURNAL_RELATIVE); |
| 1536 | let parent = path |
| 1537 | .parent() |
| 1538 | .ok_or_else(|| git_error("event journal has no parent directory"))?; |
| 1539 | fs::create_dir_all(parent).map_err(|error| { |
| 1540 | git_error(format!( |
| 1541 | "cannot create event journal directory '{}': {error}", |
| 1542 | parent.display() |
| 1543 | )) |
| 1544 | })?; |
| 1545 | let mut line = serde_json::to_vec(record) |
| 1546 | .map_err(|error| git_error(format!("cannot encode Git event evidence: {error}")))?; |
| 1547 | line.push(b'\n'); |
| 1548 | |
| 1549 | let mut file = OpenOptions::new() |
| 1550 | .create(true) |
| 1551 | .append(true) |
| 1552 | .open(&path) |
| 1553 | .map_err(|error| { |
| 1554 | git_error(format!( |
| 1555 | "cannot open append-only event journal '{}': {error}", |
| 1556 | path.display() |
| 1557 | )) |
| 1558 | })?; |
| 1559 | file.write_all(&line).map_err(|error| { |
| 1560 | git_error(format!( |
| 1561 | "cannot append event evidence to '{}': {error}", |
| 1562 | path.display() |
| 1563 | )) |
| 1564 | })?; |
| 1565 | file.sync_data().map_err(|error| { |
| 1566 | git_error(format!( |
| 1567 | "cannot sync event evidence in '{}': {error}", |
| 1568 | path.display() |
| 1569 | )) |
| 1570 | })?; |
| 1571 | log_evidence(record); |
| 1572 | Ok(()) |
| 1573 | } |
| 1574 | |
| 1575 | /// Log target of the evidence the hooks journal. |
| 1576 | const HOOK_EVIDENCE_LOG_TARGET: &str = "atomic::git::hook"; |
no test coverage detected