me

/

vpac Public
36 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

fix: use the alpm iterator for mtree verification

diviocity committed last Nov 11 · cf008b8a4fdbf8c589ddb8ce0e2f882b9831e19e View patch
Unverified signature 1 files changed +6 -32
src/verify_full.v +6 -32

@@ -20,12 +20,6 @@ fn C.archive_entry_size(entry &C.Archive_entry) i64

2020fn C.archive_entry_symlink(entry &C.Archive_entry) &char

2121fn C.archive_entry_digest(entry &C.Archive_entry, kind int) &u8

2222

23-// the binding's mtree_next hands the entry to its own parameter, so the

24-// caller never sees it: libalpm is called directly

25-fn C.alpm_pkg_mtree_next(pkg &alpm.Package, archive &C.Archive, entry &&C.Archive_entry) int

26-

27-fn C.archive_error_string(archive &C.Archive) &char

28-

2923const ae_ifmt = u32(0o170000)

3024const ae_ifreg = u32(0o100000)

3125const ae_ifdir = u32(0o040000)

@@ -73,21 +67,14 @@ fn mtree_entries(pkg &alpm.Package) !([]MtreeEntry, bool) {

7367 mut out := []MtreeEntry{}

7468 mut entry := &C.Archive_entry(unsafe { nil })

7569 for {

76- ret := C.alpm_pkg_mtree_next(pkg, archive, &entry)

77- if ret != 0 {

78- if ret != 1 {

79- // the read's reason is libarchive's, kept on the archive:

80- // libalpm passes the status through and sets no error of its

81- // own. it is taken before the close frees the archive, and a

82- // close that fails too rides along rather than going unsaid

83- read_err := error('reading the mtree failed: ${mtree_reason(pkg, archive)}')

84- pkg.mtree_close(archive) or {

85- return error('${read_err.msg()} (closing it failed too: ${err.msg()})')

86- }

87- return read_err

70+ more := pkg.mtree_step(archive, &entry) or {

71+ read_err := error('reading the mtree failed: ${err.msg()}')

72+ pkg.mtree_close(archive) or {

73+ return error('${read_err.msg()} (closing it failed too: ${err.msg()})')

8874 }

89- break

75+ return read_err

9076 }

77+ if !more { break }

9178 mut path := unsafe { cstring_to_vstring(C.archive_entry_pathname(entry)) }

9279 if path.starts_with('./') {

9380 path = path[2..]

@@ -112,19 +99,6 @@ fn mtree_entries(pkg &alpm.Package) !([]MtreeEntry, bool) {

11299 return out, true

113100}

114101

115-// mtree_reason is why an mtree read stopped: libarchive's message on the

116-// archive, or libalpm's error when libarchive kept none

117-fn mtree_reason(pkg &alpm.Package, archive &C.Archive) string {

118- msg := C.archive_error_string(archive)

119- if msg != unsafe { nil } {

120- text := unsafe { cstring_to_vstring(msg) }

121- if text != '' {

122- return text

123- }

124- }

125- return pkg.get_handle().error().msg()

126-}

127-

128102// digest_hex is a 32 byte sha256 digest as hex, empty when it is all zero:

129103// libarchive leaves it so when the mtree records none

130104fn digest_hex(d &u8) string {