34 Commits
Author SHA1 Message Date
ahp 2644912cf8 docs: add x(1) and c(1) man pages
Each page covers synopsis, options, supported formats or extensions,
safety and placement rules (x) or compression profiles and refusals (c),
the progress display, exit statuses, environment and examples. c.1
renders its profile table with tbl.

make install now installs them to $(PREFIX)/share/man/man1 (MANDIR is
overridable), and make uninstall removes them.
2026-11-05 14:46:41 +03:30
ahp 5872e82715 packaging: move the AUR package out of the repository
The PKGBUILD now lives in its own AUR clone, next to the other AUR
packages, like those of the other own projects (prx, lazyntfy). It
builds from the server's tag tarball with a pinned sha256 instead of
a git source with SKIP.

Remove packaging/aur, the srcinfo Makefile target and the makepkg
ignore rules, and shorten the README section to a pointer to the AUR
package.
2026-11-05 14:46:40 +03:30
ahp 2a1b6e9987 docs: document the Arch package and AUR publishing
Describe what the package builds and installs, how to build it locally
with makepkg, and how to publish a release: tag it, regenerate
.SRCINFO, and push PKGBUILD and .SRCINFO to the AUR repository.
v1.0.0
2026-11-05 14:34:01 +03:30
ahp c5539ceedd build: add srcinfo target
make srcinfo regenerates packaging/aur/.SRCINFO from the PKGBUILD,
which the AUR requires to match on every push.
2026-11-05 14:34:00 +03:30
ahp 457471a23c packaging: add AUR package
The PKGBUILD builds from the release tag (git+URL#tag=v$pkgver) and
follows the Arch Go package guidelines:
- PIE binaries, externally linked with makepkg's flags;
- -trimpath and a read-only module graph, with a module cache in
  $srcdir;
- GOTOOLCHAIN=local, so makepkg never downloads a toolchain.

It stamps the version from pkgver, runs the test suite in check()
(-short skips the pseudo-terminal tests), and installs x, c and the
docs. .SRCINFO is generated from it.

libarchive is a dependency because x extracts most formats with bsdtar.
7zip, zip and the compressors are optional dependencies, each described
by the formats it enables. namcap's "libarchive may not be needed" is
expected: bsdtar is executed, not linked.

makepkg's output in packaging/aur (src/, pkg/, the source clone and
packages) is ignored.
2026-11-05 14:34:00 +03:30
ahp fd14d6dc11 docs: add design notes
Records the reasoning: the flaws of the old Oh My Zsh extract, the move
from Bash to Go, backend choices, staging and placement, --force
semantics, profiles, exclusion, the progress display and the testing
approach.
2026-11-05 14:28:15 +03:30
ahp ed3f2c598b docs: add README
Covers usage, supported formats and backends, dependencies, safety
behavior, the progress display, exit statuses, known limitations and
testing.
2026-11-05 14:28:14 +03:30
ahp 06a2f4f67d build: add Makefile
make check runs gofmt, go vet, staticcheck when installed, and all
tests. make install builds static, trimpath binaries and installs them
to ~/.local/bin (PREFIX and DESTDIR are honored).
2026-11-05 14:28:14 +03:30
ahp 052e3392b9 tests: cover c end to end
Every type and profile is created and then checked with the format's
own tools, independently of x, and round-tripped through x. Tests also
cover naming, symlink inputs, refusals, backend failures, missing
dependencies, and exclusion behaving the same across tar, zip and 7z.
2026-11-05 14:28:14 +03:30
ahp d77e82cf67 tests: cover x end to end
Tests cover:
- every format round trip;
- the placement rule, conflicts and --force merges;
- validation before extraction;
- corrupt archives and missing dependencies;
- every crafted escape;
- invocation from zsh;
- the progress display on a real pseudo-terminal, including -q and
  NO_COLOR.
