Logo10.3.177.165 
  News  Recent  Stats  Forums  Discord  GitHub  Contact
  Menu
 Username

 Password


   Register here

 Main menu
   BBCode test
 
 Content
   List Content
 
 Projects
   All projects
  View project
[All projects][View on GitHub][Git Log]
Name:Arcedit
Short description:Edit archives (LHA first) on AmigaOS 4 without unpacking them
Full description:

arcedit

Edit archives without unpacking them: rename, delete and add entries, and change their comments (file notes) and protection bits. A standalone command for AmigaOS 4 and Linux, public domain, with no other libraries needed.

FormatDELETERENAMECOMMENTPROTECTADDNew archiveNotes
LHA (.lha, .lzh)yesyesyesyespacked (-lh5-)yesheader levels 0-2, self-extracting
ZIP (.zip)yesyesyesyespacked (Deflate)yesInfo-ZIP Amiga attributes; no ZIP64
TAR (.tar)yesyespax commentowner r w eyesyesustar, GNU long names, pax
TGZ (.tgz, .tar.gz)yesyespax commentowner r w epackedyesunpacked to a temporary tar and packed again
GZIP (.gz)-stored nameyes-replaces the fileyesone file per .gz
LZX (.lzx)not part of a merged groupyesyesyesstored-headers only

The formats are the ones xadmaster.library (the AmigaOS archive reading library) reads; RAR 5 isn't among them. .bz2 and .xz hold one stream without names or other fields, so there's nothing to edit. Every format is written in arcedit's own code. Details per format: docs/formats.md.

How it works

Archives like LHA, ZIP and LZX are lists of members, each a header followed by that file's own packed data. Every member is packed on its own, so (LHA as the example):

  • delete copies the other members byte for byte and leaves the deleted ones out,
  • rename, comment and protection rebuild only the headers of the changed members,
  • add packs only the new files (-lh5-, or stored when that is smaller) and replaces entries with the same name.

Nothing is unpacked and repacked (except TGZ, which is one packed stream). The new archive is written to a temporary file next to the old one (aeXXXXXXXX.tmp, short enough for any file system) and replaces it only when everything worked; the archive keeps its own protection bits and file note. Ctrl-C stops arcedit and leaves the archive as it was. WORKDIR puts the temporary files in another drawer; the new archive is then moved next to the old one (copied when that drawer is on another volume) before it replaces it, so a failure still leaves the archive as it was.

Usage

arcedit ARCHIVE/A,ENTRIES/M,DELETE/S,RENAME/K,AS/K,COMMENT/K,PROTECT/K,ADD/S,TO/K,FROM=LIST/K,INFO/S,WORKDIR/K,QUIET/S
CommandDoes
arcedit Work:a.lha docs readme.txt DELETEDelete entries; a drawer name deletes everything in it
arcedit Work:a.lha DELETE FROM RAM:listDelete the entries listed in a file, one per line
arcedit Work:a.lha RENAME docs/a.txt AS docs/b.txtRename (or move) a file
arcedit Work:a.lha RENAME docs AS DocumentationRename a drawer with everything in it
arcedit Work:a.lha docs/a.txt COMMENT "text"Set the file note ("" clears it)
arcedit Work:a.lha docs/a.txt PROTECT rwedSet the protection bits exactly
arcedit Work:a.lha docs/a.txt PROTECT +s-dAdd or remove protection bits (hsparwed)
arcedit Work:a.lha ADD RAM:x RAM:Drawer TO docsAdd files and drawers (with their contents) below docs
arcedit Work:a.zip INFOShow the format and the operations it allows
arcedit Work:a.lha docs DELETE WORKDIR RAM:Keep the temporary files in RAM: instead of the archive's drawer
  • Entry names are archive paths with / between drawers, matched without regard to case.
  • COMMENT and PROTECT can be given together, and take a list (FROM) like DELETE.
  • ADD creates the archive when it doesn't exist yet (.lha, .lzh, .zip, .tar, .tgz, .tar.gz or .gz name). Added entries keep the file's protection bits, file note and date. Empty drawers get a drawer entry.
  • A rename to a name that's already in the archive is refused.
  • WORKDIR names an existing drawer for the temporary files (the new archive, TGZ's unpacked tar). Free space is then needed there and, for the finished archive, in the archive's own drawer. Without it, or with WORKDIR "", they go to the archive's drawer. INFO ignores it.
  • QUIET prints only errors.

Return codes: 0 done, 5 some entries weren't in the archive (the others were done), 10 nothing was changed (bad arguments, archive error), 20 out of memory.

Using arcedit from other programs

  • arcedit <archive> INFO prints one line: the archive type and the operations this archive allows, e.g. ZIP: DELETE RENAME COMMENT PROTECT ADD. It reads only the archive's first bytes and checks that the archive can be replaced (not delete protected, volume not write protected), so it is fast for any archive size. An archive that can't be changed gives just the type (LHA:).
  • An operation INFO listed can still fail for reasons only that operation shows: a damaged or unsupported archive (ZIP64), not enough free space or memory, an added file over 4 GB, one file out of an LZX merged group. arcedit checks these before writing anything. Then the last line of the output is Error: <message> and the return code is 10 (20 for out of memory); the archive is unchanged.
  • Return code 5 with Warning: lines: some entries weren't in the archive, the others were done.
  • Entry lists for DELETE, COMMENT and PROTECT can be passed in a file (FROM), one entry per line.

Names

Entry names inside archives are Latin-1, as on the Amiga. The Linux build converts UTF-8 names (from the command line, list files and the file system) to Latin-1 for new names, and a UTF-8 name that matches no entry is tried again as Latin-1.

Building

make            # Linux (or other POSIX) build: bin/arcedit
make test       # host tests: results checked with Lhasa, unzip, GNU tar,
                # bsdtar, gzip, unar (lsar) and the small readers in
                # tests/*info.py; LHa for UNIX when it's there (LHAUNIX=)
make os4        # AmigaOS 4 build (bin/os4/arcedit) in the walkero/amigagccondocker image
make fuzz       # damaged archives against an AddressSanitizer/UBSan build
python3 tests/corpus.py DIR   # every edit on real archives in DIR, checked with
                # Lhasa, unzip, GNU tar, gzip and unar (the corpus isn't in
                # the repository: download archives from Aminet / OS4Depot)

Files

FileContents
src/main.cCommand line and the operations
src/arcformat.hInterface of an archive format
src/lhaformat.cLHA backend for that interface
src/lha.c, src/lha.hLHA archive model: headers, reading, writing
src/lh5enc.c-lh5- compressor
src/deflate.cDeflate compressor and decompressor (RFC 1951), CRC-32
src/zipformat.c, src/tarformat.c, src/gzformat.c, src/lzxformat.cThe other format backends
src/platform.cFile system calls (AmigaOS 4 and POSIX for the tests)
docs/lha_format.mdThe LHA header details arcedit relies on
docs/formats.mdHow each format is handled, and its limits
tests/Host tests and sample archives made by LhA 2.15
tests/os4/Scenario tests in an AmigaOS 4 guest (locks, full and write protected volumes, low memory, Ctrl-C)
package/AmigaOS 4 release: readme, Installer script, documentation, icons
tools/make_lha.sh (release archive), make_icons.py + os4/mkicon.c (release icons), os4depot_submit.py (upload a new version to OS4Depot, replacing the published one)
Open Amiga project website, Created in 2008 by Björn Hagström