vieter/src/repo/repo.v

54 lines
1.1 KiB
Coq
Raw Normal View History

2022-01-09 22:30:07 +01:00
module repo
import os
import archive
2022-01-09 22:30:07 +01:00
const pkgs_subpath = 'pkgs'
// Dummy struct to work around the fact that you can only share structs, maps &
// arrays
pub struct Dummy {
x int
}
// Handles management of a repository. Package files are stored in '$dir/pkgs'
// & moved there if necessary.
2022-01-11 14:40:25 +01:00
pub struct Repo {
2022-01-11 16:37:49 +01:00
mut:
mutex shared Dummy
pub:
dir string [required]
name string [required]
}
pub fn (r &Repo) pkg_dir() string {
return os.join_path_single(r.dir, repo.pkgs_subpath)
}
// Returns path to the given package, prepended with the repo's path.
2022-01-11 16:37:49 +01:00
pub fn (r &Repo) pkg_path(pkg string) string {
return os.join_path(r.dir, repo.pkgs_subpath, pkg)
}
2022-01-11 16:37:49 +01:00
pub fn (r &Repo) exists(pkg string) bool {
return os.exists(r.pkg_path(pkg))
}
// Returns the full path to the database file
2022-01-11 16:37:49 +01:00
pub fn (r &Repo) db_path() string {
return os.join_path_single(r.dir, '${r.name}.tar.gz')
2022-01-11 14:40:25 +01:00
}
2022-01-11 16:37:49 +01:00
pub fn (r &Repo) add_package(pkg_path string) ? {
mut res := os.Result{}
lock r.mutex {
res = os.execute("repo-add '$r.db_path()' '$pkg_path'")
}
2022-01-09 22:30:07 +01:00
if res.exit_code != 0 {
println(res.output)
return error('repo-add failed.')
}
}