2026-11-05 14:28:14 +03:30
ahp cc5b3a6ed7 tests: generate RPM, CAB, RAR, .Z and malicious fixtures
Formats that no common tool creates are written byte by byte: a minimal
RPM with a cpio payload, an uncompressed cabinet, a stored RAR 4
archive and a literal-code LZW stream. Path-traversal, absolute-path,
symlink and hard-link escapes are built with archive/tar and
archive/zip. No binary fixtures are stored.
2026-11-05 14:28:13 +03:30
ahp 9b5a07ce9c tests: add end-to-end harness
TestMain builds x and c once. Each test gets its own directory, with
HOME redirected, so real files are never touched. Helpers cover:
- running the binaries and asserting status, stdout and stderr;
- comparing trees by type, content and symlink target;
- a tree of awkward names;
- a PATH that hides chosen programs, to simulate missing dependencies.
2026-11-05 14:28:13 +03:30
ahp 534a958e57 create: test type resolution, profiles and backend arguments
Tests pin:
- every compressor's arguments for every profile;
- the zip and 7z levels;
- the full tar, zip and 7z command lines, including names that start
  with "-";
- the exclude pattern translation and type-resolution errors.
2026-11-05 14:28:13 +03:30
ahp 5b1d055398 c: add command entry point 2026-11-05 14:28:13 +03:30
ahp 3707956e27 create: build archives atomically with validated inputs
- The type comes from --type or the extension; a contradiction is an
  error, and the output is never renamed.
- Each input is stored under its own resolved name.
- An existing output, an output inside an input, the output as an
  input, duplicate names and the root directory are refused before
  any work.
- Backends: GNU tar piped into the compressor, Info-ZIP zip once per
  input, and 7-Zip.
- --exclude matches names at any depth, translated so the three
  backends behave alike.
- The archive is built beside the output and renamed into place only
  when complete.
2026-11-05 14:28:12 +03:30
ahp d85535eaa2 create: define archive types and compression profiles
The types are tar, tar.gz, tar.bz2, tar.xz, tar.zst, zip and 7z,
detected from case-insensitive suffixes. --fast, default and --best map
to each tool's own levels; "best" is the highest standard level, never
a memory-hungry mode (zstd --ultra, xz -e). xz and zstd use all cores.
2026-11-05 14:28:12 +03:30
ahp d46e5b05d7 extract: test detection, backend arguments and UDF probing
Tests cover:
- the suffix table, including stems and lookalikes that must not
  match;
- UDF detection on synthetic images;
- the exact argument vector of every backend;
- the .deb payload pattern and the "contains the source archive" guard.
2026-11-05 14:28:12 +03:30
ahp ec689eec3a x: add command entry point 2026-11-05 14:28:11 +03:30
ahp 382a756e8b extract: extract through staging with safe placement
- Every input, the destination and the needed backends 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 corrupt, unsafe or interrupted archives leave nothing
  behind.
- Placement: one top-level entry lands as itself, several land in a
  directory named after the archive.
- Existing paths are never touched without --force, which merges, and
  never touches the source archive.
- bsdtar runs with its secure defaults and without restoring
  ownership. A .deb yields its data.tar payload, like dpkg-deb -x.
- The live progress display is shown on a terminal at normal
  verbosity.
2026-11-05 14:28:11 +03:30
ahp 60cd29b38f extract: detect formats and UDF images
Formats are recognized by case-insensitive suffix, most specific first,
and the stem is kept for naming output.

Each format maps to one backend: bsdtar for tar, zip, cab, cpio, deb,
rpm and ISO 9660; 7-Zip for 7z, RAR and ISO images that carry UDF;
the reference decompressors for single files. UDF is detected from the
volume recognition sequence, because UDF-only images (Windows media)
would otherwise yield only their ISO 9660 README.
2026-11-05 14:28:10 +03:30
ahp 280c24183c progress: test rendering, sampling and terminal handling
Tests use a fake terminal and an injected clock and /proc readers.

- Rendering: layout, gradient endpoints, bar width limits, truncation,
  plain output without color, and the unknown-total and overshoot
  states.
- Behavior: speed smoothing, accumulation across processes, the show
  delay, erase sequences, messages printed above the display, and both
  kinds of prompt.
2026-11-05 14:28:10 +03:30
ahp a9990b2a84 progress: monitor backend reads and redraw in place
Progress is the bytes a backend process has read (rchar in
/proc/PID/io), so every backend works unchanged; reads of successive
processes add up. Speed is smoothed with an exponential moving average.

- The display redraws every 80 ms, appears only after 250 ms, and
  erases itself completely when stopped.
- Backend output goes through Writer, which prints whole lines above
  the display.
- An unterminated line that stays put, or a backend opening /dev/tty,
  is treated as a password prompt and stops the drawing.
