Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Compress other assets besides man pages #193

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,27 @@ fn has_copyright_metadata(file: &str) -> bool {
.any(|l| l.starts_with("License: ") || l.starts_with("Source: ") || l.starts_with("Upstream-Name: ") || l.starts_with("Format: "))
}

/// Compress man page assets per Debian Policy.
/// Compress man pages and other assets per Debian Policy.
///
/// # References
///
/// https://www.debian.org/doc/debian-policy/ch-docs.html#manual-pages
/// https://www.debian.org/doc/debian-policy/ch-docs.html
/// https://lintian.debian.org/tags/manpage-not-compressed.html
pub fn compress_man_pages(options: &mut Config, listener: &dyn Listener) -> CDResult<()> {
pub fn compress_assets(options: &mut Config, listener: &dyn Listener) -> CDResult<()> {
let mut indices_to_remove = Vec::new();
let mut new_assets = Vec::new();

fn needs_compression(path: &str) -> bool {
!path.ends_with(".gz")
&& (path.starts_with("usr/share/man/")
|| (path.starts_with("usr/share/doc/")
&& (path.ends_with("/NEWS") || path.ends_with("/changelog")))
|| (path.starts_with("usr/share/info/") && path.ends_with(".info")))
}

for (idx, asset) in options.assets.resolved.iter().enumerate() {
let target_path_str = asset.target_path.to_string_lossy();
if target_path_str.starts_with("usr/share/man/") &&
!target_path_str.ends_with(".gz")
{
if needs_compression(&target_path_str) {
listener.info(format!("Compressing '{}'", asset.source.path().unwrap_or(Path::new("-")).display()));

let content = asset.source.data()?;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn process(

options.resolve_assets()?;

crate::data::compress_man_pages(&mut options, listener)?;
crate::data::compress_assets(&mut options, listener)?;

if (options.strip || separate_debug_symbols) && !no_strip {
strip_binaries(&mut options, target, listener, separate_debug_symbols)?;
Expand Down