From cf008b8a4fdbf8c589ddb8ce0e2f882b9831e19e Mon Sep 17 00:00:00 2001 From: diviocity Date: Wed, 11 Nov 2026 05:48:56 +0100 Subject: [PATCH] fix: use the alpm iterator for mtree verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Read entries and EOF through Package.mtree_step, preserving truncated-mtree diagnostics and close errors. This removes verify mode’s direct libalpm iterator call while the native backend is developed. Validated with v -check ., all 27 src test binaries, both vmakepkg test binaries, and the 14-test alpm suite. Requires alpm.v b88a116 or later. Resolves #3. --- src/verify_full.v | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/verify_full.v b/src/verify_full.v index abca18c..a1de3a6 100644 --- a/src/verify_full.v +++ b/src/verify_full.v @@ -20,12 +20,6 @@ fn C.archive_entry_size(entry &C.Archive_entry) i64 fn C.archive_entry_symlink(entry &C.Archive_entry) &char fn C.archive_entry_digest(entry &C.Archive_entry, kind int) &u8 -// the binding's mtree_next hands the entry to its own parameter, so the -// caller never sees it: libalpm is called directly -fn C.alpm_pkg_mtree_next(pkg &alpm.Package, archive &C.Archive, entry &&C.Archive_entry) int - -fn C.archive_error_string(archive &C.Archive) &char - const ae_ifmt = u32(0o170000) const ae_ifreg = u32(0o100000) const ae_ifdir = u32(0o040000) @@ -73,21 +67,14 @@ fn mtree_entries(pkg &alpm.Package) !([]MtreeEntry, bool) { mut out := []MtreeEntry{} mut entry := &C.Archive_entry(unsafe { nil }) for { - ret := C.alpm_pkg_mtree_next(pkg, archive, &entry) - if ret != 0 { - if ret != 1 { - // the read's reason is libarchive's, kept on the archive: - // libalpm passes the status through and sets no error of its - // own. it is taken before the close frees the archive, and a - // close that fails too rides along rather than going unsaid - read_err := error('reading the mtree failed: ${mtree_reason(pkg, archive)}') - pkg.mtree_close(archive) or { - return error('${read_err.msg()} (closing it failed too: ${err.msg()})') - } - return read_err + more := pkg.mtree_step(archive, &entry) or { + read_err := error('reading the mtree failed: ${err.msg()}') + pkg.mtree_close(archive) or { + return error('${read_err.msg()} (closing it failed too: ${err.msg()})') } - break + return read_err } + if !more { break } mut path := unsafe { cstring_to_vstring(C.archive_entry_pathname(entry)) } if path.starts_with('./') { path = path[2..] @@ -112,19 +99,6 @@ fn mtree_entries(pkg &alpm.Package) !([]MtreeEntry, bool) { return out, true } -// mtree_reason is why an mtree read stopped: libarchive's message on the -// archive, or libalpm's error when libarchive kept none -fn mtree_reason(pkg &alpm.Package, archive &C.Archive) string { - msg := C.archive_error_string(archive) - if msg != unsafe { nil } { - text := unsafe { cstring_to_vstring(msg) } - if text != '' { - return text - } - } - return pkg.get_handle().error().msg() -} - // digest_hex is a 32 byte sha256 digest as hex, empty when it is all zero: // libarchive leaves it so when the mtree records none fn digest_hex(d &u8) string { -- 2.56.1