mod control;
mod copyright;
mod deb;
mod dsc;
mod file_list;
mod tarball;
mod utils;
#[cfg(test)]
mod deb_extra_test;
#[cfg(test)]
mod scan_test;
pub use self::control::{
DebianControlParser, DebianDistrolessInstalledParser, DebianInstalledParser,
};
pub use self::copyright::DebianCopyrightParser;
pub use self::deb::{
DebianControlInExtractedDebParser, DebianDebParser, DebianMd5sumInPackageParser,
};
pub use self::dsc::DebianDscParser;
pub use self::file_list::{DebianInstalledListParser, DebianInstalledMd5sumsParser};
pub use self::tarball::{DebianDebianTarParser, DebianOrigTarParser};
use std::sync::LazyLock;
use crate::models::{DatasourceId, PackageData, PackageType};
use regex::Regex;
const PACKAGE_TYPE: PackageType = PackageType::Deb;
const MAX_ARCHIVE_SIZE: u64 = 1024 * 1024 * 1024;
const MAX_FILE_SIZE: u64 = 50 * 1024 * 1024;
const MAX_COMPRESSION_RATIO: usize = 100;
static DEP_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r"^\s*([a-zA-Z0-9][a-zA-Z0-9.+\-]+)\s*(?:\(([<>=!]+)\s*([^)]+)\))?\s*(?:\[.*\])?\s*$",
)
.expect("compile-time constant dependency regex")
});
fn default_package_data(datasource_id: DatasourceId) -> PackageData {
PackageData {
package_type: Some(PACKAGE_TYPE),
datasource_id: Some(datasource_id),
..Default::default()
}
}
const VERSION_CLUES_DEBIAN: &[&str] = &["deb"];
const VERSION_CLUES_UBUNTU: &[&str] = &["ubuntu"];
const MAINTAINER_CLUES_DEBIAN: &[&str] = &[
"packages.debian.org",
"lists.debian.org",
"lists.alioth.debian.org",
"@debian.org",
"debian-init-diversity@",
];
const MAINTAINER_CLUES_UBUNTU: &[&str] = &["lists.ubuntu.com", "@canonical.com"];
struct DepFieldSpec {
field: &'static str,
scope: &'static str,
is_runtime: bool,
is_optional: bool,
}
const DEP_FIELDS: &[DepFieldSpec] = &[
DepFieldSpec {
field: "depends",
scope: "depends",
is_runtime: true,
is_optional: false,
},
DepFieldSpec {
field: "pre-depends",
scope: "pre-depends",
is_runtime: true,
is_optional: false,
},
DepFieldSpec {
field: "recommends",
scope: "recommends",
is_runtime: true,
is_optional: true,
},
DepFieldSpec {
field: "suggests",
scope: "suggests",
is_runtime: true,
is_optional: true,
},
DepFieldSpec {
field: "breaks",
scope: "breaks",
is_runtime: false,
is_optional: false,
},
DepFieldSpec {
field: "conflicts",
scope: "conflicts",
is_runtime: false,
is_optional: false,
},
DepFieldSpec {
field: "replaces",
scope: "replaces",
is_runtime: false,
is_optional: false,
},
DepFieldSpec {
field: "provides",
scope: "provides",
is_runtime: false,
is_optional: false,
},
DepFieldSpec {
field: "build-depends",
scope: "build-depends",
is_runtime: false,
is_optional: false,
},
DepFieldSpec {
field: "build-depends-indep",
scope: "build-depends-indep",
is_runtime: false,
is_optional: false,
},
DepFieldSpec {
field: "build-conflicts",
scope: "build-conflicts",
is_runtime: false,
is_optional: false,
},
];
const IGNORED_ROOT_DIRS: &[&str] = &["/.", "/bin", "/etc", "/lib", "/sbin", "/usr", "/var"];