diff --git a/src/archive/archive.v b/src/archive/archive.v index ca911c70..011333f0 100644 --- a/src/archive/archive.v +++ b/src/archive/archive.v @@ -2,7 +2,7 @@ module archive import os -pub fn get_pkg_info(pkg_path string) ?string { +pub fn pkg_info_string(pkg_path string) ?string { if !os.is_file(pkg_path) { return error("'$pkg_path' doesn't exist or isn't a file.") } diff --git a/src/main.v b/src/main.v index af6b06c5..0b277366 100644 --- a/src/main.v +++ b/src/main.v @@ -54,7 +54,7 @@ fn reader_to_file(mut reader io.BufferedReader, length int, path string) ? { } } -fn main() { +fn main2() { // Configure logger log_level_str := os.getenv_opt('LOG_LEVEL') or { 'WARN' } log_level := log.level_from_tag(log_level_str) or { @@ -102,11 +102,11 @@ fn main() { }, port) } -// fn main() { -// // archive.list_filenames() -// info := archive.get_pkg_info('test/jjr-joplin-desktop-2.6.10-4-x86_64.pkg.tar.zst') or { -// eprintln(err.msg) -// return -// } -// println(info) -// } +fn main() { + // archive.list_filenames() + info := repo.get_pkg_info('test/jjr-joplin-desktop-2.6.10-4-x86_64.pkg.tar.zst') or { + eprintln(err.msg) + return + } + println(info) +} diff --git a/src/repo/pkg.v b/src/repo/pkg.v new file mode 100644 index 00000000..b45839bd --- /dev/null +++ b/src/repo/pkg.v @@ -0,0 +1,90 @@ +module repo + +import archive +import time + +struct PkgInfo { +mut: + // Single values + name string + base string + version string + description string + size i64 + csize i64 + url string + arch string + build_date i64 + packager string + md5sum string + sha256sum string + pgpsig string + pgpsigsize i64 + + // Array values + groups []string + licenses []string + replaces []string + depends []string + conflicts []string + provides []string + optdepends []string + makedepends []string + checkdepends []string +} + +pub fn get_pkg_info(pkg_path string) ?PkgInfo { + pkg_info_str := archive.pkg_info_string(pkg_path) ? + mut pkg_info := PkgInfo{} + + mut i := 0 + mut j := 0 + + // Iterate over the entire string + for line in pkg_info_str.split_into_lines() { + // Skip any comment lines + if line.starts_with('#') { + continue + } + parts := line.split_nth('=', 2) + + if parts.len < 2 { + return error('Invalid line detected.') + } + + value := parts[1].trim_space() + key := parts[0].trim_space() + + match key { + // Single values + 'pkgname' { pkg_info.name = value } + 'pkgbase' { pkg_info.base = value } + 'pkgver' { pkg_info.version = value } + 'pkgdesc' { pkg_info.description = value } + 'csize' { pkg_info.csize = value.int() } + 'size' { pkg_info.size = value.int() } + 'url' { pkg_info.url = value } + 'arch' { pkg_info.arch = value } + 'builddate' { pkg_info.build_date = value.int() } + 'packager' { pkg_info.packager = value } + 'md5sum' { pkg_info.md5sum = value } + 'sha256sum' { pkg_info.sha256sum = value } + 'pgpsig' { pkg_info.pgpsig = value } + 'pgpsigsize' { pkg_info.pgpsigsize = value.int() } + + // Array values + 'group' { pkg_info.groups << value } + 'license' { pkg_info.licenses << value } + 'replaces' { pkg_info.replaces << value } + 'depend' { pkg_info.depends << value } + 'conflict' { pkg_info.conflicts << value } + 'provides' { pkg_info.provides << value } + 'optdepend' { pkg_info.optdepends << value } + 'makedepend' { pkg_info.makedepends << value } + 'checkdepend' { pkg_info.checkdepends << value } + else { return error("Invalid key '$key'.") } + } + } + + return pkg_info +} diff --git a/src/repo.v b/src/repo/repo.v similarity index 98% rename from src/repo.v rename to src/repo/repo.v index 6b307e89..494f8c93 100644 --- a/src/repo.v +++ b/src/repo/repo.v @@ -1,6 +1,7 @@ module repo import os +import archive const pkgs_subpath = 'pkgs'