-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo_fake.go
71 lines (59 loc) · 1.89 KB
/
repo_fake.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package pkgcraft
// #cgo pkg-config: pkgcraft
// #include <pkgcraft.h>
import "C"
import (
"runtime"
"unsafe"
)
type FakeRepo struct {
*BaseRepo
}
// Create a new fake repo.
func NewFakeRepo(id string, priority int, cpvs []string) (*FakeRepo, error) {
c_cpvs, c_len := sliceToCharArray(cpvs)
c_id := C.CString(id)
ptr := C.pkgcraft_repo_fake_new(c_id, C.int(priority), c_cpvs, c_len)
C.free(unsafe.Pointer(c_id))
C.free(unsafe.Pointer(c_cpvs))
if ptr != nil {
repo := &FakeRepo{repoFromPtr(ptr)}
runtime.SetFinalizer(repo, func(self *FakeRepo) { C.pkgcraft_repo_free(self.ptr) })
return repo, nil
} else {
return nil, newPkgcraftError()
}
}
// Add packages to an existing repo.
func (self *FakeRepo) Extend(cpvs []string) error {
c_cpvs, c_len := sliceToCharArray(cpvs)
ptr := C.pkgcraft_repo_fake_extend(self.ptr, (**C.char)(c_cpvs), c_len)
C.free(unsafe.Pointer(c_cpvs))
if ptr != nil {
return nil
} else {
return newPkgcraftError()
}
}
func (self *FakeRepo) createPkg(ptr *C.Pkg) *FakePkg {
format := PkgFormat(C.pkgcraft_pkg_format(ptr))
pkg := &FakePkg{&BasePkg{ptr: ptr, format: format}}
runtime.SetFinalizer(pkg, func(self *FakePkg) { C.pkgcraft_pkg_free(self.ptr) })
return pkg
}
// Return an iterator over the packages of a repo.
func (self *FakeRepo) Iter() *repoIter[*FakePkg] {
return newRepoIter[*FakePkg](self)
}
// Return a channel iterating over the packages of a repo.
func (self *FakeRepo) Pkgs() <-chan *FakePkg {
return repoPkgs((pkgRepo[*FakePkg])(self))
}
// Return an iterator over the restricted packages of a repo.
func (self *FakeRepo) IterRestrict(restrict *Restrict) *repoIterRestrict[*FakePkg] {
return newRepoIterRestrict[*FakePkg](self, restrict)
}
// Return a channel iterating over the restricted packages of a repo.
func (self *FakeRepo) RestrictPkgs(restrict *Restrict) <-chan *FakePkg {
return repoRestrictPkgs((pkgRepo[*FakePkg])(self), restrict)
}