me

/

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

fix: initialization errors and local db permission checks

diviocity committed last Nov 11 · 6a725c0ab99bcdb7b8b4f0cbceb402de129a8440 View patch
Unverified signature 3 files changed +61 -1
README.md +4 -0

@@ -59,6 +59,10 @@ Installed-package cache reads report invalid or duplicate entries and reject

5959directory read failures rather than accepting a partial package list. Symlinked

6060local package entries remain excluded.

6161

62+Local database initialization honors the process umask and checks version-file

63+writes. A regular file at the local database path is reported as an open error

64+and is preserved. Initialization errors include their cause.

65+

6266`v test src` and `v test vmakepkg` run the test suites.

6367

6468## docs

src/frontend_test.v +56 -0

@@ -1971,6 +1971,62 @@ fn test_local_cache_read_failure_is_reported_and_can_be_retried() ! {

19711971 assert !s.lock_left()

19721972}

19731973

1974+fn test_local_database_file_reports_an_open_error_without_replacing_it() ! {

1975+ s := fake_system('local_db_file')!

1976+ defer { os.rmdir_all(s.tmp) or { went_on('remove the test system', err) } }

1977+ path := s.path('db/local')

1978+ os.rmdir_all(path)!

1979+ os.write_file(path, 'keep this file')!

1980+ run := s.run('', fn () ! {

1981+ info(ConfigInfo{ fields: 'name', query: ['local/app'] }) or {

1982+ check(err.code() == int(alpm.Errno.db_open), 'initialization error kind is preserved')!

1983+ return err

1984+ }

1985+ })!

1986+ assert run.err.contains(alpm.Errno.db_open.strerror()), run.err

1987+ assert run.of('info').len == 0

1988+ assert os.read_file(path)! == 'keep this file'

1989+ assert !s.lock_left()

1990+}

1991+

1992+fn test_empty_database_creation_does_not_reopen_a_write_only_version_file() ! {

1993+ s := fake_system('local_db_umask')!

1994+ defer { os.rmdir_all(s.tmp) or { went_on('remove the test system', err) } }

1995+ version := s.path('db/local/ALPM_DB_VERSION')

1996+ os.rm(version)!

1997+ run := s.run('', fn () ! {

1998+ prior := C.umask(0o444)

1999+ defer { C.umask(prior) }

2000+ mut ui := new_trans_ui()

2001+ handle := init_handle(ui)!

2002+ defer { handle.release() or { went_on('release the alpm handle', err) } }

2003+ defer { ui.stop() }

2004+ packages := local_pkgcache(handle)!

2005+ check(packages.pkgs().len == 0, 'new local database is empty')!

2006+ })!

2007+ assert run.err == '' && run.failed == 0, run.err

2008+ assert os.stat(version)!.mode & 0o777 == 0o222

2009+ os.chmod(version, 0o644)!

2010+ assert os.read_file(version)! == '9\n'

2011+ assert !s.lock_left()

2012+}

2013+

2014+fn test_info_accepts_the_source_unsigned_local_version_format() ! {

2015+ s := fake_system('local_db_numeric_version')!

2016+ defer { os.rmdir_all(s.tmp) or { went_on('remove the test system', err) } }

2017+ s.install_local(fake_pkg('app', '1.0-1', []))!

2018+ path := s.path('db/local/ALPM_DB_VERSION')

2019+ text := '-${u64(C.SIZE_MAX) - 8} trailing\n'

2020+ os.write_file(path, text)!

2021+ run := s.run('', fn () ! {

2022+ info(ConfigInfo{ fields: 'name,version', query: ['local/app'] })!

2023+ })!

2024+ assert run.err == '' && run.failed == 0, run.err

2025+ assert run.of('info').len == 1

2026+ assert os.read_file(path)! == text

2027+ assert !s.lock_left()

2028+}

2029+

19742030fn test_info_scopes_and_satisfiers() ! {

19752031 s := fake_system('infoscope')!

19762032 defer { os.rmdir_all(s.tmp) or {} }

src/ui.v +1 -1

@@ -890,7 +890,7 @@ fn flag_answer(yes bool) i32 {

890890// and the configured parallel download count

891891fn init_handle(ui &TransUI) !&alpm.Handle {

892892 handle := alpm.initialize(root_path, db_path) or {

893- return error('failed to initialize alpm')

893+ return error_with_code('failed to initialize alpm: ${err.msg()}', err.code())

894894 }

895895 handle.option_set_dlcb(cb_download, voidptr(ui))!

896896 handle.option_set_progresscb(cb_progress, voidptr(ui))!