module testdb import os // testdb writes libalpm local dbs for the tests: every test file is a // binary of its own, so a writer they share lives in a module they import // and vpac itself never does — it is in no build of the program. // Pkg is one installed package of a written db: what its desc says, and the // entries of its file list (directories with their trailing slash, as // libalpm keeps them) pub struct Pkg { pub: name string version string = '1.0-1' reason int // 0 explicit, 1 a dependency depends []string optdepends []string provides []string conflicts []string groups []string files []string // no_files leaves the file list out altogether, a broken entry no_files bool } // desc is the text of a package's desc file: the sections that have // something to say, in libalpm's spelling pub fn (p Pkg) desc() string { mut out := '%NAME%\n${p.name}\n\n%VERSION%\n${p.version}\n\n%ARCH%\nany\n\n%REASON%\n${p.reason}\n\n' for key, items in { 'DEPENDS': p.depends 'OPTDEPENDS': p.optdepends 'PROVIDES': p.provides 'CONFLICTS': p.conflicts 'GROUPS': p.groups } { if items.len > 0 { out += '%${key}%\n${items.join('\n')}\n\n' } } return out } // write_local lays out a local db (version 9) under dbpath: the version // file, and one dir per package, named name-version, with its desc and its // file list. it adds to a db that is there; no packages write an empty one pub fn write_local(dbpath string, pkgs []Pkg) ! { local := os.join_path(dbpath, 'local') os.mkdir_all(local)! os.write_file(os.join_path(local, 'ALPM_DB_VERSION'), '9\n')! for p in pkgs { dir := os.join_path(local, '${p.name}-${p.version}') os.mkdir_all(dir)! os.write_file(os.join_path(dir, 'desc'), p.desc())! if !p.no_files { os.write_file(os.join_path(dir, 'files'), '%FILES%\n${p.files.join('\n')}\n\n')! } } }