2026-11-05 14:28:10 +03:30
ahp 35a151386d progress: render zap-style progress frames
A frame has three lines, in the style of github.com/programmersd21/zap:
- an operation badge, a braille spinner and the item;
- a bar blending Catppuccin blue to mauve over a dark track;
- a data / speed / ETA line, or "finishing…" once all input is read.

Rendering is a pure function of the frame. It falls back to plain text
without color, and truncates so no line wraps on narrow terminals.
2026-11-05 14:28:09 +03:30
ahp 44bc47673d fsx: test rename, merge and removal edge cases
Tests cover:
- an existing file or an empty directory blocks a no-replace rename;
- a read-only directory moves and keeps its mode;
- merges keep unrelated files and refuse type changes;
- a merge refuses to write through a destination symlink;
- removal of an unreadable tree leaves a symlink target's mode
  untouched.
2026-11-05 14:28:09 +03:30
ahp ecb7aa5d52 fsx: add atomic no-replace rename, merge and removal
- RenameNoReplace uses renameat2(RENAME_NOREPLACE), so the existence
  check and the rename are one atomic step; it falls back to
  check-then-rename where the flag is unsupported.
- Move renames read-only directories, as found in ISO images, by
  granting u+w for the rename and restoring the full mode afterwards.
- Merge implements --force: files replace files, directories merge,
  a file never replaces a directory or the reverse, and symlinks in
  the destination are never followed.
- RemoveAll makes read-only trees removable without following symlinks.
2026-11-05 14:28:09 +03:30
ahp 69408e0f6a proc: test pipelines, failures and cancellation
Tests cover data flowing through two stages, the rightmost failure
winning, a missing program, the working directory, and a cancelled
pipeline stopping within seconds instead of waiting for its stages.
2026-11-05 14:28:09 +03:30
ahp 6f653a030f proc: run backend pipelines without a shell
Commands are argument vectors passed straight to exec, so file names
are never quoted or evaluated.

- Pipelines connect each stdout to the next stdin and, like a shell
  with pipefail, fail if any stage fails, reporting the rightmost
  failure ("tar exited with status 2").
- Cancelling the context sends SIGTERM, then kills after five seconds.
- PipelineIO takes explicit streams and reports the process IDs once
  every stage has started.
2026-11-05 14:28:08 +03:30
ahp 1c9a69d362 cli: test option parsing
Table tests cover:
- bundles, including one that ends in a value option;
- attached and empty values, values that look like options;
- permutation, "--" and a lone "-";
- every usage error message.
2026-11-05 14:28:08 +03:30
ahp dcf8ecb70f cli: add GNU-style option parser
Options may follow operands, "--" ends them, short flags bundle (-qv),
and values may be separate, attached (-dDIR) or given with "=". Long
options are never abbreviated, so parsing stays predictable. Options
are returned in command-line order so that "last one wins" is natural.
2026-11-05 14:28:08 +03:30
ahp e7d1ef2c43 cli: add exit statuses, error reporting and signal-aware main
- x and c share these exit statuses: 1 failure, 2 usage, 3 bad input,
  4 missing dependency.
- Error carries a status; usage errors add a hint to use --help.
- Problems reports every validation error before exiting with the
  status of the first, so users can fix everything in one go.
- Main turns SIGINT, SIGTERM and SIGHUP into context cancellation.
  Commands can then stop their backend and clean up; the process exits
  with 128 + the signal number, and a second signal kills at once.
2026-11-05 14:28:08 +03:30
ahp a8b6a9b30a cli: add logger with terminal-aware color
Diagnostics are printed as "prog: message" on stderr, at three levels:
quiet (errors only), normal and verbose. Warnings and errors are
colored only when stderr is a terminal, NO_COLOR is unset and TERM is
not "dumb"; the terminal check uses the TCGETS ioctl instead of
guessing from the file mode.
2026-11-05 14:28:07 +03:30
ahp 0deb27fd13 chore: ignore build output
make build writes the x and c binaries to build/.
2026-11-05 14:28:07 +03:30
ahp c257b0e40a chore: release into the public domain
Use the Unlicense, as the dotfiles repository does.
2026-11-05 14:28:06 +03:30
ahp 8656bab274 build: initialize Go module
Module src.panahifar.ir/ahp/archive-utils, Go 1.26. The only dependency
is golang.org/x/sys, for renameat2(2) and terminal ioctls that the
standard library does not expose.
2026-11-05 14:28:03 +03:30