From 6a725c0ab99bcdb7b8b4f0cbceb402de129a8440 Mon Sep 17 00:00:00 2001 From: diviocity Date: Wed, 11 Nov 2026 20:57:00 +0100 Subject: [PATCH] fix: initialization errors and local db permission checks Retain the library initialization cause and error code. Test a regular-file local path without replacement, empty DB creation under a write-only version umask and source-compatible numeric versions. Preserve fixture data and locks and document initialization behavior. Validation with companion native engine: all 27 frontend and 2 vmakepkg binaries pass; all 78 engine binaries pass. Compiler diagnostics, formatting and actual binary no-libalpm checks pass. Resolves #13 after companion publication. --- README.md | 4 ++++ src/frontend_test.v | 56 +++++++++++++++++++++++++++++++++++++++++++++ src/ui.v | 2 +- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28b518a..15037f8 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ Installed-package cache reads report invalid or duplicate entries and reject directory read failures rather than accepting a partial package list. Symlinked local package entries remain excluded. +Local database initialization honors the process umask and checks version-file +writes. A regular file at the local database path is reported as an open error +and is preserved. Initialization errors include their cause. + `v test src` and `v test vmakepkg` run the test suites. ## docs diff --git a/src/frontend_test.v b/src/frontend_test.v index 6458566..efe6f1a 100644 --- a/src/frontend_test.v +++ b/src/frontend_test.v @@ -1971,6 +1971,62 @@ fn test_local_cache_read_failure_is_reported_and_can_be_retried() ! { assert !s.lock_left() } +fn test_local_database_file_reports_an_open_error_without_replacing_it() ! { + s := fake_system('local_db_file')! + defer { os.rmdir_all(s.tmp) or { went_on('remove the test system', err) } } + path := s.path('db/local') + os.rmdir_all(path)! + os.write_file(path, 'keep this file')! + run := s.run('', fn () ! { + info(ConfigInfo{ fields: 'name', query: ['local/app'] }) or { + check(err.code() == int(alpm.Errno.db_open), 'initialization error kind is preserved')! + return err + } + })! + assert run.err.contains(alpm.Errno.db_open.strerror()), run.err + assert run.of('info').len == 0 + assert os.read_file(path)! == 'keep this file' + assert !s.lock_left() +} + +fn test_empty_database_creation_does_not_reopen_a_write_only_version_file() ! { + s := fake_system('local_db_umask')! + defer { os.rmdir_all(s.tmp) or { went_on('remove the test system', err) } } + version := s.path('db/local/ALPM_DB_VERSION') + os.rm(version)! + run := s.run('', fn () ! { + prior := C.umask(0o444) + defer { C.umask(prior) } + mut ui := new_trans_ui() + handle := init_handle(ui)! + defer { handle.release() or { went_on('release the alpm handle', err) } } + defer { ui.stop() } + packages := local_pkgcache(handle)! + check(packages.pkgs().len == 0, 'new local database is empty')! + })! + assert run.err == '' && run.failed == 0, run.err + assert os.stat(version)!.mode & 0o777 == 0o222 + os.chmod(version, 0o644)! + assert os.read_file(version)! == '9\n' + assert !s.lock_left() +} + +fn test_info_accepts_the_source_unsigned_local_version_format() ! { + s := fake_system('local_db_numeric_version')! + defer { os.rmdir_all(s.tmp) or { went_on('remove the test system', err) } } + s.install_local(fake_pkg('app', '1.0-1', []))! + path := s.path('db/local/ALPM_DB_VERSION') + text := '-${u64(C.SIZE_MAX) - 8} trailing\n' + os.write_file(path, text)! + run := s.run('', fn () ! { + info(ConfigInfo{ fields: 'name,version', query: ['local/app'] })! + })! + assert run.err == '' && run.failed == 0, run.err + assert run.of('info').len == 1 + assert os.read_file(path)! == text + assert !s.lock_left() +} + fn test_info_scopes_and_satisfiers() ! { s := fake_system('infoscope')! defer { os.rmdir_all(s.tmp) or {} } diff --git a/src/ui.v b/src/ui.v index 33bf0f4..16f119f 100644 --- a/src/ui.v +++ b/src/ui.v @@ -890,7 +890,7 @@ fn flag_answer(yes bool) i32 { // and the configured parallel download count fn init_handle(ui &TransUI) !&alpm.Handle { handle := alpm.initialize(root_path, db_path) or { - return error('failed to initialize alpm') + return error_with_code('failed to initialize alpm: ${err.msg()}', err.code()) } handle.option_set_dlcb(cb_download, voidptr(ui))! handle.option_set_progresscb(cb_progress, voidptr(ui))! -- 2.56.1