From b760fb223c25d47eac5e139c9999b0185118b654 Mon Sep 17 00:00:00 2001 From: diviocity Date: Wed, 11 Nov 2026 08:00:49 +0100 Subject: [PATCH] fix: preserve preparation errors when formatting conflicts --- src/frontend_test.v | 20 ++++++++++++++++++++ src/trans.v | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/frontend_test.v b/src/frontend_test.v index 8e628ec..777a40f 100644 --- a/src/frontend_test.v +++ b/src/frontend_test.v @@ -9,6 +9,26 @@ import os import testdb import time +fn test_prepare_conflict_keeps_its_error_kind_after_copying_names() ! { + s := fake_system('prepare_conflict_kind')! + defer { os.rmdir_all(s.tmp) or { went_on('remove the test system', err) } } + testdb.write_local(s.path('db'), [testdb.Pkg{ name: 'old', conflicts: ['new'] }])! + s.publish([FakePkg{ name: 'new' }])! + handle := alpm.initialize(s.path('root'), s.path('db'))! + defer { handle.release() or { went_on('release the alpm handle', err) } } + db := handle.register_syncdb('core', 0)! + trans_begin(handle, .nolock)! + defer { trans_cleanup(handle) } + handle.add_pkg(db.get_pkg('new') or { return error('missing new package') })! + trans_prepare_checked(handle) or { + assert err.code() == int(alpm.Errno.conflicting_deps) + assert err.msg().contains('unresolvable package conflicts:') + assert err.msg().contains('new and old are in conflict') + return + } + assert false, 'the conflicting transaction was accepted' +} + #include fn C.__fpurge(stream &C.FILE) diff --git a/src/trans.v b/src/trans.v index 4b984d6..fb1e777 100644 --- a/src/trans.v +++ b/src/trans.v @@ -201,8 +201,9 @@ fn trans_prepare_checked(handle &alpm.Handle) ! { if problems.len == 0 { return err } - // the errno is still the prepare's: nothing called libalpm since - return error(prepare_problem_lines(handle.errno(), problems).join('\n')) + // copying conflict package names can reset the handle's mutable errno. + kind := unsafe { alpm.Errno(err.code()) } + return error_with_code(prepare_problem_lines(kind, problems).join('\n'), err.code()) } } -- 2.56.1