Skip to content

Commit

Permalink
Add support for zstd compression format where supported
Browse files Browse the repository at this point in the history
  • Loading branch information
bapt committed Jun 25, 2019
1 parent 7a96832 commit d34c8d9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/pkg-create.8
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Set
.Ar format
as the package output format.
It can be one of
.Ar txz , tbz , tgz
.Ar tzst, txz , tbz , tgz
or
.Ar tar
which are currently the only supported formats.
Expand Down
16 changes: 16 additions & 0 deletions libpkg/packing.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ packing_set_format(struct archive *a, pkg_formats format)
const char *notsupp_fmt = "%s is not supported, trying %s";

switch (format) {
case TZS:
#ifdef HAVE_ARCHIVE_WRITE_ADD_FILTER_ZSTD
if (archive_write_add_filter_zstd(a) == ARCHIVE_OK) {
if (archive_write_set_filter_option(a, NULL, "compression-level", "19") != ARCHIVE_OK) {
pkg_emit_error("bad compression-level");
}
return ("tzst");
}
#endif
pkg_emit_error(notsupp_fmt, "zstd", "xz");
/* FALLTHRU */
case TXZ:
if (archive_write_add_filter_xz(a) == ARCHIVE_OK)
return ("txz");
Expand Down Expand Up @@ -342,6 +353,8 @@ packing_format_from_string(const char *str)
{
if (str == NULL)
return TXZ;
if (strcmp(str, "tzst") == 0)
return TZS;
if (strcmp(str, "txz") == 0)
return TXZ;
if (strcmp(str, "tbz") == 0)
Expand All @@ -360,6 +373,9 @@ packing_format_to_string(pkg_formats format)
const char *res = NULL;

switch (format) {
case TZS:
res = "tzst";
break;
case TXZ:
res = "txz";
break;
Expand Down
2 changes: 1 addition & 1 deletion libpkg/pkg.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ void pkg_solve_problem_free(struct pkg_solve_problem *problem);
/**
* Archive formats options.
*/
typedef enum pkg_formats { TAR, TGZ, TBZ, TXZ } pkg_formats;
typedef enum pkg_formats { TAR, TGZ, TBZ, TXZ, TZS } pkg_formats;

/**
* Create package from an installed & registered package
Expand Down
3 changes: 2 additions & 1 deletion libpkg/pkg_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ pkg_jobs_maybe_match_file(struct job_pattern *jp, const char *pattern)
* Compare suffix with .txz or .tbz
*/
dot_pos ++;
if (strcmp(dot_pos, "txz") == 0 ||
if (strcmp(dot_pos, "tzst") == 0 ||
strcmp(dot_pos, "txz") == 0 ||
strcmp(dot_pos, "tbz") == 0 ||
strcmp(dot_pos, "tgz") == 0 ||
strcmp(dot_pos, "tar") == 0) {
Expand Down
2 changes: 1 addition & 1 deletion libpkg/pkg_repo_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pkg_repo_meta_open_schema_v1()
"version = {type = integer};\n"
"maintainer = {type = string};\n"
"source = {type = string};\n"
"packing_format = {enum = [txz, tbz, tgz, tar]};\n"
"packing_format = {enum = [tszt, txz, tbz, tgz, tar]};\n"
"digest_format = {enum = [sha256_base32, sha256_hex, blake2_base32, blake2s_base32]};\n"
"digests = {type = string};\n"
"manifests = {type = string};\n"
Expand Down
2 changes: 1 addition & 1 deletion scripts/completion/_pkg.in
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ _pkg_args() {
'(-q --quiet)'{-q,--quiet}'[force quiet output]' \
'(-v --verbose)'{-v,--verbose}'[be verbose]' \
'(-n --no-clobber)'{-n,--no-clobber}"[don't overwrite existing packages]" \
'(-f --format)'{-f+,--format=}'[specify package output format]:format:(tar tgz tbz txz)' \
'(-f --format)'{-f+,--format=}'[specify package output format]:format:(tar tgz tbz txz tzst)' \
'(-o --out-dir)'{-o+,--out-dir=}'[output directory]:outdir:_files -/' \
'(-r --root-dir)'{-r+,--root-dir=}'[specify root directory]:rootdir:_files -/' \
- '(manifest)' \
Expand Down
9 changes: 7 additions & 2 deletions src/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
}

switch (fmt) {
case TZS:
format = "tzst";
break;
case TXZ:
format = "txz";
break;
Expand Down Expand Up @@ -180,7 +183,7 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
/*
* options:
* -M: manifest file
* -f <format>: format could be txz, tgz, tbz or tar
* -f <format>: format could be tzst, txz, tgz, tbz or tar
* -g: globbing
* -h: pkg name with hash and symlink
* -m: path to dir where to find the metadata
Expand Down Expand Up @@ -299,7 +302,9 @@ exec_create(int argc, char **argv)
} else {
if (format[0] == '.')
++format;
if (strcmp(format, "txz") == 0)
if (strcmp(format, "tzst") == 0)
fmt = TZS;
else if (strcmp(format, "txz") == 0)
fmt = TXZ;
else if (strcmp(format, "tbz") == 0)
fmt = TBZ;
Expand Down

0 comments on commit d34c8d9

Please sign in to comment.