use super::{Finding, Scope, Severity};
use crate::{ObjectId, ObjectKind};
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct TransferLimits {
pub max_objects: usize,
pub max_bytes: u64,
pub max_findings: usize,
pub packs: crate::PackLimits,
pub read: crate::ReadLimits,
}
impl Default for TransferLimits {
fn default() -> Self {
Self {
max_objects: 1 << 24,
max_bytes: 1 << 32,
max_findings: 1 << 20,
packs: Default::default(),
read: Default::default(),
}
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct TransferFinding {
pub id: ObjectId,
pub kind: ObjectKind,
pub finding: Finding,
}
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct TransferReport {
pub checked_objects: usize,
pub decoded_bytes: u64,
pub findings: Vec<TransferFinding>,
pub unknown_messages: Vec<Vec<u8>>,
}
impl TransferReport {
pub fn has_errors(&self) -> bool {
self.findings
.iter()
.any(|finding| matches!(finding.finding.severity, Severity::Error | Severity::Fatal))
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum TransferError {
#[error(transparent)]
Config(#[from] Box<crate::config::InvalidValue>),
#[error(transparent)]
Policy(#[from] super::PolicyError),
#[error(transparent)]
Read(#[from] Box<crate::ObjectReadError>),
#[error(transparent)]
Artifact(#[from] Box<crate::fetch::FetchError>),
#[error("received-pack fsck I/O")]
Io(#[from] std::io::Error),
#[error("received pack failed fsck policy")]
Rejected(Box<TransferReport>),
#[error("received-pack fsck limit exceeded: {0}")]
Limit(&'static str),
#[error("received-pack fsck cancelled")]
Cancelled,
}
pub fn transfer_enabled(
config: &crate::Config,
scope: Scope,
) -> Result<bool, crate::config::InvalidValue> {
let section = match scope {
Scope::Repository => return Ok(true),
Scope::Fetch => "fetch",
Scope::Receive => "receive",
};
match config.boolean(section, None, "fsckobjects")? {
Some(enabled) => Ok(enabled),
None => Ok(config
.boolean("transfer", None, "fsckobjects")?
.unwrap_or(false)),
}
}