Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress man pages with zstd, enable mancompress by default #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion man/package.yml.5
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ If in doubt, omit this option where possible\.
.IP "\[ci]" 4
\fBmancompress\fR [boolean]
.IP
By default, this key is disabled\. Enables compression of man/info pages using gzip at the maximum compression level, to decrease the installed size of the package on disk\. Disabled by default as it generally increases the size of eopkg file(s) due to xz having a hard time compressing pre\-compressed gzip files\. Only enable when it significantly reduces the installed size of a package on disk without sacrificing eopkg size too much\.
By default, this key is enabled\. Enables compression of man/info pages using zstd at the maximum compression level, to decrease the installed size of the package on disk\. Disabled by default as it generally increases the size of eopkg file(s) due to xz having a hard time compressing pre\-compressed zstd files\. Only enable when it significantly reduces the installed size of a package on disk without sacrificing eopkg size too much\.
.IP "\[ci]" 4
\fBfatfakeroot\fR [boolean]
.IP
Expand Down
6 changes: 3 additions & 3 deletions man/package.yml.5.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/package.yml.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ additional functionality.

* `mancompress` [boolean]

By default, this key is disabled. Enables compression of man/info pages
using gzip at the maximum compression level, to decrease the installed
By default, this key is enabled. Enables compression of man/info pages
using zstd at the maximum compression level, to decrease the installed
size of the package on disk. Disabled by default as it generally increases the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled by default

size of eopkg file(s) due to xz having a hard time compressing pre-compressed
gzip files. Only enable when it significantly reduces the installed
zstd files. Only enable when it significantly reduces the installed
size of a package on disk without sacrificing eopkg size too much.

* `fatfakeroot` [boolean]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PyYaml
python-magic
xattr
zstandard
36 changes: 21 additions & 15 deletions ypkg2/compressdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
# (at your option) any later version.
#

import gzip
import os
import shutil
import zstandard as zstd

compressed_exts = [
".gz",
Expand All @@ -36,8 +35,8 @@ def is_compressed(path):
return False


def compress_gzip(path):
"""Compresses a single file with `gzip`.
def compress_zstd(path):
"""Compresses a single file with `zstd`.

The original file will be deleted after compression.
"""
Expand All @@ -47,12 +46,19 @@ def compress_gzip(path):
# Open the file
in_file = open(path)

# Capture the mtime of the file so we can re-apply it to the compressed version (for reproducibility)
in_time = os.path.getmtime(path)

# Create the file to write to
out_path = "{}.gz".format(path)
out_path = "{}.zst".format(path)

# Open the file
with open(path, "rb") as in_file, gzip.GzipFile(filename=out_path, mode="wb", compresslevel=9, mtime=0) as out_file:
shutil.copyfileobj(in_file, out_file)
cctx = zstd.ZstdCompressor(level=19)
with open(path, "rb") as in_file, open(out_path, "wb") as out_file:
cctx.copy_stream(in_file, out_file)

# Restore the mtime
os.utime(out_path, (in_time, in_time))

# Remove the original file
os.unlink(path)
Expand All @@ -66,7 +72,7 @@ def update_link(path):
"""Update a symlink to point to the compressed target.

This reads the target path of a symlink, unlinks it, and creates
a new link pointing to the target path with `.gz` appended to the end.
a new link pointing to the target path with `.zst` appended to the end.
"""

if not os.path.islink(path):
Expand All @@ -79,7 +85,7 @@ def update_link(path):
return

# Figure out what the compressed target path is
new_link = "{}.gz".format(link_target)
new_link = "{}.zst".format(link_target)

# Re-link to the new target
os.unlink(path)
Expand All @@ -91,7 +97,7 @@ def compress_dir(path):

This function iterates over all children in the
given directory. If the file is a regular uncompressed
file, it will be compressed with `gzip`.
file, it will be compressed with `zstd`.

Files that are already compressed will be ignored.

Expand All @@ -114,10 +120,10 @@ def compress_dir(path):
update_link(file_path)
elif os.path.isfile(file_path):
# We have a file, compress it
bytes_saved += compress_gzip(file_path)
bytes_saved += compress_zstd(file_path)
num_compressed += 1

return (num_compressed, bytes_saved)
return num_compressed, bytes_saved


def compress_man_pages(root):
Expand Down Expand Up @@ -154,7 +160,7 @@ def compress_man_pages(root):
num_compressed += c
bytes_saved += s

return (num_compressed, bytes_saved)
return num_compressed, bytes_saved


def compress_info_pages(root):
Expand All @@ -181,7 +187,7 @@ def compress_info_pages(root):
if is_compressed(path):
continue

bytes_saved += compress_gzip(path)
bytes_saved += compress_zstd(path)
num_compressed += 1
elif os.path.islink(path):
# If it's a symlink, update it
Expand All @@ -192,4 +198,4 @@ def compress_info_pages(root):
num_compressed += c
bytes_saved += s

return (num_compressed, bytes_saved)
return num_compressed, bytes_saved
2 changes: 1 addition & 1 deletion ypkg2/ypkgspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class YpkgSpec:
pkg_clang = False
pkg_strip = True
pkg_lastrip = True
pkg_mancompress = False
pkg_mancompress = True
pkg_fatfakeroot = False
pkg_ccache = True
pkg_emul32 = False
Expand Down