Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2644912cf8
|
||
|
|
5872e82715
|
No files matched your search
@@ -1,4 +1 @@
|
||||
build/
|
||||
# makepkg output in packaging/aur
|
||||
packaging/aur/*/
|
||||
packaging/aur/*.pkg.tar.*
|
||||
@@ -1,11 +1,12 @@
|
||||
PREFIX ?= $(HOME)/.local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
MANDIR ?= $(PREFIX)/share/man
|
||||
GO ?= go
|
||||
|
||||
# Static, reproducible binaries: no cgo, no local paths embedded.
|
||||
BUILD = CGO_ENABLED=0 $(GO) build -trimpath
|
||||
|
||||
.PHONY: all build check test lint install uninstall clean srcinfo
|
||||
.PHONY: all build check test lint install uninstall clean
|
||||
|
||||
all: build
|
||||
|
||||
@@ -28,13 +29,12 @@ lint:
|
||||
install: build
|
||||
install -d '$(DESTDIR)$(BINDIR)'
|
||||
install -m 755 build/x build/c '$(DESTDIR)$(BINDIR)/'
|
||||
install -d '$(DESTDIR)$(MANDIR)/man1'
|
||||
install -m 644 man/x.1 man/c.1 '$(DESTDIR)$(MANDIR)/man1/'
|
||||
|
||||
uninstall:
|
||||
rm -f '$(DESTDIR)$(BINDIR)/x' '$(DESTDIR)$(BINDIR)/c'
|
||||
rm -f '$(DESTDIR)$(MANDIR)/man1/x.1' '$(DESTDIR)$(MANDIR)/man1/c.1'
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
||||
# Regenerate the AUR metadata after editing packaging/aur/PKGBUILD.
|
||||
srcinfo:
|
||||
cd packaging/aur && makepkg --printsrcinfo > .SRCINFO
|
||||
@@ -103,7 +103,7 @@ code itself.
|
||||
|
||||
```sh
|
||||
make check # gofmt, go vet, staticcheck (if installed), all tests
|
||||
make install # builds static binaries and installs them to ~/.local/bin
|
||||
make install # static binaries to ~/.local/bin, man pages to ~/.local/share/man
|
||||
make uninstall
|
||||
```
|
||||
|
||||
@@ -111,35 +111,11 @@ Use `make install PREFIX=/usr/local` (as root) for a system-wide install.
|
||||
|
||||
### Arch Linux package
|
||||
|
||||
`packaging/aur/PKGBUILD` builds a package that follows the Arch Go package
|
||||
guidelines:
|
||||
|
||||
- the binaries are PIE and externally linked with makepkg's flags;
|
||||
- they are built with `-trimpath` and a read-only module graph;
|
||||
- `check()` runs the tests;
|
||||
- the version is stamped from `pkgver`.
|
||||
|
||||
The package installs `/usr/bin/x`, `/usr/bin/c` and the docs. It depends on
|
||||
`libarchive` and lists the other backends as optional dependencies.
|
||||
|
||||
To build and install from the release tag:
|
||||
|
||||
```sh
|
||||
cd packaging/aur && makepkg -si
|
||||
```
|
||||
|
||||
To publish a release to the AUR (package name `archive-utils`):
|
||||
|
||||
```sh
|
||||
git tag v1.0.0 && git push origin v1.0.0 # the PKGBUILD builds from this tag
|
||||
make srcinfo # after any PKGBUILD change
|
||||
git clone ssh://aur@aur.archlinux.org/archive-utils.git ~/aur/archive-utils
|
||||
cp packaging/aur/PKGBUILD packaging/aur/.SRCINFO ~/aur/archive-utils/
|
||||
cd ~/aur/archive-utils
|
||||
git add PKGBUILD .SRCINFO && git commit -m "Update to 1.0.0" && git push
|
||||
```
|
||||
|
||||
For a later release, update `pkgver`, reset `pkgrel=1`, tag, and repeat.
|
||||
An AUR package, `archive-utils`, is maintained separately from this
|
||||
repository. It builds from the release tags and follows the Arch Go package
|
||||
guidelines: PIE binaries, makepkg's flags, `-trimpath`, and the tests in
|
||||
`check()`. It installs `/usr/bin/x`, `/usr/bin/c` and the docs, depends on
|
||||
`libarchive`, and lists the other backends as optional dependencies.
|
||||
|
||||
> **Oh My Zsh users:** the `extract` plugin defines `alias x=extract`, and an
|
||||
> alias takes precedence over `~/.local/bin/x` in interactive zsh. Remove
|
||||
@@ -358,11 +334,11 @@ exit status is 1.
|
||||
|
||||
```
|
||||
cmd/x, cmd/c entry points (one line each)
|
||||
man/ x(1) and c(1) manual pages
|
||||
internal/cli GNU-style option parser, logger, exit codes, signal-aware main
|
||||
internal/proc runs backend pipelines (pipefail semantics; SIGTERM on cancel)
|
||||
internal/fsx no-replace rename, read-only-safe move, merge and removal
|
||||
internal/progress zap-style live display: renderer and backend monitor
|
||||
packaging/aur PKGBUILD and .SRCINFO for the AUR
|
||||
internal/extract x: format detection, UDF probe, backends, staging and placement
|
||||
internal/create c: types, profiles, validation, backends
|
||||
tests/ end-to-end tests: build both binaries, run real archives
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
'\" t
|
||||
.TH C 1 2026-11-05 "archive-utils 1.0.0" "User Commands"
|
||||
.SH NAME
|
||||
c \- create archives with a consistent interface
|
||||
.SH SYNOPSIS
|
||||
.B c
|
||||
.RI [ options ]
|
||||
.I output
|
||||
.I input
|
||||
.RI [ input ...]
|
||||
.SH DESCRIPTION
|
||||
.B c
|
||||
creates an archive with GNU
|
||||
.BR tar ,
|
||||
Info-ZIP
|
||||
.B zip
|
||||
or 7-Zip.
|
||||
The type comes from the extension of
|
||||
.IR output ,
|
||||
or from
|
||||
.BR \-\-type ;
|
||||
an unknown extension without
|
||||
.B \-\-type
|
||||
is an error, and
|
||||
.I output
|
||||
is never renamed.
|
||||
.PP
|
||||
Each input is stored under its own name, the last component of its resolved
|
||||
path, wherever it lives.
|
||||
A symlink given as an input is followed; symlinks inside directories are
|
||||
stored as links.
|
||||
Inputs and the output are validated before anything is written.
|
||||
The archive is built beside the output and renamed into place only when
|
||||
complete, so a failed run never leaves a partial archive.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BR \-t ", " \-\-type " \fITYPE\fR"
|
||||
Archive type:
|
||||
.BR tar ", " tar.gz ", " tar.bz2 ", " tar.xz ", " tar.zst ", " zip ", " 7z .
|
||||
.TP
|
||||
.BR \-f ", " \-\-fast
|
||||
Favour speed over size.
|
||||
.TP
|
||||
.BR \-b ", " \-\-best
|
||||
Favour size over speed (each tool's highest standard level).
|
||||
.TP
|
||||
.BR \-q ", " \-\-quiet
|
||||
Print errors only.
|
||||
.TP
|
||||
.BR \-v ", " \-\-verbose
|
||||
List archived entries.
|
||||
.TP
|
||||
.B \-\-force
|
||||
Replace an existing output file.
|
||||
.TP
|
||||
.BI \-\-exclude " NAME"
|
||||
Skip files and directories whose name matches the shell glob
|
||||
.I NAME
|
||||
at any depth. Repeatable. Patterns containing
|
||||
.B /
|
||||
are rejected.
|
||||
.TP
|
||||
.BR \-h ", " \-\-help
|
||||
Show help and exit.
|
||||
.TP
|
||||
.B \-\-version
|
||||
Show the version and exit.
|
||||
.PP
|
||||
If both
|
||||
.B \-\-fast
|
||||
and
|
||||
.B \-\-best
|
||||
are given, the last one wins.
|
||||
.SH EXTENSIONS
|
||||
\&.tar, .tar.gz, .tgz, .tar.bz2, .tbz2, .tbz, .tar.xz, .txz, .tar.zst, .tzst,
|
||||
\&.zip, .7z (case-insensitive)
|
||||
.SH PROFILES
|
||||
.TS
|
||||
l l l l.
|
||||
Type \-\-fast default \-\-best
|
||||
tar.gz gzip \-1 \-6 \-9
|
||||
tar.bz2 bzip2 \-1 \-9 \-9
|
||||
tar.xz xz \-T0 \-1 \-6 \-9
|
||||
tar.zst zstd \-T0 \-1 \-3 \-19
|
||||
zip \-1 \-6 \-9
|
||||
7z \-mx=1 \-mx=5 \-mx=9
|
||||
.TE
|
||||
.PP
|
||||
Memory-hungry modes
|
||||
.RB ( "zstd \-\-ultra" ", " "xz \-e" )
|
||||
are never used.
|
||||
.SH REFUSALS
|
||||
.B c
|
||||
refuses an existing output (without
|
||||
.BR \-\-force ),
|
||||
an output that is a directory, an output inside one of the inputs, an
|
||||
output that is also an input, a missing output directory, two inputs with
|
||||
the same name, and
|
||||
.B /
|
||||
as an input.
|
||||
.SH PROGRESS
|
||||
On a terminal at least 40 columns wide, and only at normal verbosity, a live
|
||||
progress display appears after 250 ms and is erased when the archive is done.
|
||||
It shows
|
||||
.B finishing\&...
|
||||
once all input has been read but the backend is still compressing.
|
||||
.SH EXIT STATUS
|
||||
.TP
|
||||
.B 0
|
||||
Success.
|
||||
.TP
|
||||
.B 1
|
||||
Creation failed, or the output already exists.
|
||||
.TP
|
||||
.B 2
|
||||
Usage error.
|
||||
.TP
|
||||
.B 3
|
||||
Missing or unreadable input, or an invalid output path.
|
||||
.TP
|
||||
.B 4
|
||||
A required program is not installed.
|
||||
.TP
|
||||
.B 128+n
|
||||
Interrupted by signal
|
||||
.IR n ,
|
||||
after cleaning up.
|
||||
.SH ENVIRONMENT
|
||||
.TP
|
||||
.B NO_COLOR
|
||||
If set and not empty, disables color.
|
||||
.TP
|
||||
.B TERM
|
||||
Color and the progress display are off when unset or
|
||||
.BR dumb .
|
||||
.SH EXAMPLES
|
||||
.EX
|
||||
c backup.tar.zst ./project
|
||||
c -b backup.tar.xz ./project
|
||||
c --exclude node_modules --exclude \(aq*.o\(aq src.zip ./src
|
||||
c -t zip release.pkg ./dist
|
||||
.EE
|
||||
.SH SEE ALSO
|
||||
.BR x (1),
|
||||
.BR tar (1),
|
||||
.BR zip (1),
|
||||
.BR 7z (1)
|
||||
@@ -0,0 +1,137 @@
|
||||
.TH X 1 2026-11-05 "archive-utils 1.0.0" "User Commands"
|
||||
.SH NAME
|
||||
x \- extract archives and compressed files safely
|
||||
.SH SYNOPSIS
|
||||
.B x
|
||||
.RI [ options ]
|
||||
.I archive
|
||||
.RI [ archive ...]
|
||||
.SH DESCRIPTION
|
||||
.B x
|
||||
extracts archives and compressed files through established tools
|
||||
.RB ( bsdtar ,
|
||||
7-Zip and the standard decompressors).
|
||||
Every input and the destination are validated before anything is extracted.
|
||||
Each archive is extracted into a private staging directory inside the
|
||||
destination and moved into place only after the backend succeeds, so a
|
||||
corrupt, unsafe or interrupted extraction leaves nothing behind.
|
||||
Source archives are never modified or removed.
|
||||
.PP
|
||||
Results are placed by one rule for every format:
|
||||
.TP
|
||||
one top-level entry
|
||||
.IR DEST / entry
|
||||
.TP
|
||||
several top-level entries
|
||||
.IR DEST / name /,
|
||||
where
|
||||
.I name
|
||||
is the archive name without its extension
|
||||
.TP
|
||||
no entries
|
||||
nothing is created (a warning is printed)
|
||||
.TP
|
||||
a compressed file \fIname\fR.gz
|
||||
.IR DEST / name
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BR \-d ", " \-\-dest " \fIDIR\fR"
|
||||
Extract into
|
||||
.I DIR
|
||||
(created if missing; default: the current directory).
|
||||
.TP
|
||||
.BR \-f ", " \-\-force
|
||||
Replace existing files and merge into existing directories.
|
||||
A file never replaces a directory or the reverse, symlinks in the
|
||||
destination are never followed, and the source archive is never overwritten.
|
||||
.TP
|
||||
.BR \-k ", " \-\-keep
|
||||
Keep source archives. This is always the case; the option is accepted for habit.
|
||||
.TP
|
||||
.BR \-q ", " \-\-quiet
|
||||
Print errors only.
|
||||
.TP
|
||||
.BR \-v ", " \-\-verbose
|
||||
List extracted entries.
|
||||
.TP
|
||||
.BR \-h ", " \-\-help
|
||||
Show help and exit.
|
||||
.TP
|
||||
.B \-\-version
|
||||
Show the version and exit.
|
||||
.PP
|
||||
Options may follow operands,
|
||||
.B \-\-
|
||||
ends options, short options may be combined
|
||||
.RB ( \-qf ),
|
||||
and values may be attached
|
||||
.RB ( \-dDIR ", " \-\-dest=DIR ).
|
||||
.SH FORMATS
|
||||
.TP
|
||||
.B bsdtar
|
||||
\&.tar, .tar.gz, .tgz, .tar.bz2, .tbz2, .tbz, .tar.xz, .txz, .tar.zst, .tzst,
|
||||
\&.tar.lzma, .zip, .jar, .war, .ear, .cab, .cpio, .iso (ISO 9660),
|
||||
\&.deb (payload only), .rpm (payload only)
|
||||
.TP
|
||||
.B 7-Zip
|
||||
\&.7z, .rar, .iso images that contain a UDF filesystem
|
||||
.TP
|
||||
.BR gzip ", " bzip2 ", " xz ", " zstd
|
||||
\&.gz, .Z, .bz2, .xz, .lzma, .zst
|
||||
.PP
|
||||
Extensions are matched case-insensitively.
|
||||
A missing backend is reported by name.
|
||||
.SH SAFETY
|
||||
bsdtar refuses entries containing
|
||||
.BR .. ,
|
||||
including hard-link targets, refuses to extract through symlinks, and strips
|
||||
a leading
|
||||
.BR / .
|
||||
7-Zip rewrites such paths so that entries stay inside the output directory.
|
||||
Ownership recorded in archives is ignored.
|
||||
.SH PROGRESS
|
||||
On a terminal at least 40 columns wide, and only at normal verbosity, a live
|
||||
progress display (bar, data, speed, ETA) appears after 250 ms and is erased
|
||||
when the extraction ends.
|
||||
Set
|
||||
.B NO_COLOR
|
||||
to draw it without color.
|
||||
.SH EXIT STATUS
|
||||
.TP
|
||||
.B 0
|
||||
Success.
|
||||
.TP
|
||||
.B 1
|
||||
An extraction failed, or a result would overwrite an existing path.
|
||||
.TP
|
||||
.B 2
|
||||
Usage error.
|
||||
.TP
|
||||
.B 3
|
||||
Missing, unreadable or unsupported input, or an invalid destination.
|
||||
.TP
|
||||
.B 4
|
||||
A required program is not installed.
|
||||
.TP
|
||||
.B 128+n
|
||||
Interrupted by signal
|
||||
.IR n ,
|
||||
after cleaning up.
|
||||
.SH ENVIRONMENT
|
||||
.TP
|
||||
.B NO_COLOR
|
||||
If set and not empty, disables color.
|
||||
.TP
|
||||
.B TERM
|
||||
Color and the progress display are off when unset or
|
||||
.BR dumb .
|
||||
.SH EXAMPLES
|
||||
.EX
|
||||
x project-1.0.tar.gz # -> ./project-1.0/
|
||||
x -d /tmp/out a.zip b.7z # both into /tmp/out
|
||||
x -f update.tar.zst # merge into an existing tree
|
||||
.EE
|
||||
.SH SEE ALSO
|
||||
.BR c (1),
|
||||
.BR bsdtar (1),
|
||||
.BR 7z (1)
|
||||
@@ -1,27 +0,0 @@
|
||||
pkgbase = archive-utils
|
||||
pkgdesc = Safe, predictable archive extractor (x) and creator (c) built on bsdtar, GNU tar, 7-Zip and zip
|
||||
pkgver = 1.0.0
|
||||
pkgrel = 1
|
||||
url = https://src.panahifar.ir/ahp/archive-utils
|
||||
arch = x86_64
|
||||
arch = aarch64
|
||||
license = Unlicense
|
||||
checkdepends = 7zip
|
||||
checkdepends = binutils
|
||||
checkdepends = unzip
|
||||
checkdepends = zip
|
||||
makedepends = git
|
||||
makedepends = go
|
||||
depends = glibc
|
||||
depends = libarchive
|
||||
optdepends = 7zip: x for 7z, RAR and UDF ISO images; c for 7z
|
||||
optdepends = zip: c for zip
|
||||
optdepends = tar: c for tar archives (GNU tar)
|
||||
optdepends = gzip: x for .gz and .Z; c for tar.gz
|
||||
optdepends = bzip2: x for .bz2; c for tar.bz2
|
||||
optdepends = xz: x for .xz and .lzma; c for tar.xz
|
||||
optdepends = zstd: x for .zst; c for tar.zst
|
||||
source = git+https://src.panahifar.ir/ahp/archive-utils.git#tag=v1.0.0
|
||||
sha256sums = SKIP
|
||||
|
||||
pkgname = archive-utils
|
||||
@@ -1,63 +0,0 @@
|
||||
# Maintainer: Amir Husayn Panahifar <ahp at panahifar dot ir>
|
||||
|
||||
pkgname=archive-utils
|
||||
pkgver=1.0.0
|
||||
pkgrel=1
|
||||
pkgdesc='Safe, predictable archive extractor (x) and creator (c) built on bsdtar, GNU tar, 7-Zip and zip'
|
||||
arch=('x86_64' 'aarch64')
|
||||
url='https://src.panahifar.ir/ahp/archive-utils'
|
||||
license=('Unlicense')
|
||||
depends=(
|
||||
'glibc'
|
||||
'libarchive' # bsdtar: x extracts most formats with it
|
||||
)
|
||||
makedepends=('git' 'go')
|
||||
checkdepends=('7zip' 'binutils' 'unzip' 'zip')
|
||||
optdepends=(
|
||||
'7zip: x for 7z, RAR and UDF ISO images; c for 7z'
|
||||
'zip: c for zip'
|
||||
'tar: c for tar archives (GNU tar)'
|
||||
'gzip: x for .gz and .Z; c for tar.gz'
|
||||
'bzip2: x for .bz2; c for tar.bz2'
|
||||
'xz: x for .xz and .lzma; c for tar.xz'
|
||||
'zstd: x for .zst; c for tar.zst'
|
||||
)
|
||||
source=("git+$url.git#tag=v$pkgver")
|
||||
sha256sums=('SKIP')
|
||||
|
||||
# Go settings from the Arch Go package guidelines: PIE, external linking
|
||||
# with makepkg's flags, reproducible paths, a read-only module graph, and a
|
||||
# module cache inside $srcdir that makepkg can clean.
|
||||
_goenv() {
|
||||
export CGO_CPPFLAGS="$CPPFLAGS" CGO_CFLAGS="$CFLAGS" CGO_CXXFLAGS="$CXXFLAGS" CGO_LDFLAGS="$LDFLAGS"
|
||||
export GOFLAGS='-buildmode=pie -trimpath -mod=readonly -modcacherw'
|
||||
export GOPATH="$srcdir/gopath" GOTOOLCHAIN=local
|
||||
}
|
||||
|
||||
prepare() {
|
||||
cd "$pkgname"
|
||||
_goenv
|
||||
go mod download
|
||||
}
|
||||
|
||||
build() {
|
||||
cd "$pkgname"
|
||||
_goenv
|
||||
go build \
|
||||
-ldflags "-linkmode=external -X src.panahifar.ir/ahp/archive-utils/internal/cli.Version=$pkgver" \
|
||||
-o build/ ./cmd/x ./cmd/c
|
||||
}
|
||||
|
||||
check() {
|
||||
cd "$pkgname"
|
||||
_goenv
|
||||
# -short skips the tests that need a pseudo-terminal.
|
||||
go test -short ./...
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$pkgname"
|
||||
install -Dm755 build/x build/c -t "$pkgdir/usr/bin/"
|
||||
install -Dm644 README.md DESIGN.md -t "$pkgdir/usr/share/doc/$pkgname/"
|
||||
# The Unlicense is a common license (/usr/share/licenses/spdx/Unlicense.txt).
|
||||
}
|
||||
Reference in new issue
Block a user