forked from Morganamilo/go-alpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
200 lines (153 loc) · 4.08 KB
/
types.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// types.go - libalpm types.
//
// Copyright (c) 2013 The go-alpm Authors
//
// MIT Licensed. See LICENSE for details.
package alpm
// #cgo CFLAGS: -D_FILE_OFFSET_BITS=64
// #include <alpm.h>
import "C"
import (
"fmt"
"reflect"
"unsafe"
)
type Depend C.alpm_depend_t
func (dep *Depend) Name() string {
return C.GoString(dep.name)
}
func (dep *Depend) Version() string {
return C.GoString(dep.version)
}
func (dep *Depend) Description() string {
return C.GoString(dep.desc)
}
func (dep *Depend) NameHash() uint {
return uint(dep.name_hash)
}
func (dep *Depend) Mod() DepMod {
return DepMod(dep.mod)
}
type File C.alpm_file_t
func (file *File) Name() string {
return C.GoString(file.name)
}
func (file *File) Size() int64 {
return int64(file.size)
}
func (file *File) Mode() uint32 {
return uint32(file.mode)
}
type FileList C.alpm_filelist_t
func (fl *FileList) Count() uint {
return uint(fl.count)
}
func (fl *FileList) Slice() []File {
size := int(fl.Count())
items := reflect.SliceHeader{
Len: size,
Cap: size,
Data: uintptr(unsafe.Pointer(fl.files))}
return *(*[]File)(unsafe.Pointer(&items))
}
type Backup C.alpm_backup_t
type QuestionAny C.alpm_question_any_t
func (question *QuestionAny) SetAnswer(answer bool) {
if answer {
question.answer = 1
} else {
question.answer = 0
}
}
type QuestionInstallIgnorepkg C.alpm_question_install_ignorepkg_t
func (question *QuestionAny) Type() QuestionType {
return QuestionType(question._type)
}
func (question *QuestionAny) Answer() bool {
return question.answer == 1
}
func (question *QuestionAny) QuestionInstallIgnorepkg() (QuestionInstallIgnorepkg, error) {
if question.Type() == QuestionTypeInstallIgnorepkg {
return *(*QuestionInstallIgnorepkg)(unsafe.Pointer(&question)), nil
}
return QuestionInstallIgnorepkg{}, fmt.Errorf("Can not convert to QuestionInstallIgnorepkg")
}
func (question *QuestionAny) QuestionSelectProvider() (QuestionSelectProvider, error) {
if question.Type() == QuestionTypeSelectProvider {
return *(*QuestionSelectProvider)(unsafe.Pointer(&question)), nil
}
return QuestionSelectProvider{}, fmt.Errorf("Can not convert to QuestionInstallIgnorepkg")
}
func (question *QuestionAny) QuestionReplace() (QuestionReplace, error) {
if question.Type() == QuestionTypeReplacePkg {
return *(*QuestionReplace)(unsafe.Pointer(&question)), nil
}
return QuestionReplace{}, fmt.Errorf("Can not convert to QuestionReplace")
}
func (question QuestionInstallIgnorepkg) SetInstall(install bool) {
if install {
question.install = 1
} else {
question.install = 0
}
}
func (question *QuestionInstallIgnorepkg) Type() QuestionType {
return QuestionType(question._type)
}
func (question *QuestionInstallIgnorepkg) Install() bool {
return question.install == 1
}
func (question *QuestionInstallIgnorepkg) Pkg(h *Handle) Package {
return Package{
question.pkg,
*h,
}
}
type QuestionReplace C.alpm_question_replace_t
func (question *QuestionReplace) Type() QuestionType {
return QuestionType(question._type)
}
func (question *QuestionReplace) SetReplace(replace bool) {
if replace {
question.replace = 1
} else {
question.replace = 0
}
}
func (question *QuestionReplace) Replace() bool {
return question.replace == 1
}
func (question *QuestionReplace) NewPkg(h *Handle) *Package {
return &Package{
question.newpkg,
*h,
}
}
func (question *QuestionReplace) OldPkg(h *Handle) *Package {
return &Package{
question.oldpkg,
*h,
}
}
func (question *QuestionReplace) newDB(h *Handle) *DB {
return &DB{
question.newdb,
*h,
}
}
type QuestionSelectProvider C.alpm_question_select_provider_t
func (question *QuestionSelectProvider) Type() QuestionType {
return QuestionType(question._type)
}
func (question *QuestionSelectProvider) SetUseIndex(index int) {
question.use_index = C.int(index)
}
func (question *QuestionSelectProvider) UseIndex() int {
return int(question.use_index)
}
func (question *QuestionSelectProvider) Providers(h *Handle) PackageList {
return makePackageList(question.providers, *h)
}
func (question *QuestionSelectProvider) Dep() *Depend {
return (*Depend)(question.depend)
}