nspkg / tests / coracle / alpm.v
2573 lines · 2056 sloc · 65.24 KB · c01b0795d1db56c7bce2539b2c46b110637fdc1a
Raw
1// C reference based on the public API at 3d0a6ea; never a production backend.
2module coracle
3
4#flag -I/usr/include
5#flag -lalpm
6#flag -std=gnu99
7
8#include "@DIR/native_oracle.h"
9
10struct C.Archive {}
11
12fn C.archive_error_string(&C.Archive) &char
13
14struct C.Archive_acl {}
15
16struct C.Archive_entry {}
17
18struct C.Archive_entry_linkresolver {}
19
20type Size_t = u32
21type Ulong = u32
22type Ushort = u16
23type Uint = u32
24type U_int8_t = u8
25type U_int16_t = u16
26type U_int32_t = u32
27type U_int64_t = u64
28
29type Time_t = i64
30type Off_t = i64
31type Pid_t = int
32type Uid_t = u32
33type Gid_t = u32
34type Mode_t = u32
35type Dev_t = u64
36type Ino_t = u64
37type Nlink_t = u64
38type Blksize_t = i64
39type Blkcnt_t = i64
40type Clock_t = i64
41type Clockid_t = int
42type Timer_t = voidptr
43type Suseconds_t = i64
44type Useconds_t = u32
45type Syscall_slong_t = i64
46type Off64_t = i64
47
48struct C.Timespec {
49 tv_sec Time_t
50 tv_nsec Syscall_slong_t
51}
52
53type La_int64_t = i64
54type La_uint64_t = u64
55type La_ssize_t = int
56
57pub fn (list &List) get_pkg() ?&Package {
58 data := unsafe { &Package(list.data) }
59 return if data == unsafe { nil } { none } else { data }
60}
61
62pub fn (list &List) get_db() ?&DB {
63 data := unsafe { &DB(list.data) }
64 return if data == unsafe { nil } { none } else { data }
65}
66
67pub fn (list &List) get_str() ?string {
68 data := unsafe { &u8(list.data) }
69 return if data == unsafe { nil } { none } else { unsafe { data.vstring() } }
70}
71
72pub fn (list &List) get_group() ?&Group {
73 data := unsafe { &Group(list.data) }
74 return if data == unsafe { nil } { none } else { data }
75}
76
77pub fn (list &List) get_backup() ?&Backup {
78 if list.data == unsafe { nil } {
79 return none
80 }
81 return &Backup(list.data)
82}
83
84pub fn (b &Backup) get_name() string {
85 return cstring_to_vstring_or_none(b.name)
86}
87
88pub fn (b &Backup) get_hash() string {
89 return cstring_to_vstring_or_none(b.hash)
90}
91
92pub fn (list &List) get_depend() ?&Depend {
93 data := unsafe { &Depend(list.data) }
94 return if data == unsafe { nil } { none } else { data }
95}
96
97pub fn (mut list List) pkgs() []&Package {
98 mut out := []&Package{}
99 for list != unsafe { nil } {
100 if pkg := list.get_pkg() {
101 out << pkg
102 } else {
103 break
104 }
105 list = list.next
106 }
107 return out
108}
109
110pub fn (mut list List) dbs() []&DB {
111 mut out := []&DB{}
112 for list != unsafe { nil } {
113 if db := list.get_db() {
114 out << db
115 } else {
116 break
117 }
118 list = list.next
119 }
120 return out
121}
122
123pub fn (mut list List) strs() []string {
124 mut out := []string{}
125 for list != unsafe { nil } {
126 if s := list.get_str() {
127 out << s
128 } else {
129 break
130 }
131 list = list.next
132 }
133 return out
134}
135
136pub fn (mut list List) groups() []&Group {
137 mut out := []&Group{}
138 for list != unsafe { nil } {
139 if s := list.get_group() {
140 out << s
141 } else {
142 break
143 }
144 list = list.next
145 }
146 return out
147}
148
149pub fn (mut list List) depends() []&Depend {
150 mut out := []&Depend{}
151 for list != unsafe { nil } {
152 if s := list.get_depend() {
153 out << s
154 } else {
155 break
156 }
157 list = list.next
158 }
159 return out
160}
161
162pub struct HandleW {
163pub mut:
164 handle &Handle = unsafe { nil }
165 err Errno
166}
167
168pub struct Handle {}
169
170pub struct DB {}
171
172pub struct Package {}
173
174pub struct PkgXdata {
175 name &u8 = unsafe { nil }
176 value &u8 = unsafe { nil }
177}
178
179type Time = i64
180
181pub struct File {
182 name &u8 = unsafe { nil }
183 size i64
184 mode u32
185}
186
187pub struct Filelist {
188 count uint
189 files &File = unsafe { nil }
190}
191
192pub struct Backup {
193 name &u8 = unsafe { nil }
194 hash &u8 = unsafe { nil }
195}
196
197fn C.oracle_alpm_filelist_contains(filelist &Filelist, path &u8) &File
198
199fn C.oracle_alpm_find_group_pkgs(dbs &List, name &u8) &List
200
201pub fn (filelist &Filelist) contains(path string) ?&File {
202 res := C.oracle_alpm_filelist_contains(filelist, path.str)
203 return if res == unsafe { nil } {
204 none
205 } else {
206 res
207 }
208}
209
210pub struct Group {
211pub mut:
212 name &u8 = unsafe { nil }
213 packages &List = unsafe { nil }
214}
215
216pub fn (group &Group) get_name() string {
217 return cstring_to_vstring_or_none(group.name)
218}
219
220pub fn (dbs &List) find_group_pkgs(name string) &List {
221 return C.oracle_alpm_find_group_pkgs(dbs, name.str)
222}
223
224pub enum Errno {
225 ok = 0
226 memory
227 system
228 badperms
229 not_a_file
230 not_a_dir
231 wrong_args
232 disk_space
233 handle_null
234 handle_not_null
235 handle_lock
236 db_open
237 db_create
238 db_null
239 db_not_null
240 db_not_found
241 db_invalid
242 db_invalid_sig
243 db_version
244 db_write
245 db_remove
246 server_bad_url
247 server_none
248 trans_not_null
249 trans_null
250 trans_dup_target
251 trans_dup_filename
252 trans_not_initialized
253 trans_not_prepared
254 trans_abort
255 trans_type
256 trans_not_locked
257 trans_hook_failed
258 pkg_not_found
259 pkg_ignored
260 pkg_invalid
261 pkg_invalid_checksum
262 pkg_invalid_sig
263 pkg_missing_sig
264 pkg_open
265 pkg_cant_remove
266 pkg_invalid_name
267 pkg_invalid_arch
268 sig_missing
269 sig_invalid
270 unsatisfied_deps
271 conflicting_deps
272 file_conflicts
273 retrieve_prepare
274 retrieve
275 invalid_regex
276 libarchive
277 libcurl
278 external_download
279 gpgme
280 missing_capability_signatures
281}
282
283fn C.oracle_alpm_errno(handle &Handle) Errno
284
285fn C.oracle_alpm_strerror(err Errno) &u8
286
287fn C.oracle_alpm_initialize(root &u8, dbpath &u8, err &Errno) &Handle
288
289fn C.oracle_alpm_release(handle &Handle) int
290
291pub fn (handle &Handle) errno() Errno {
292 return C.oracle_alpm_errno(handle)
293}
294
295pub fn (err Errno) strerror() string {
296 return unsafe { C.oracle_alpm_strerror(err).vstring() }
297}
298
299pub fn (err Errno) ierror() IError {
300 return error_with_code(err.strerror(), int(err))
301}
302
303pub fn (handle &Handle) error() IError {
304 return handle.errno().ierror()
305}
306
307pub fn initialize(root string, dbpath string) !&Handle {
308 mut err := Errno.ok
309 handle := C.oracle_alpm_initialize(root.str, dbpath.str, &err)
310 return if err != .ok {
311 err.ierror()
312 } else if handle == unsafe { nil } {
313 error('handle is NULL')
314 } else {
315 handle
316 }
317}
318
319pub fn (handle &Handle) release() ! {
320 if C.oracle_alpm_release(handle) != 0 {
321 return handle.error()
322 }
323}
324
325// the values of a @[flag] enum are bit positions, not masks: V turns
326// `database = 10` into 1 << 10, libalpm's ALPM_SIG_DATABASE. alpm_test.v
327// checks every flag enum against libalpm's own constants
328@[flag]
329pub enum SigLevel {
330 package = 0
331 package_optional = 1
332 package_marginal_ok = 2
333 package_unknown_ok = 3
334 database = 10
335 database_optional = 11
336 database_marginal_ok = 12
337 database_unknown_ok = 13
338 use_default = 30
339}
340
341pub enum SigStatus {
342 valid
343 key_expired
344 sig_expired
345 key_unknown
346 key_disabled
347 invalid
348}
349
350pub enum SigValidity {
351 full
352 marginal
353 never
354 unknown
355}
356
357pub struct PGPKey {
358pub mut:
359 data voidptr = unsafe { nil }
360 fingerprint &u8 = unsafe { nil }
361 uid &u8 = unsafe { nil }
362 name &u8 = unsafe { nil }
363 email &u8 = unsafe { nil }
364 created Time
365 expires Time
366 length u32
367 revoked u32
368}
369
370pub struct SigResult {
371pub mut:
372 key PGPKey
373 status SigStatus
374 validity SigValidity
375}
376
377pub struct SigList {
378pub mut:
379 count uint
380 results &SigResult = unsafe { nil }
381}
382
383fn C.oracle_alpm_pkg_check_pgp_signature(pkg &Package, siglist &SigList) int
384
385fn C.oracle_alpm_db_check_pgp_signature(db &DB, siglist &SigList) int
386
387fn C.oracle_alpm_siglist_cleanup(siglist &SigList) int
388
389fn C.oracle_alpm_decode_signature(base64_data &u8, data &&u8, data_len &uint) int
390
391fn C.oracle_alpm_extract_keyid(handle &Handle, identifier &u8, sig &u8, len uint, keys &&List) int
392
393pub fn (pkg &Package) check_pgp_signature() ?&SigList {
394 mut siglist := &SigList{}
395 return if C.oracle_alpm_pkg_check_pgp_signature(pkg, siglist) != 0 { none } else { siglist }
396}
397
398pub fn (db &DB) check_pgp_signature() ?&SigList {
399 mut siglist := &SigList{}
400 return if C.oracle_alpm_db_check_pgp_signature(db, siglist) != 0 { none } else { siglist }
401}
402
403pub fn (siglist &SigList) cleanup() ! {
404 if C.oracle_alpm_siglist_cleanup(siglist) != 0 {
405 return error('failed to cleanup siglist')
406 }
407}
408
409pub fn decode_signature(base64_data string, data_len &uint) !&u8 {
410 if data_len == unsafe { nil } { return Errno.wrong_args.ierror() }
411 unsafe { *data_len = 0 }
412 mut data := &u8(unsafe { nil })
413 if C.oracle_alpm_decode_signature(base64_data.str, &data, data_len) != 0 {
414 return Errno.sig_invalid.ierror()
415 }
416 return data
417}
418
419fn C.oracle_alpm_decode_signature(&u8, &&u8, &uint) int
420fn C.oracle_alpm_extract_keyid(&Handle, &u8, &u8, uint, &&List) int
421
422pub fn (handle &Handle) extract_keyid(identifier string, sig &u8, len uint) !&List {
423 if handle == unsafe { nil } { return Errno.handle_null.ierror() }
424 if int(len) < 0 || (sig == unsafe { nil } && len != 0) { return Errno.wrong_args.ierror() }
425 mut keys := &List(unsafe { nil })
426 if len == 0 { return keys }
427 if C.oracle_alpm_extract_keyid(handle, identifier.str, sig, len, &keys) != 0 {
428 return handle.error()
429 }
430 return keys
431}
432
433pub enum Depmod {
434 any = 1
435 equal
436 at_least
437 at_most
438 greater_than
439 less_than
440}
441
442pub enum FileConflictType {
443 target = 1
444 filesystem
445}
446
447pub struct Depend {
448pub mut:
449 name &u8 = unsafe { nil }
450 version &u8 = unsafe { nil }
451 desc &u8 = unsafe { nil }
452 name_hash u64
453 mod Depmod
454}
455
456pub fn (dep Depend) get_name() string {
457 return cstring_to_vstring_or_none(dep.name)
458}
459
460pub fn (dep Depend) get_version() string {
461 return cstring_to_vstring_or_none(dep.version)
462}
463
464pub fn (dep Depend) get_desc() string {
465 return cstring_to_vstring_or_none(dep.desc)
466}
467
468pub struct DepMissing {
469pub mut:
470 target &u8 = unsafe { nil }
471 depend &Depend = unsafe { nil }
472 causingpkg &u8 = unsafe { nil }
473}
474
475pub struct Conflict {
476pub mut:
477 package1 &Package = unsafe { nil }
478 package2 &Package = unsafe { nil }
479 reason &Depend = unsafe { nil }
480}
481
482pub struct FileConflict {
483pub mut:
484 target &u8 = unsafe { nil }
485 type_ FileConflictType
486 file &u8 = unsafe { nil }
487 ctarget &u8 = unsafe { nil }
488}
489
490fn C.oracle_alpm_checkdeps(handle &Handle, pkglist &List, remove &List, upgrade &List, reversedeps int) &List
491
492fn C.oracle_alpm_find_dbs_satisfier(handle &Handle, dbs &List, depstring &u8) &Package
493
494fn C.oracle_alpm_checkconflicts(handle &Handle, pkglist &List) &List
495
496fn C.oracle_alpm_conflict_free(conflict &Conflict)
497
498pub fn (handle &Handle) checkdeps(pkglist &List, remove &List, upgrade &List, reversedeps int) &List {
499 return C.oracle_alpm_checkdeps(handle, pkglist, remove, upgrade, reversedeps)
500}
501
502pub fn (pkgs &List) find_satisfier(depstring string) ?&Package {
503 result := C.oracle_alpm_find_satisfier(pkgs, depstring.str)
504 return if result == unsafe { nil } { none } else { result }
505}
506
507fn C.oracle_alpm_find_satisfier(&List, &u8) &Package
508
509pub fn (handle &Handle) find_dbs_satisfier(dbs &List, depstring string) ?&Package {
510 res := C.oracle_alpm_find_dbs_satisfier(handle, dbs, depstring.str)
511 return if res == unsafe { nil } { none } else { res }
512}
513
514pub fn (handle &Handle) checkconflicts(pkglist &List) &List {
515 return C.oracle_alpm_checkconflicts(handle, pkglist)
516}
517
518// preserve the public pointer layout until packages and lists are native too.
519// libc owns these buffers so existing callers can still pass them to C libalpm.
520pub fn (dep &Depend) compute_string() string {
521 text := C.oracle_alpm_dep_compute_string(dep)
522 if text == unsafe { nil } { return '' }
523 defer { C.free(text) }
524 return unsafe { cstring_to_vstring(text) }
525}
526
527fn C.oracle_alpm_dep_compute_string(&Depend) &u8
528fn C.oracle_alpm_dep_from_string(&u8) &Depend
529fn C.oracle_alpm_dep_free(&Depend)
530
531pub fn dep_from_string(depstring string) &Depend {
532 return C.oracle_alpm_dep_from_string(depstring.str)
533}
534
535pub fn (dep &Depend) free() {
536 if dep == unsafe { nil } { return }
537 C.oracle_alpm_dep_free(dep)
538}
539
540pub fn (conflict &FileConflict) free() {
541 if conflict == unsafe { nil } { return }
542 C.free(conflict.ctarget)
543 C.free(conflict.file)
544 C.free(conflict.target)
545 C.free(conflict)
546}
547
548pub fn (miss &DepMissing) free() {
549 if miss == unsafe { nil } { return }
550 miss.depend.free()
551 C.free(miss.target)
552 C.free(miss.causingpkg)
553 C.free(miss)
554}
555
556pub fn (conflict &Conflict) free() {
557 C.oracle_alpm_conflict_free(conflict)
558}
559
560pub enum EventType {
561 checkdeps_start = 1
562 checkdeps_done
563 fileconflicts_start
564 fileconflicts_done
565 resolvedeps_start
566 resolvedeps_done
567 interconflicts_start
568 interconflicts_done
569 transaction_start
570 transaction_done
571 package_operation_start
572 package_operation_done
573 integrity_start
574 integrity_done
575 load_start
576 load_done
577 scriptlet_info
578 db_retrieve_start
579 db_retrieve_done
580 db_retrieve_failed
581 pkg_retrieve_start
582 pkg_retrieve_done
583 pkg_retrieve_failed
584 diskspace_start
585 diskspace_done
586 optdep_removal
587 database_missing
588 keyring_start
589 keyring_done
590 key_download_start
591 key_download_done
592 pacnew_created
593 pacsave_created
594 hook_start
595 hook_done
596 hook_run_start
597 hook_run_done
598}
599
600pub struct EventAny {
601 type_ EventType
602}
603
604pub enum PackageOperation {
605 install = 1
606 upgrade
607 reinstall
608 downgrade
609 remove
610}
611
612pub struct EventPackageOperation {
613pub mut:
614 type_ EventType
615 operation PackageOperation
616 oldpkg &Package = unsafe { nil }
617 newpkg &Package = unsafe { nil }
618}
619
620pub struct EventOptDepRemoval {
621pub mut:
622 type_ EventType
623 pkg &Package = unsafe { nil }
624 optdep &Depend = unsafe { nil }
625}
626
627pub struct EventScriptletInfo {
628pub mut:
629 type_ EventType
630 line &u8 = unsafe { nil }
631}
632
633pub struct EventDatabaseMissing {
634pub mut:
635 type_ EventType
636 dbname &u8 = unsafe { nil }
637}
638
639pub struct EventPkgDownload {
640pub mut:
641 type_ EventType
642 file &u8 = unsafe { nil }
643}
644
645pub struct EventPacnewCreated {
646pub mut:
647 type_ EventType
648 from_noupgrade i32
649 oldpkg &Package = unsafe { nil }
650 newpkg &Package = unsafe { nil }
651 file &u8 = unsafe { nil }
652}
653
654pub struct EventPacsaveCreated {
655pub mut:
656 type_ EventType
657 oldpkg &Package = unsafe { nil }
658 file &u8 = unsafe { nil }
659}
660
661pub enum HookWhen {
662 pre_transaction = 1
663 post_transaction
664}
665
666pub struct EventHook {
667pub mut:
668 type_ EventType
669 when HookWhen
670}
671
672pub struct EventHookRun {
673pub mut:
674 type_ EventType
675 name &u8 = unsafe { nil }
676 desc &u8 = unsafe { nil }
677 position uint
678 total uint
679}
680
681pub struct EventPkgRetrieve {
682pub mut:
683 type_ EventType
684 num uint
685 total_size i64
686}
687
688union Event {
689pub mut:
690 type_ EventType
691 any EventAny
692 package_operation EventPackageOperation
693 optdep_removal EventOptDepRemoval
694 scriptlet_info EventScriptletInfo
695 database_missing EventDatabaseMissing
696 pkgdownload EventPkgDownload
697 pacnew_created EventPacnewCreated
698 pacsave_created EventPacsaveCreated
699 hook EventHook
700 hook_run EventHookRun
701 pkg_retrieve EventPkgRetrieve
702}
703
704type CbEvent = fn (voidptr, &Event)
705
706pub enum QuestionType {
707 install_ignorepkg = 1 << 0
708 replace_pkg = 1 << 1
709 conflict_pkg = 1 << 2
710 corrupted_pkg = 1 << 3
711 remove_pkgs = 1 << 4
712 select_provider = 1 << 5
713 import_key = 1 << 6
714}
715
716pub struct QuestionAny {
717pub mut:
718 type_ QuestionType
719 answer i32
720}
721
722pub struct QuestionInstallIgnorePkg {
723pub mut:
724 type_ QuestionType
725 install i32
726 pkg &Package = unsafe { nil }
727}
728
729pub struct QuestionReplace {
730pub mut:
731 type_ QuestionType
732 replace i32
733 oldpkg &Package = unsafe { nil }
734 newpkg &Package = unsafe { nil }
735 newdb &DB = unsafe { nil }
736}
737
738pub struct QuestionConflict {
739pub mut:
740 type_ QuestionType
741 remove_ i32
742 conflict &Conflict = unsafe { nil }
743}
744
745pub struct QuestionCorrupted {
746pub mut:
747 type_ QuestionType
748 remove_ i32
749 filepath &u8 = unsafe { nil }
750 reason Errno
751}
752
753pub struct QuestionRemovePkgs {
754pub mut:
755 type_ QuestionType
756 skip i32
757 packages &List = unsafe { nil }
758}
759
760pub struct QuestionSelectProvider {
761pub mut:
762 type_ QuestionType
763 use_index i32
764 providers &List = unsafe { nil }
765 depend &Depend = unsafe { nil }
766}
767
768pub struct QuestionImportKey {
769pub mut:
770 type_ QuestionType
771 import_ i32
772 uid &u8 = unsafe { nil }
773 fingerprint &u8 = unsafe { nil }
774}
775
776union Question {
777pub mut:
778 type_ QuestionType
779 any QuestionAny
780 install_ignorepkg QuestionInstallIgnorePkg
781 replace QuestionReplace
782 conflict QuestionConflict
783 corrupted QuestionCorrupted
784 remove_pkgs QuestionRemovePkgs
785 select_provider QuestionSelectProvider
786 import_key QuestionImportKey
787}
788
789type CbQuestion = fn (voidptr, &Question)
790
791pub enum Progress {
792 add_start
793 upgrade_start
794 downgrade_start
795 reinstall_start
796 remove_start
797 conflicts_start
798 diskspace_start
799 integrity_start
800 load_start
801 keyring_start
802}
803
804type CbProgress = fn (voidptr, Progress, &u8, i32, uint, uint)
805
806pub enum DownloadEventType {
807 init
808 progress
809 retry
810 completed
811}
812
813pub struct DownloadEventInit {
814pub mut:
815 optional i32
816}
817
818pub struct DownloadEventProgress {
819pub mut:
820 downloaded i64
821 total i64
822}
823
824pub struct DownloadEventRetry {
825pub mut:
826 resume i32
827}
828
829pub struct DownloadEventCompleted {
830pub mut:
831 total i64
832 result i32
833}
834
835type CbDownload = fn (voidptr, &u8, DownloadEventType, voidptr)
836type CbFetch = fn (voidptr, &u8, &u8, i32) i32
837
838fn C.oracle_alpm_get_localdb(handle &Handle) &DB
839
840fn C.oracle_alpm_get_syncdbs(handle &Handle) &List
841
842fn C.oracle_alpm_register_syncdb(handle &Handle, treename &u8, level int) &DB
843
844fn C.oracle_alpm_unregister_all_syncdbs(handle &Handle) int
845
846fn C.oracle_alpm_db_unregister(db &DB) int
847
848fn C.oracle_alpm_db_get_handle(db &DB) &Handle
849
850fn C.oracle_alpm_db_get_name(db &DB) &u8
851
852fn C.oracle_alpm_db_get_siglevel(db &DB) int
853
854fn C.oracle_alpm_db_get_valid(db &DB) int
855
856fn C.oracle_alpm_db_get_servers(db &DB) &List
857
858fn C.oracle_alpm_db_set_servers(db &DB, servers &List) int
859
860fn C.oracle_alpm_db_add_server(db &DB, url &u8) int
861
862fn C.oracle_alpm_db_remove_server(db &DB, url &u8) int
863
864fn C.oracle_alpm_db_get_cache_servers(db &DB) &List
865
866fn C.oracle_alpm_db_set_cache_servers(db &DB, servers &List) int
867
868fn C.oracle_alpm_db_add_cache_server(db &DB, url &u8) int
869
870fn C.oracle_alpm_db_remove_cache_server(db &DB, url &u8) int
871
872fn C.oracle_alpm_db_update(handle &Handle, dbs &List, force int) int
873
874fn C.oracle_alpm_db_get_pkg(db &DB, name &u8) &Package
875
876fn C.oracle_alpm_db_get_pkgcache(db &DB) &List
877
878fn C.oracle_alpm_db_get_group(db &DB, name &u8) &Group
879
880fn C.oracle_alpm_db_get_groupcache(db &DB) &List
881
882fn C.oracle_alpm_db_search(db &DB, needles &List, ret &&List) int
883
884pub fn (handle &Handle) get_localdb() !&DB {
885 mut out := C.oracle_alpm_get_localdb(handle)
886 return if out == unsafe { nil } { handle.error() } else { out }
887}
888
889pub fn (handle &Handle) get_syncdbs() !&List {
890 mut out := C.oracle_alpm_get_syncdbs(handle)
891 return if out == unsafe { nil } { handle.error() } else { out }
892}
893
894pub fn (handle &Handle) register_syncdb(treename string, level int) !&DB {
895 mut out := C.oracle_alpm_register_syncdb(handle, treename.str, level)
896 return if out == unsafe { nil } { handle.error() } else { out }
897}
898
899pub fn (handle &Handle) unregister_all_syncdbs() ! {
900 if C.oracle_alpm_unregister_all_syncdbs(handle) != 0 {
901 return handle.error()
902 }
903}
904
905pub fn (db &DB) unregister() ! {
906 if C.oracle_alpm_db_unregister(db) != 0 {
907 return db.get_handle().error()
908 }
909}
910
911pub fn (db &DB) get_handle() &Handle {
912 return C.oracle_alpm_db_get_handle(db)
913}
914
915pub fn (db &DB) get_name() string {
916 return unsafe { C.oracle_alpm_db_get_name(db).vstring() }
917}
918
919pub fn (db &DB) get_siglevel() SigLevel {
920 return unsafe { SigLevel(C.oracle_alpm_db_get_siglevel(db)) }
921}
922
923pub fn (db &DB) get_valid() !bool {
924 return if C.oracle_alpm_db_get_valid(db) == 0 {
925 true
926 } else {
927 db.get_handle().error()
928 }
929}
930
931pub fn (db &DB) get_servers() &List {
932 return C.oracle_alpm_db_get_servers(db)
933}
934
935pub fn (db &DB) set_servers(servers &List) ! {
936 if C.oracle_alpm_db_set_servers(db, servers) != 0 {
937 return db.get_handle().error()
938 }
939}
940
941pub fn (db &DB) add_server(url string) ! {
942 if C.oracle_alpm_db_add_server(db, url.str) != 0 {
943 return db.get_handle().error()
944 }
945}
946
947pub fn (db &DB) remove_server(url string) ! {
948 if C.oracle_alpm_db_remove_server(db, url.str) != 0 {
949 return db.get_handle().error()
950 }
951}
952
953pub fn (db &DB) get_cache_servers() ?&List {
954 out := C.oracle_alpm_db_get_cache_servers(db)
955 return if out == unsafe { nil } { none } else { out }
956}
957
958pub fn (db &DB) set_cache_servers(servers &List) ! {
959 if C.oracle_alpm_db_set_cache_servers(db, servers) != 0 {
960 return db.get_handle().error()
961 }
962}
963
964pub fn (db &DB) add_cache_server(url string) ! {
965 if C.oracle_alpm_db_add_cache_server(db, url.str) != 0 {
966 return db.get_handle().error()
967 }
968}
969
970pub fn (db &DB) remove_cache_server(url string) ! {
971 if C.oracle_alpm_db_remove_cache_server(db, url.str) != 0 {
972 return db.get_handle().error()
973 }
974}
975
976// db_update updates the sync dbs. it answers whether anything was downloaded:
977// libalpm returns 0 after a download, 1 when the dbs are all current (only
978// possible without force, an "up to date" answer) and -1 on error. the up to
979// date case is a success, not an error
980pub fn (handle &Handle) db_update(dbs &List, force bool) !bool {
981 ret := C.oracle_alpm_db_update(handle, dbs, int(force))
982 return if ret < 0 {
983 handle.error()
984 } else {
985 ret == 0
986 }
987}
988
989pub fn (db &DB) get_pkg(name string) ?&Package {
990 out := C.oracle_alpm_db_get_pkg(db, name.str)
991 return if out == unsafe { nil } { none } else { out }
992}
993
994pub fn (db &DB) get_pkgcache() ?&List {
995 out := C.oracle_alpm_db_get_pkgcache(db)
996 return if out == unsafe { nil } { none } else { out }
997}
998
999pub fn (db &DB) get_group(name string) ?&Group {
1000 out := C.oracle_alpm_db_get_group(db, name.str)
1001 return if out == unsafe { nil } { none } else { out }
1002}
1003
1004pub fn (db &DB) get_groupcache() ?&List {
1005 out := C.oracle_alpm_db_get_groupcache(db)
1006 return if out == unsafe { nil } { none } else { out }
1007}
1008
1009pub fn (db &DB) search(needles &List) !&List {
1010 mut out := &List(unsafe { nil })
1011 if C.oracle_alpm_db_search(db, needles, &out) != 0 {
1012 return db.get_handle().error()
1013 }
1014 return out
1015}
1016
1017// bit positions, as for SigLevel
1018@[flag]
1019pub enum DBUsage {
1020 sync = 0
1021 search = 1
1022 install = 2
1023 upgrade = 3
1024}
1025
1026// db_usage_all is ALPM_DB_USAGE_ALL. a flag enum member is one bit, so the
1027// four together are a constant
1028pub const db_usage_all = DBUsage.sync | .search | .install | .upgrade
1029
1030fn C.oracle_alpm_db_set_usage(db &DB, usage int) int
1031
1032pub fn (db &DB) set_usage(usage DBUsage) ! {
1033 if C.oracle_alpm_db_set_usage(db, int(usage)) != 0 {
1034 return db.get_handle().error()
1035 }
1036}
1037
1038fn C.oracle_alpm_db_get_usage(db &DB, usage &int) int
1039
1040pub fn (db &DB) get_usage() ?DBUsage {
1041 mut usage := int(0)
1042 return if C.oracle_alpm_db_get_usage(db, &usage) != -0 {
1043 none
1044 } else {
1045 DBUsage.from(usage) or { none }
1046 }
1047}
1048
1049// bit positions, as for SigLevel
1050@[flag]
1051pub enum LogLevel {
1052 error = 0
1053 warning = 1
1054 debug = 2
1055 function = 3
1056}
1057
1058type CbLog = fn (voidptr, LogLevel, &u8, voidptr)
1059
1060@[c2v_variadic]
1061fn C.oracle_alpm_logaction(handle &Handle, prefix &u8, fmt &u8) int
1062
1063fn C.oracle_alpm_option_get_logcb(handle &Handle) CbLog
1064
1065fn C.oracle_alpm_option_get_logcb_ctx(handle &Handle) voidptr
1066
1067fn C.oracle_alpm_option_set_logcb(handle &Handle, cb CbLog, ctx voidptr) int
1068
1069fn C.oracle_alpm_option_get_dlcb(handle &Handle) CbDownload
1070
1071fn C.oracle_alpm_option_get_dlcb_ctx(handle &Handle) voidptr
1072
1073fn C.oracle_alpm_option_set_dlcb(handle &Handle, cb CbDownload, ctx voidptr) int
1074
1075fn C.oracle_alpm_option_get_fetchcb(handle &Handle) CbFetch
1076
1077fn C.oracle_alpm_option_get_fetchcb_ctx(handle &Handle) voidptr
1078
1079fn C.oracle_alpm_option_set_fetchcb(handle &Handle, cb CbFetch, ctx voidptr) int
1080
1081fn C.oracle_alpm_option_get_eventcb(handle &Handle) CbEvent
1082
1083fn C.oracle_alpm_option_get_eventcb_ctx(handle &Handle) voidptr
1084
1085fn C.oracle_alpm_option_set_eventcb(handle &Handle, cb CbEvent, ctx voidptr) int
1086
1087fn C.oracle_alpm_option_get_questioncb(handle &Handle) CbQuestion
1088
1089fn C.oracle_alpm_option_get_questioncb_ctx(handle &Handle) voidptr
1090
1091fn C.oracle_alpm_option_set_questioncb(handle &Handle, cb CbQuestion, ctx voidptr) int
1092
1093fn C.oracle_alpm_option_get_progresscb(handle &Handle) CbProgress
1094
1095fn C.oracle_alpm_option_get_progresscb_ctx(handle &Handle) voidptr
1096
1097fn C.oracle_alpm_option_set_progresscb(handle &Handle, cb CbProgress, ctx voidptr) int
1098
1099fn C.oracle_alpm_option_get_root(handle &Handle) &u8
1100
1101fn C.oracle_alpm_option_get_dbpath(handle &Handle) &u8
1102
1103fn C.oracle_alpm_option_get_lockfile(handle &Handle) &u8
1104
1105fn C.oracle_alpm_option_get_cachedirs(handle &Handle) &List
1106
1107fn C.oracle_alpm_option_set_cachedirs(handle &Handle, cachedirs &List) int
1108
1109fn C.oracle_alpm_option_add_cachedir(handle &Handle, cachedir &u8) int
1110
1111fn C.oracle_alpm_option_remove_cachedir(handle &Handle, cachedir &u8) int
1112
1113fn C.oracle_alpm_option_get_hookdirs(handle &Handle) &List
1114
1115fn C.oracle_alpm_option_set_hookdirs(handle &Handle, hookdirs &List) int
1116
1117fn C.oracle_alpm_option_add_hookdir(handle &Handle, hookdir &u8) int
1118
1119fn C.oracle_alpm_option_remove_hookdir(handle &Handle, hookdir &u8) int
1120
1121fn C.oracle_alpm_option_get_overwrite_files(handle &Handle) &List
1122
1123fn C.oracle_alpm_option_set_overwrite_files(handle &Handle, globs &List) int
1124
1125fn C.oracle_alpm_option_add_overwrite_file(handle &Handle, glob &u8) int
1126
1127fn C.oracle_alpm_option_remove_overwrite_file(handle &Handle, glob &u8) int
1128
1129fn C.oracle_alpm_option_get_logfile(handle &Handle) &u8
1130
1131fn C.oracle_alpm_option_set_logfile(handle &Handle, logfile &u8) int
1132
1133fn C.oracle_alpm_option_get_gpgdir(handle &Handle) &u8
1134
1135fn C.oracle_alpm_option_set_gpgdir(handle &Handle, gpgdir &u8) int
1136
1137fn C.oracle_alpm_option_get_sandboxuser(handle &Handle) &u8
1138
1139fn C.oracle_alpm_option_set_sandboxuser(handle &Handle, sandboxuser &u8) int
1140
1141fn C.oracle_alpm_option_get_usesyslog(handle &Handle) int
1142
1143fn C.oracle_alpm_option_set_usesyslog(handle &Handle, usesyslog int) int
1144
1145fn C.oracle_alpm_option_get_noupgrades(handle &Handle) &List
1146
1147fn C.oracle_alpm_option_add_noupgrade(handle &Handle, path &u8) int
1148
1149fn C.oracle_alpm_option_set_noupgrades(handle &Handle, noupgrade &List) int
1150
1151fn C.oracle_alpm_option_remove_noupgrade(handle &Handle, path &u8) int
1152
1153fn C.oracle_alpm_option_match_noupgrade(handle &Handle, path &u8) int
1154
1155fn C.oracle_alpm_option_get_noextracts(handle &Handle) &List
1156
1157fn C.oracle_alpm_option_add_noextract(handle &Handle, path &u8) int
1158
1159fn C.oracle_alpm_option_set_noextracts(handle &Handle, noextract &List) int
1160
1161fn C.oracle_alpm_option_remove_noextract(handle &Handle, path &u8) int
1162
1163fn C.oracle_alpm_option_match_noextract(handle &Handle, path &u8) int
1164
1165fn C.oracle_alpm_option_get_ignorepkgs(handle &Handle) &List
1166
1167fn C.oracle_alpm_option_add_ignorepkg(handle &Handle, pkg &u8) int
1168
1169fn C.oracle_alpm_option_set_ignorepkgs(handle &Handle, ignorepkgs &List) int
1170
1171fn C.oracle_alpm_option_remove_ignorepkg(handle &Handle, pkg &u8) int
1172
1173fn C.oracle_alpm_option_get_ignoregroups(handle &Handle) &List
1174
1175fn C.oracle_alpm_option_add_ignoregroup(handle &Handle, grp &u8) int
1176
1177fn C.oracle_alpm_option_set_ignoregroups(handle &Handle, ignoregrps &List) int
1178
1179fn C.oracle_alpm_option_remove_ignoregroup(handle &Handle, grp &u8) int
1180
1181fn C.oracle_alpm_option_get_assumeinstalled(handle &Handle) &List
1182
1183fn C.oracle_alpm_option_add_assumeinstalled(handle &Handle, dep &Depend) int
1184
1185fn C.oracle_alpm_option_set_assumeinstalled(handle &Handle, deps &List) int
1186
1187fn C.oracle_alpm_option_remove_assumeinstalled(handle &Handle, dep &Depend) int
1188
1189fn C.oracle_alpm_option_get_architectures(handle &Handle) &List
1190
1191fn C.oracle_alpm_option_add_architecture(handle &Handle, arch &u8) int
1192
1193fn C.oracle_alpm_option_set_architectures(handle &Handle, arches &List) int
1194
1195fn C.oracle_alpm_option_remove_architecture(handle &Handle, arch &u8) int
1196
1197fn C.oracle_alpm_option_get_checkspace(handle &Handle) int
1198
1199fn C.oracle_alpm_option_set_checkspace(handle &Handle, checkspace int) int
1200
1201fn C.oracle_alpm_option_get_dbext(handle &Handle) &u8
1202
1203fn C.oracle_alpm_option_set_dbext(handle &Handle, dbext &u8) int
1204
1205fn C.oracle_alpm_option_get_default_siglevel(handle &Handle) int
1206
1207fn C.oracle_alpm_option_set_default_siglevel(handle &Handle, level int) int
1208
1209fn C.oracle_alpm_option_get_local_file_siglevel(handle &Handle) int
1210
1211fn C.oracle_alpm_option_set_local_file_siglevel(handle &Handle, level int) int
1212
1213fn C.oracle_alpm_option_get_remote_file_siglevel(handle &Handle) int
1214
1215fn C.oracle_alpm_option_set_remote_file_siglevel(handle &Handle, level int) int
1216
1217fn C.oracle_alpm_option_get_disable_dl_timeout(handle &Handle) int
1218
1219fn C.oracle_alpm_option_set_disable_dl_timeout(handle &Handle, disable_dl_timeout u16) int
1220
1221fn C.oracle_alpm_option_get_parallel_downloads(handle &Handle) int
1222
1223fn C.oracle_alpm_option_set_parallel_downloads(handle &Handle, num_streams u32) int
1224
1225fn C.oracle_alpm_option_get_disable_sandbox_filesystem(handle &Handle) int
1226
1227fn C.oracle_alpm_option_set_disable_sandbox_filesystem(handle &Handle, disable_sandbox_filesystem u16) int
1228
1229fn C.oracle_alpm_option_set_disable_sandbox_syscalls(handle &Handle, disable_sandbox_syscalls u16) int
1230
1231fn C.oracle_alpm_option_get_disable_sandbox_syscalls(handle &Handle) int
1232
1233pub fn (handle &Handle) log_action(prefix string, fmt string) ! {
1234 if C.oracle_alpm_logaction(handle, prefix.str, fmt.str) != 0 {
1235 return handle.error()
1236 }
1237}
1238
1239pub fn (handle &Handle) option_get_logcb() CbLog {
1240 return C.oracle_alpm_option_get_logcb(handle)
1241}
1242
1243pub fn (handle &Handle) option_get_logcb_ctx() voidptr {
1244 return C.oracle_alpm_option_get_logcb_ctx(handle)
1245}
1246
1247pub fn (handle &Handle) option_set_logcb(cb CbLog, ctx voidptr) ! {
1248 if C.oracle_alpm_option_set_logcb(handle, cb, ctx) != 0 {
1249 return handle.error()
1250 }
1251}
1252
1253pub fn (handle &Handle) option_get_dlcb() CbDownload {
1254 return C.oracle_alpm_option_get_dlcb(handle)
1255}
1256
1257pub fn (handle &Handle) option_get_dlcb_ctx() voidptr {
1258 return C.oracle_alpm_option_get_dlcb_ctx(handle)
1259}
1260
1261pub fn (handle &Handle) option_set_dlcb(cb CbDownload, ctx voidptr) ! {
1262 if C.oracle_alpm_option_set_dlcb(handle, cb, ctx) != 0 {
1263 return handle.error()
1264 }
1265}
1266
1267pub fn (handle &Handle) option_get_fetchcb() CbFetch {
1268 return C.oracle_alpm_option_get_fetchcb(handle)
1269}
1270
1271pub fn (handle &Handle) get_fetchcb_ctx() voidptr {
1272 return C.oracle_alpm_option_get_fetchcb_ctx(handle)
1273}
1274
1275pub fn (handle &Handle) option_set_fetchcb(cb CbFetch, ctx voidptr) ! {
1276 if C.oracle_alpm_option_set_fetchcb(handle, cb, ctx) != 0 {
1277 return handle.error()
1278 }
1279}
1280
1281pub fn (handle &Handle) option_get_eventcb() CbEvent {
1282 return C.oracle_alpm_option_get_eventcb(handle)
1283}
1284
1285pub fn (handle &Handle) option_get_eventcb_ctx() voidptr {
1286 return C.oracle_alpm_option_get_eventcb_ctx(handle)
1287}
1288
1289pub fn (handle &Handle) option_set_eventcb(cb CbEvent, ctx voidptr) ! {
1290 if C.oracle_alpm_option_set_eventcb(handle, cb, ctx) != 0 {
1291 return handle.error()
1292 }
1293}
1294
1295pub fn (handle &Handle) option_get_questioncb() CbQuestion {
1296 return C.oracle_alpm_option_get_questioncb(handle)
1297}
1298
1299pub fn (handle &Handle) option_get_questioncb_ctx() voidptr {
1300 return C.oracle_alpm_option_get_questioncb_ctx(handle)
1301}
1302
1303pub fn (handle &Handle) option_set_questioncb(cb CbQuestion, ctx voidptr) ! {
1304 if C.oracle_alpm_option_set_questioncb(handle, cb, ctx) != 0 {
1305 return handle.error()
1306 }
1307}
1308
1309pub fn (handle &Handle) option_get_progresscb() CbProgress {
1310 return C.oracle_alpm_option_get_progresscb(handle)
1311}
1312
1313pub fn (handle &Handle) option_get_progresscb_ctx() voidptr {
1314 return C.oracle_alpm_option_get_progresscb_ctx(handle)
1315}
1316
1317pub fn (handle &Handle) option_set_progresscb(cb CbProgress, ctx voidptr) ! {
1318 if C.oracle_alpm_option_set_progresscb(handle, cb, ctx) != 0 {
1319 return handle.error()
1320 }
1321}
1322
1323pub fn (handle &Handle) option_get_root() string {
1324 return unsafe { C.oracle_alpm_option_get_root(handle).vstring() }
1325}
1326
1327pub fn (handle &Handle) option_get_dbpath() string {
1328 return unsafe { C.oracle_alpm_option_get_dbpath(handle).vstring() }
1329}
1330
1331pub fn (handle &Handle) option_get_lockfile() string {
1332 return unsafe { C.oracle_alpm_option_get_lockfile(handle).vstring() }
1333}
1334
1335pub fn (handle &Handle) option_get_cachedirs() &List {
1336 return C.oracle_alpm_option_get_cachedirs(handle)
1337}
1338
1339pub fn (handle &Handle) option_set_cachedirs(cachedirs &List) ! {
1340 if C.oracle_alpm_option_set_cachedirs(handle, cachedirs) != 0 {
1341 return handle.error()
1342 }
1343}
1344
1345pub fn (handle &Handle) option_add_cachedir(cachedir string) ! {
1346 if C.oracle_alpm_option_add_cachedir(handle, cachedir.str) != 0 {
1347 return handle.error()
1348 }
1349}
1350
1351pub fn (handle &Handle) option_remove_cachedir(cachedir string) ! {
1352 if C.oracle_alpm_option_remove_cachedir(handle, cachedir.str) < 0 {
1353 return handle.error()
1354 }
1355}
1356
1357pub fn (handle &Handle) option_get_hookdirs() ?&List {
1358 return C.oracle_alpm_option_get_hookdirs(handle)
1359}
1360
1361pub fn (handle &Handle) option_set_hookdirs(hookdirs &List) ! {
1362 if C.oracle_alpm_option_set_hookdirs(handle, hookdirs) != 0 {
1363 return handle.error()
1364 }
1365}
1366
1367pub fn (handle &Handle) option_add_hookdir(hookdir string) ! {
1368 if C.oracle_alpm_option_add_hookdir(handle, hookdir.str) != 0 {
1369 return handle.error()
1370 }
1371}
1372
1373pub fn (handle &Handle) option_remove_hookdir(hookdir string) ! {
1374 if C.oracle_alpm_option_remove_hookdir(handle, hookdir.str) < 0 {
1375 return handle.error()
1376 }
1377}
1378
1379pub fn (handle &Handle) option_get_overwrite_files() &List {
1380 return C.oracle_alpm_option_get_overwrite_files(handle)
1381}
1382
1383pub fn (handle &Handle) option_set_overwrite_files(globs &List) ! {
1384 if C.oracle_alpm_option_set_overwrite_files(handle, globs) != 0 {
1385 return handle.error()
1386 }
1387}
1388
1389pub fn (handle &Handle) option_add_overwrite_file(glob string) ! {
1390 if C.oracle_alpm_option_add_overwrite_file(handle, glob.str) != 0 {
1391 return handle.error()
1392 }
1393}
1394
1395pub fn (handle &Handle) option_remove_overwrite_file(glob string) ! {
1396 if C.oracle_alpm_option_remove_overwrite_file(handle, glob.str) < 0 {
1397 return handle.error()
1398 }
1399}
1400
1401pub fn (handle &Handle) option_get_logfile() string {
1402 return unsafe { C.oracle_alpm_option_get_logfile(handle).vstring() }
1403}
1404
1405pub fn (handle &Handle) option_set_logfile(logfile string) ! {
1406 if C.oracle_alpm_option_set_logfile(handle, logfile.str) != 0 {
1407 return handle.error()
1408 }
1409}
1410
1411pub fn (handle &Handle) option_get_gpgdir() string {
1412 return unsafe { C.oracle_alpm_option_get_gpgdir(handle).vstring() }
1413}
1414
1415pub fn (handle &Handle) option_set_gpgdir(gpgdir string) ! {
1416 if C.oracle_alpm_option_set_gpgdir(handle, gpgdir.str) != 0 {
1417 return handle.error()
1418 }
1419}
1420
1421pub fn (handle &Handle) option_get_sandboxuser() string {
1422 return unsafe { C.oracle_alpm_option_get_sandboxuser(handle).vstring() }
1423}
1424
1425pub fn (handle &Handle) option_set_sandboxuser(sandboxuser string) ! {
1426 if C.oracle_alpm_option_set_sandboxuser(handle, sandboxuser.str) != 0 {
1427 return handle.error()
1428 }
1429}
1430
1431pub fn (handle &Handle) option_get_usesyslog() bool {
1432 return if C.oracle_alpm_option_get_usesyslog(handle) == 0 { false } else { true }
1433}
1434
1435pub fn (handle &Handle) option_set_usesyslog(usesyslog int) ! {
1436 if C.oracle_alpm_option_set_usesyslog(handle, usesyslog) != 0 {
1437 return handle.error()
1438 }
1439}
1440
1441pub fn (handle &Handle) option_get_noupgrades() &List {
1442 return C.oracle_alpm_option_get_noupgrades(handle)
1443}
1444
1445pub fn (handle &Handle) option_add_noupgrade(path string) ! {
1446 if C.oracle_alpm_option_add_noupgrade(handle, path.str) != 0 {
1447 return handle.error()
1448 }
1449}
1450
1451pub fn (handle &Handle) option_set_noupgrades(noupgrade &List) ! {
1452 if C.oracle_alpm_option_set_noupgrades(handle, noupgrade) != 0 {
1453 return handle.error()
1454 }
1455}
1456
1457pub fn (handle &Handle) option_remove_noupgrade(path string) ! {
1458 if C.oracle_alpm_option_remove_noupgrade(handle, path.str) < 0 {
1459 return handle.error()
1460 }
1461}
1462
1463pub fn (handle &Handle) option_match_no_upgrade(path string) bool {
1464 return if C.oracle_alpm_option_match_noupgrade(handle, path.str) == 0 { true } else { false }
1465}
1466
1467pub fn (handle &Handle) option_get_no_extracts() &List {
1468 return C.oracle_alpm_option_get_noextracts(handle)
1469}
1470
1471pub fn (handle &Handle) option_add_no_extract(path string) ! {
1472 if C.oracle_alpm_option_add_noextract(handle, path.str) != 0 {
1473 return handle.error()
1474 }
1475}
1476
1477pub fn (handle &Handle) option_set_no_extracts(noextract &List) ! {
1478 if C.oracle_alpm_option_set_noextracts(handle, noextract) != 0 {
1479 return handle.error()
1480 }
1481}
1482
1483pub fn (handle &Handle) option_remove_no_extract(path string) ! {
1484 if C.oracle_alpm_option_remove_noextract(handle, path.str) < 0 {
1485 return handle.error()
1486 }
1487}
1488
1489pub fn (handle &Handle) option_match_no_extract(path string) bool {
1490 return if C.oracle_alpm_option_match_noextract(handle, path.str) == 0 { true } else { false }
1491}
1492
1493pub fn (handle &Handle) option_get_ignore_pkgs() &List {
1494 return C.oracle_alpm_option_get_ignorepkgs(handle)
1495}
1496
1497pub fn (handle &Handle) option_add_ignore_pkg(pkg string) ! {
1498 if C.oracle_alpm_option_add_ignorepkg(handle, pkg.str) != 0 {
1499 return handle.error()
1500 }
1501}
1502
1503pub fn (handle &Handle) option_set_ignore_pkgs(ignorepkgs &List) ! {
1504 if C.oracle_alpm_option_set_ignorepkgs(handle, ignorepkgs) != 0 {
1505 return handle.error()
1506 }
1507}
1508
1509pub fn (handle &Handle) option_remove_ignore_pkg(pkg string) ! {
1510 if C.oracle_alpm_option_remove_ignorepkg(handle, pkg.str) < 0 {
1511 return handle.error()
1512 }
1513}
1514
1515pub fn (handle &Handle) option_get_ignore_groups() &List {
1516 return C.oracle_alpm_option_get_ignoregroups(handle)
1517}
1518
1519pub fn (handle &Handle) option_add_ignore_group(grp string) ! {
1520 if C.oracle_alpm_option_add_ignoregroup(handle, grp.str) != 0 {
1521 return handle.error()
1522 }
1523}
1524
1525pub fn (handle &Handle) option_set_ignore_groups(ignoregrps &List) ! {
1526 if C.oracle_alpm_option_set_ignoregroups(handle, ignoregrps) != 0 {
1527 return handle.error()
1528 }
1529}
1530
1531pub fn (handle &Handle) option_remove_ignore_group(grp string) ! {
1532 if C.oracle_alpm_option_remove_ignoregroup(handle, grp.str) < 0 {
1533 return handle.error()
1534 }
1535}
1536
1537pub fn option_get_assume_installed(handle &Handle) ?&List {
1538 out := C.oracle_alpm_option_get_assumeinstalled(handle)
1539 return if out == unsafe { nil } { none } else { out }
1540}
1541
1542pub fn (handle &Handle) option_add_assumeinstalled(dep &Depend) ! {
1543 if C.oracle_alpm_option_add_assumeinstalled(handle, dep) != 0 {
1544 return handle.error()
1545 }
1546}
1547
1548pub fn (handle &Handle) option_set_assumeinstalled(deps &List) ! {
1549 if C.oracle_alpm_option_set_assumeinstalled(handle, deps) != 0 {
1550 return handle.error()
1551 }
1552}
1553
1554pub fn (handle &Handle) option_remove_assumeinstalled(dep &Depend) ! {
1555 if C.oracle_alpm_option_remove_assumeinstalled(handle, dep) < 0 {
1556 return handle.error()
1557 }
1558}
1559
1560pub fn (handle &Handle) option_get_architectures() ?&List {
1561 out := C.oracle_alpm_option_get_architectures(handle)
1562 return if out == unsafe { nil } { none } else { out }
1563}
1564
1565pub fn (handle &Handle) option_add_architecture(architecture string) ! {
1566 if C.oracle_alpm_option_add_architecture(handle, architecture.str) != 0 {
1567 return handle.error()
1568 }
1569}
1570
1571pub fn (handle &Handle) option_set_architectures(arches &List) ! {
1572 if C.oracle_alpm_option_set_architectures(handle, arches) != 0 {
1573 return handle.error()
1574 }
1575}
1576
1577pub fn (handle &Handle) option_remove_architecture(architecture string) ! {
1578 if C.oracle_alpm_option_remove_architecture(handle, architecture.str) < 0 {
1579 return handle.error()
1580 }
1581}
1582
1583pub fn (handle &Handle) option_get_checkspace() bool {
1584 return if C.oracle_alpm_option_get_checkspace(handle) != 0 { true } else { false }
1585}
1586
1587pub fn (handle &Handle) option_set_checkspace(checkspace int) ! {
1588 if C.oracle_alpm_option_set_checkspace(handle, checkspace) != 0 {
1589 return handle.error()
1590 }
1591}
1592
1593pub fn (handle &Handle) option_get_dbext() string {
1594 return unsafe { C.oracle_alpm_option_get_dbext(handle).vstring() }
1595}
1596
1597pub fn (handle &Handle) option_set_dbext(dbext string) ! {
1598 if C.oracle_alpm_option_set_dbext(handle, dbext.str) != 0 {
1599 return handle.error()
1600 }
1601}
1602
1603pub fn (handle &Handle) option_get_default_siglevel() ?SigLevel {
1604 return SigLevel.from(C.oracle_alpm_option_get_default_siglevel(handle)) or { none }
1605}
1606
1607pub fn (handle &Handle) option_set_default_siglevel(level SigLevel) ! {
1608 if C.oracle_alpm_option_set_default_siglevel(handle, int(level)) != 0 {
1609 return handle.error()
1610 }
1611}
1612
1613pub fn (handle &Handle) option_get_local_file_siglevel() ?SigLevel {
1614 return SigLevel.from(C.oracle_alpm_option_get_local_file_siglevel(handle)) or { none }
1615}
1616
1617pub fn (handle &Handle) option_set_local_file_siglevel(level SigLevel) ! {
1618 if C.oracle_alpm_option_set_local_file_siglevel(handle, int(level)) != 0 {
1619 return handle.error()
1620 }
1621}
1622
1623pub fn (handle &Handle) option_get_remote_file_siglevel() ?SigLevel {
1624 return SigLevel.from(C.oracle_alpm_option_get_remote_file_siglevel(handle)) or { none }
1625}
1626
1627pub fn (handle &Handle) option_set_remote_file_siglevel(level SigLevel) ! {
1628 if C.oracle_alpm_option_set_remote_file_siglevel(handle, int(level)) != 0 {
1629 return handle.error()
1630 }
1631}
1632
1633pub fn (handle &Handle) option_get_disable_dl_timeout() bool {
1634 return if C.oracle_alpm_option_get_disable_dl_timeout(handle) != 0 { true } else { false }
1635}
1636
1637pub fn (handle &Handle) option_set_disable_dl_timeout(disable_dl_timeout u16) ! {
1638 if C.oracle_alpm_option_set_disable_dl_timeout(handle, disable_dl_timeout) != 0 {
1639 return handle.error()
1640 }
1641}
1642
1643pub fn (handle &Handle) option_get_parallel_downloads() int {
1644 return C.oracle_alpm_option_get_parallel_downloads(handle)
1645}
1646
1647pub fn (handle &Handle) option_set_parallel_downloads(num_streams u32) ! {
1648 if C.oracle_alpm_option_set_parallel_downloads(handle, num_streams) != 0 {
1649 return handle.error()
1650 }
1651}
1652
1653// the combined C symbols are not exported by the referenced libalpm build.
1654pub fn (handle &Handle) option_get_disable_sandbox() bool {
1655 return handle.option_get_disable_sandbox_filesystem() || handle.option_get_disable_sandbox_syscalls()
1656}
1657
1658pub fn (handle &Handle) option_set_disable_sandbox(disable_sandbox u16) ! {
1659 handle.option_set_disable_sandbox_filesystem(disable_sandbox)!
1660 handle.option_set_disable_sandbox_syscalls(disable_sandbox)!
1661}
1662
1663pub fn (handle &Handle) option_get_disable_sandbox_filesystem() bool {
1664 return if C.oracle_alpm_option_get_disable_sandbox_filesystem(handle) != 0 {
1665 true
1666 } else {
1667 false
1668 }
1669}
1670
1671pub fn (handle &Handle) option_set_disable_sandbox_filesystem(disable_sandbox_filesystem u16) ! {
1672 if C.oracle_alpm_option_set_disable_sandbox_filesystem(handle, disable_sandbox_filesystem) != 0 {
1673 return handle.error()
1674 }
1675}
1676
1677pub fn (handle &Handle) option_get_disable_sandbox_syscalls() bool {
1678 return if C.oracle_alpm_option_get_disable_sandbox_syscalls(handle) != 0 { true } else { false }
1679}
1680
1681pub fn (handle &Handle) option_set_disable_sandbox_syscalls(disable_sandbox_syscalls u16) ! {
1682 if C.oracle_alpm_option_set_disable_sandbox_syscalls(handle, disable_sandbox_syscalls) != 0 {
1683 return handle.error()
1684 }
1685}
1686
1687pub enum PackageReason {
1688 explicit = 0
1689 depend = 1
1690 unknown = 2
1691}
1692
1693pub enum PackageFrom {
1694 file = 1
1695 localdb
1696 syncdb
1697}
1698
1699pub enum PkgValidation {
1700 unknown = 0
1701 none = 1 << 0
1702 md5sum = 1 << 1
1703 sha256sum = 1 << 2
1704 signature = 1 << 3
1705}
1706
1707fn C.oracle_alpm_pkg_load(handle &Handle, filename &u8, full int, level int, pkg &&Package) int
1708
1709fn C.oracle_alpm_fetch_pkgurl(handle &Handle, urls &List, fetched &&List) int
1710
1711fn C.oracle_alpm_pkg_find(haystack &List, needle &u8) &Package
1712
1713fn C.oracle_alpm_pkg_free(pkg &Package) int
1714
1715fn C.oracle_alpm_pkg_checkmd5sum(pkg &Package) int
1716
1717fn C.oracle_alpm_pkg_compute_requiredby(pkg &Package) &List
1718
1719fn C.oracle_alpm_pkg_compute_optionalfor(pkg &Package) &List
1720
1721fn C.oracle_alpm_pkg_should_ignore(handle &Handle, pkg &Package) int
1722
1723fn C.oracle_alpm_pkg_get_handle(pkg &Package) &Handle
1724
1725fn C.oracle_alpm_pkg_get_filename(pkg &Package) &u8
1726
1727fn C.oracle_alpm_pkg_get_base(pkg &Package) &u8
1728
1729fn C.oracle_alpm_pkg_get_name(pkg &Package) &u8
1730
1731fn C.oracle_alpm_pkg_get_version(pkg &Package) &u8
1732
1733fn C.oracle_alpm_pkg_get_origin(pkg &Package) PackageFrom
1734
1735fn C.oracle_alpm_pkg_get_desc(pkg &Package) &u8
1736
1737fn C.oracle_alpm_pkg_get_url(pkg &Package) &u8
1738
1739fn C.oracle_alpm_pkg_get_builddate(pkg &Package) Time
1740
1741fn C.oracle_alpm_pkg_get_installdate(pkg &Package) Time
1742
1743fn C.oracle_alpm_pkg_get_packager(pkg &Package) &u8
1744
1745fn C.oracle_alpm_pkg_get_md5sum(pkg &Package) &u8
1746
1747fn C.oracle_alpm_pkg_get_sha256sum(pkg &Package) &u8
1748
1749fn C.oracle_alpm_pkg_get_arch(pkg &Package) &u8
1750
1751fn C.oracle_alpm_pkg_get_size(pkg &Package) i64
1752
1753fn C.oracle_alpm_pkg_get_isize(pkg &Package) i64
1754
1755fn C.oracle_alpm_pkg_get_reason(pkg &Package) PackageReason
1756
1757fn C.oracle_alpm_pkg_get_licenses(pkg &Package) &List
1758
1759fn C.oracle_alpm_pkg_get_groups(pkg &Package) &List
1760
1761fn C.oracle_alpm_pkg_get_depends(pkg &Package) &List
1762
1763fn C.oracle_alpm_pkg_get_optdepends(pkg &Package) &List
1764
1765fn C.oracle_alpm_pkg_get_checkdepends(pkg &Package) &List
1766
1767fn C.oracle_alpm_pkg_get_makedepends(pkg &Package) &List
1768
1769fn C.oracle_alpm_pkg_get_conflicts(pkg &Package) &List
1770
1771fn C.oracle_alpm_pkg_get_provides(pkg &Package) &List
1772
1773fn C.oracle_alpm_pkg_get_replaces(pkg &Package) &List
1774
1775fn C.oracle_alpm_pkg_get_files(pkg &Package) &Filelist
1776
1777fn C.oracle_alpm_pkg_get_backup(pkg &Package) &List
1778
1779fn C.oracle_alpm_pkg_get_db(pkg &Package) &DB
1780
1781fn C.oracle_alpm_pkg_get_base64_sig(pkg &Package) &u8
1782
1783fn C.oracle_alpm_pkg_get_sig(pkg &Package, sig &&u8, sig_len &uint) int
1784
1785fn C.oracle_alpm_pkg_get_validation(pkg &Package) PkgValidation
1786
1787fn C.oracle_alpm_pkg_get_xdata(pkg &Package) &List
1788
1789fn C.oracle_alpm_pkg_has_scriptlet(pkg &Package) int
1790
1791fn C.oracle_alpm_pkg_download_size(newpkg &Package) i64
1792
1793fn C.oracle_alpm_pkg_set_reason(pkg &Package, reason PackageReason) int
1794
1795fn C.oracle_alpm_pkg_changelog_open(pkg &Package) voidptr
1796
1797fn C.oracle_alpm_pkg_changelog_read(ptr voidptr, size uint, pkg &Package, fp voidptr) uint
1798
1799fn C.oracle_alpm_pkg_changelog_close(pkg &Package, fp voidptr) int
1800
1801fn C.oracle_alpm_pkg_mtree_open(pkg &Package) &C.Archive
1802
1803fn C.oracle_alpm_pkg_mtree_next(pkg &Package, archive &C.Archive, entry &&C.Archive_entry) int
1804
1805fn C.oracle_alpm_pkg_mtree_close(pkg &Package, archive &C.Archive) int
1806
1807pub fn (handle &Handle) pkg_load(filename string, full int, level int) !&Package {
1808 mut pkg := &Package{}
1809 if C.oracle_alpm_pkg_load(handle, filename.str, full, level, pkg) != 0 {
1810 return handle.error()
1811 }
1812 return pkg
1813}
1814
1815pub fn (handle &Handle) fetch_pkgurl(urls &List) !&List {
1816 // libalpm fills in the head of the output list, so it needs its address
1817 mut fetched := &List(unsafe { nil })
1818 if C.oracle_alpm_fetch_pkgurl(handle, urls, &fetched) != 0 {
1819 return handle.error()
1820 }
1821 return fetched
1822}
1823
1824pub fn (haystack &List) pkg_find(needle string) ?&Package {
1825 pkg := C.oracle_alpm_pkg_find(haystack, needle.str)
1826 return if pkg == unsafe { nil } { none } else { pkg }
1827}
1828
1829pub fn (pkg &Package) free_pkg() ! {
1830 if C.oracle_alpm_pkg_free(pkg) != 0 {
1831 return pkg.get_handle().error()
1832 }
1833}
1834
1835pub fn (pkg &Package) checkmd5sum() int {
1836 return C.oracle_alpm_pkg_checkmd5sum(pkg)
1837}
1838
1839pub fn pkg_vercmp(a string, b string) int {
1840 return C.oracle_alpm_pkg_vercmp(a.str, b.str)
1841}
1842
1843fn C.oracle_alpm_pkg_vercmp(&u8, &u8) int
1844
1845// the names of the packages that depend on this one, or that list it as an
1846// optional dependency: the local db answers for installed packages and every
1847// sync db for sync ones, as pacman's -Sii does. libalpm strdups the name
1848// list; every name is copied before the list and its strings are freed,
1849// since a V string from .vstring() points into memory this call frees
1850pub fn (pkg &Package) compute_required_by() []string {
1851 res := C.oracle_alpm_pkg_compute_requiredby(pkg)
1852 mut out := []string{}
1853 for cur := res; cur != unsafe { nil }; cur = cur.next {
1854 data := unsafe { &u8(cur.data) }
1855 if data != unsafe { nil } {
1856 out << unsafe { tos_clone(data) }
1857 }
1858 }
1859 defer {
1860 res.free_inner(fn (p voidptr) {
1861 unsafe { C.free(p) }
1862 })
1863 res.free()
1864 }
1865 return out
1866}
1867
1868pub fn (pkg &Package) compute_optional_for() []string {
1869 res := C.oracle_alpm_pkg_compute_optionalfor(pkg)
1870 mut out := []string{}
1871 for cur := res; cur != unsafe { nil }; cur = cur.next {
1872 data := unsafe { &u8(cur.data) }
1873 if data != unsafe { nil } {
1874 out << unsafe { tos_clone(data) }
1875 }
1876 }
1877 defer {
1878 res.free_inner(fn (p voidptr) {
1879 unsafe { C.free(p) }
1880 })
1881 res.free()
1882 }
1883 return out
1884}
1885
1886pub fn (handle &Handle) pkg_should_ignore(pkg &Package) int {
1887 return C.oracle_alpm_pkg_should_ignore(handle, pkg)
1888}
1889
1890pub fn (pkg &Package) get_handle() &Handle {
1891 return C.oracle_alpm_pkg_get_handle(pkg)
1892}
1893
1894@[inline]
1895fn cstring_to_vstring_or_none(s &u8) string {
1896 return if s == unsafe { nil } { '' } else { unsafe { cstring_to_vstring(s) } }
1897}
1898
1899pub fn (pkg &Package) get_filename() string {
1900 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_filename(pkg))
1901}
1902
1903pub fn (pkg &Package) get_base() string {
1904 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_base(pkg))
1905}
1906
1907pub fn (pkg &Package) get_name() string {
1908 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_name(pkg))
1909}
1910
1911pub fn (pkg &Package) get_version() string {
1912 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_version(pkg))
1913}
1914
1915pub fn (pkg &Package) get_origin() PackageFrom {
1916 return C.oracle_alpm_pkg_get_origin(pkg)
1917}
1918
1919pub fn (pkg &Package) get_desc() string {
1920 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_desc(pkg))
1921}
1922
1923pub fn (pkg &Package) get_url() string {
1924 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_url(pkg))
1925}
1926
1927pub fn (pkg &Package) get_build_date() Time {
1928 return C.oracle_alpm_pkg_get_builddate(pkg)
1929}
1930
1931pub fn (pkg &Package) get_install_date() Time {
1932 return C.oracle_alpm_pkg_get_installdate(pkg)
1933}
1934
1935pub fn (pkg &Package) get_packager() string {
1936 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_packager(pkg))
1937}
1938
1939pub fn (pkg &Package) get_md5_sum() string {
1940 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_md5sum(pkg))
1941}
1942
1943pub fn (pkg &Package) get_sha256_sum() string {
1944 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_sha256sum(pkg))
1945}
1946
1947pub fn (pkg &Package) get_arch() string {
1948 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_arch(pkg))
1949}
1950
1951pub fn (pkg &Package) get_size() i64 {
1952 return C.oracle_alpm_pkg_get_size(pkg)
1953}
1954
1955pub fn (pkg &Package) get_isize() i64 {
1956 return C.oracle_alpm_pkg_get_isize(pkg)
1957}
1958
1959pub fn (pkg &Package) get_reason() PackageReason {
1960 return C.oracle_alpm_pkg_get_reason(pkg)
1961}
1962
1963pub fn (pkg &Package) get_licenses() &List {
1964 return C.oracle_alpm_pkg_get_licenses(pkg)
1965}
1966
1967pub fn (pkg &Package) get_groups() &List {
1968 return C.oracle_alpm_pkg_get_groups(pkg)
1969}
1970
1971pub fn (pkg &Package) get_depends() &List {
1972 return C.oracle_alpm_pkg_get_depends(pkg)
1973}
1974
1975pub fn (pkg &Package) get_opt_depends() &List {
1976 return C.oracle_alpm_pkg_get_optdepends(pkg)
1977}
1978
1979pub fn (pkg &Package) get_check_depends() &List {
1980 return C.oracle_alpm_pkg_get_checkdepends(pkg)
1981}
1982
1983pub fn (pkg &Package) get_make_depends() &List {
1984 return C.oracle_alpm_pkg_get_makedepends(pkg)
1985}
1986
1987pub fn (pkg &Package) get_conflicts() &List {
1988 return C.oracle_alpm_pkg_get_conflicts(pkg)
1989}
1990
1991pub fn (pkg &Package) get_provides() &List {
1992 return C.oracle_alpm_pkg_get_provides(pkg)
1993}
1994
1995pub fn (pkg &Package) get_replaces() &List {
1996 return C.oracle_alpm_pkg_get_replaces(pkg)
1997}
1998
1999pub fn (pkg &Package) get_files() &Filelist {
2000 return C.oracle_alpm_pkg_get_files(pkg)
2001}
2002
2003pub fn (pkg &Package) get_backup() &List {
2004 return C.oracle_alpm_pkg_get_backup(pkg)
2005}
2006
2007pub fn (pkg &Package) get_db() !&DB {
2008 db := C.oracle_alpm_pkg_get_db(pkg)
2009 return if db == unsafe { nil } { error('db is NULL') } else { db }
2010}
2011
2012pub fn (pkg &Package) get_base64_sig() string {
2013 return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_base64_sig(pkg))
2014}
2015
2016pub fn (pkg &Package) get_sig(sig_len &uint) !&u8 {
2017 mut sig := &u8(unsafe { nil })
2018 if C.oracle_alpm_pkg_get_sig(pkg, sig, sig_len) != 0 {
2019 return pkg.get_handle().error()
2020 }
2021 return sig
2022}
2023
2024pub fn (pkg &Package) get_validation() PkgValidation {
2025 return C.oracle_alpm_pkg_get_validation(pkg)
2026}
2027
2028pub fn (pkg &Package) get_xdata() &List {
2029 return C.oracle_alpm_pkg_get_xdata(pkg)
2030}
2031
2032pub fn (pkg &Package) has_scriptlet() bool {
2033 return if C.oracle_alpm_pkg_has_scriptlet(pkg) == 1 { true } else { false }
2034}
2035
2036pub fn (newpkg &Package) download_size() i64 {
2037 return C.oracle_alpm_pkg_download_size(newpkg)
2038}
2039
2040pub fn (pkg &Package) set_reason(reason PackageReason) ! {
2041 if C.oracle_alpm_pkg_set_reason(pkg, reason) != 0 {
2042 return pkg.get_handle().error()
2043 }
2044}
2045
2046pub fn (pkg &Package) changelog_open() voidptr {
2047 return C.oracle_alpm_pkg_changelog_open(pkg)
2048}
2049
2050pub fn (pkg &Package) changelog_read(ptr voidptr, size uint, fp voidptr) uint {
2051 return C.oracle_alpm_pkg_changelog_read(ptr, size, pkg, fp)
2052}
2053
2054pub fn (pkg &Package) changelog_close(fp voidptr) ! {
2055 if C.oracle_alpm_pkg_changelog_close(pkg, fp) != 0 {
2056 return pkg.get_handle().error()
2057 }
2058}
2059
2060pub fn (pkg &Package) mtree_open() &C.Archive {
2061 return C.oracle_alpm_pkg_mtree_open(pkg)
2062}
2063
2064// the legacy wrapper advances but cannot propagate its pointer output.
2065// mtree_step returns true for an entry, false for EOF, and preserves read errors.
2066pub fn (pkg &Package) mtree_step(archive &C.Archive, entry &&C.Archive_entry) !bool {
2067 if pkg == unsafe { nil } || archive == unsafe { nil } || entry == unsafe { nil } {
2068 return error('mtree_step requires a package, archive and entry output')
2069 }
2070 status := C.oracle_alpm_pkg_mtree_next(pkg, archive, entry)
2071 if status == 0 { return true }
2072 if status == 1 { return false }
2073 message := C.archive_error_string(archive)
2074 if message != unsafe { nil } {
2075 text := unsafe { tos_clone(&u8(message)) }
2076 if text != '' { return error(text) }
2077 }
2078 return error('mtree read failed with status ${status}')
2079}
2080
2081pub fn (pkg &Package) mtree_next(archive &C.Archive, entry &C.Archive_entry) ! {
2082 if C.oracle_alpm_pkg_mtree_next(pkg, archive, &entry) != 0 {
2083 return pkg.get_handle().error()
2084 }
2085}
2086
2087pub fn (pkg &Package) mtree_close(archive &C.Archive) ! {
2088 if C.oracle_alpm_pkg_mtree_close(pkg, archive) != 0 {
2089 return pkg.get_handle().error()
2090 }
2091}
2092
2093@[flag]
2094pub enum TransFlag {
2095 no_deps = 0
2096 no_save = 2
2097 no_depversion = 3
2098 cascade = 4
2099 recurse = 5
2100 db_only = 6
2101 no_hooks = 7
2102 all_deps = 8
2103 download_only = 9
2104 no_scriptlet = 10
2105 no_conflicts = 11
2106 needed = 13
2107 all_explicit = 14
2108 unneeded = 15
2109 recurse_all = 16
2110 nolock = 17
2111}
2112
2113pub const trans_flag_0 = TransFlag.zero()
2114
2115fn C.oracle_alpm_trans_get_flags(handle &Handle) int
2116
2117fn C.oracle_alpm_trans_get_add(handle &Handle) &List
2118
2119fn C.oracle_alpm_trans_get_remove(handle &Handle) &List
2120
2121fn C.oracle_alpm_trans_init(handle &Handle, flags int) int
2122
2123fn C.oracle_alpm_trans_prepare(handle &Handle, data &&List) int
2124
2125fn C.oracle_alpm_trans_commit(handle &Handle, data &&List) int
2126
2127fn C.oracle_alpm_trans_interrupt(handle &Handle) int
2128
2129fn C.oracle_alpm_trans_release(handle &Handle) int
2130
2131fn C.oracle_alpm_sync_sysupgrade(handle &Handle, enable_downgrade int) int
2132
2133fn C.oracle_alpm_add_pkg(handle &Handle, pkg &Package) int
2134
2135fn C.oracle_alpm_remove_pkg(handle &Handle, pkg &Package) int
2136
2137fn C.oracle_alpm_sync_get_new_version(pkg &Package, dbs_sync &List) &Package
2138
2139fn C.oracle_alpm_unlock(handle &Handle) int
2140
2141pub fn (handle &Handle) trans_get_flags() TransFlag {
2142 return unsafe { TransFlag(C.oracle_alpm_trans_get_flags(handle)) }
2143}
2144
2145pub fn (handle &Handle) trans_get_add() &List {
2146 return C.oracle_alpm_trans_get_add(handle)
2147}
2148
2149pub fn (handle &Handle) trans_get_remove() &List {
2150 return C.oracle_alpm_trans_get_remove(handle)
2151}
2152
2153pub fn (handle &Handle) trans_init(flags TransFlag) ! {
2154 if C.oracle_alpm_trans_init(handle, int(flags)) != 0 {
2155 return handle.error()
2156 }
2157}
2158
2159pub fn (handle &Handle) trans_prepare() !&List {
2160 mut data := &List(unsafe { nil })
2161 if C.oracle_alpm_trans_prepare(handle, &data) != 0 {
2162 return handle.error()
2163 }
2164 return data
2165}
2166
2167// DepProblem is one dependency that a failed prepare found broken: the package
2168// that needs it, the dependency itself, and the package whose removal or
2169// replacement breaks it
2170pub struct DepProblem {
2171pub:
2172 target string
2173 depend string
2174 causing string
2175}
2176
2177// trans_prepare_problems is trans_prepare, except that a failure also returns
2178// the dependency problems libalpm found, which pacman lists when it refuses
2179// trans_prepare_problems explains a failed prepare, reading the error data
2180// the way libalpm's docs define it: the payload type follows the errno, and
2181// is alpm_depmissing_t for unsatisfied_deps, alpm_conflict_t for
2182// conflicting_deps, a package for pkg_invalid and a plain string otherwise
2183pub fn (handle &Handle) trans_prepare_problems() ([]DepProblem, ?IError) {
2184 mut data := &List(unsafe { nil })
2185 if C.oracle_alpm_trans_prepare(handle, &data) == 0 {
2186 return []DepProblem{}, none
2187 }
2188 kind := handle.errno()
2189 mut problems := []DepProblem{}
2190 if kind == .unsatisfied_deps {
2191 mut cur := data
2192 for cur != unsafe { nil } {
2193 if cur.data != unsafe { nil } {
2194 miss := unsafe { &DepMissing(cur.data) }
2195 depend := if miss.depend != unsafe { nil } {
2196 miss.depend.compute_string()
2197 } else {
2198 ''
2199 }
2200 problems << DepProblem{
2201 target: cstring_to_vstring_or_none(miss.target)
2202 depend: depend
2203 causing: cstring_to_vstring_or_none(miss.causingpkg)
2204 }
2205 miss.free()
2206 }
2207 cur = cur.next
2208 }
2209 } else if kind == .conflicting_deps {
2210 mut cur := data
2211 for cur != unsafe { nil } {
2212 if cur.data != unsafe { nil } {
2213 conflict := unsafe { &Conflict(cur.data) }
2214 p1 := if conflict.package1 != unsafe { nil } {
2215 conflict.package1.get_name()
2216 } else {
2217 ''
2218 }
2219 p2 := if conflict.package2 != unsafe { nil } {
2220 conflict.package2.get_name()
2221 } else {
2222 ''
2223 }
2224 reason := if conflict.reason != unsafe { nil } {
2225 conflict.reason.compute_string()
2226 } else {
2227 ''
2228 }
2229 problems << DepProblem{
2230 target: p1
2231 depend: reason
2232 causing: p2
2233 }
2234 conflict.free()
2235 }
2236 cur = cur.next
2237 }
2238 } else if kind == .pkg_invalid {
2239 mut cur := data
2240 for cur != unsafe { nil } {
2241 if cur.data != unsafe { nil } {
2242 pkg := unsafe { &Package(cur.data) }
2243 problems << DepProblem{
2244 target: pkg.get_name()
2245 depend: pkg.get_filename()
2246 causing: ''
2247 }
2248 pkg.free_pkg() or {}
2249 }
2250 cur = cur.next
2251 }
2252 } else {
2253 // trans_dup_target and friends come as plain strings
2254 mut cur := data
2255 for cur != unsafe { nil } {
2256 if cur.data != unsafe { nil } {
2257 problems << DepProblem{
2258 target: cstring_to_vstring_or_none(&u8(cur.data))
2259 depend: ''
2260 causing: ''
2261 }
2262 }
2263 cur = cur.next
2264 }
2265 data.free_inner(C.free)
2266 }
2267 data.free()
2268 // package getters used above may reset the handle errno while copying data.
2269 return problems, kind.ierror()
2270}
2271
2272pub fn (handle &Handle) trans_commit() !&List {
2273 mut data := &List(unsafe { nil })
2274 if C.oracle_alpm_trans_commit(handle, &data) != 0 {
2275 return handle.error()
2276 }
2277 return data
2278}
2279
2280pub fn (handle &Handle) trans_interrupt() ! {
2281 if C.oracle_alpm_trans_interrupt(handle) != 0 {
2282 return handle.error()
2283 }
2284}
2285
2286pub fn (handle &Handle) trans_release() ! {
2287 if C.oracle_alpm_trans_release(handle) != 0 {
2288 return handle.error()
2289 }
2290}
2291
2292pub fn (handle &Handle) sync_sysupgrade(enable_downgrade bool) ! {
2293 if C.oracle_alpm_sync_sysupgrade(handle, int(enable_downgrade)) != 0 {
2294 return handle.error()
2295 }
2296}
2297
2298pub fn (handle &Handle) add_pkg(pkg &Package) ! {
2299 if C.oracle_alpm_add_pkg(handle, pkg) != 0 {
2300 return handle.error()
2301 }
2302}
2303
2304pub fn (handle &Handle) remove_pkg(pkg &Package) ! {
2305 if C.oracle_alpm_remove_pkg(handle, pkg) != 0 {
2306 return handle.error()
2307 }
2308}
2309
2310pub fn (dbs_sync &List) sync_get_new_version(pkg &Package) &Package {
2311 return C.oracle_alpm_sync_get_new_version(pkg, dbs_sync)
2312}
2313
2314pub fn compute_md5sum(filename string) ?string {
2315 data := C.oracle_alpm_compute_md5sum(filename.str)
2316 if data == unsafe { nil } { return none }
2317 defer { C.free(data) }
2318 return unsafe { cstring_to_vstring(data) }
2319}
2320
2321pub fn compute_sha256sum(filename string) ?string {
2322 data := C.oracle_alpm_compute_sha256sum(filename.str)
2323 if data == unsafe { nil } { return none }
2324 defer { C.free(data) }
2325 return unsafe { cstring_to_vstring(data) }
2326}
2327
2328fn C.oracle_alpm_compute_md5sum(&u8) &u8
2329fn C.oracle_alpm_compute_sha256sum(&u8) &u8
2330
2331pub fn (handle &Handle) unlock() ! {
2332 if handle.unlock_async() != 0 {
2333 return handle.error()
2334 }
2335}
2336
2337// status only: the signal path cannot allocate a V error or run callbacks.
2338pub fn (handle &Handle) unlock_async() int {
2339 return C.oracle_alpm_unlock(handle)
2340}
2341
2342// bit positions, as for SigLevel
2343@[flag]
2344pub enum Caps {
2345 nls = 0
2346 downloader = 1
2347 signatures = 2
2348}
2349
2350fn C.oracle_alpm_version() &u8
2351
2352fn C.oracle_alpm_capabilities() int
2353
2354fn C.oracle_alpm_sandbox_setup_child(handle &Handle, sandboxuser &u8, sandbox_path &u8, restrict_syscalls bool) int
2355
2356pub fn version() string {
2357 return unsafe { C.oracle_alpm_version().vstring() }
2358}
2359
2360pub fn capabilities() Caps {
2361 return unsafe { Caps(C.oracle_alpm_capabilities()) }
2362}
2363
2364pub fn (handle &Handle) sandbox_setup_child(sandboxuser string, sandbox_path string, restrict_syscalls bool) ! {
2365 if C.oracle_alpm_sandbox_setup_child(handle, sandboxuser.str, sandbox_path.str, restrict_syscalls) != 0 {
2366 return handle.error()
2367 }
2368}
2369
2370// helpers built on the bindings above: finding packages by name, walking the
2371// dependency graph and reading the file list
2372
2373// strip_db_prefix removes a db prefix from a target, the way pacman accepts
2374// 'local/patchelf' or 'system/bash'
2375pub fn (handle &Handle) strip_db_prefix(target string) string {
2376 if target.starts_with('local/') && target.len > 6 {
2377 return target[6..]
2378 }
2379 dbs := handle.get_syncdbs() or { return target }
2380 for db in dbs.dbs() {
2381 prefix := db.get_name() + '/'
2382 if target.starts_with(prefix) && target.len > prefix.len {
2383 return target[prefix.len..]
2384 }
2385 }
2386 return target
2387}
2388
2389// find_local_pkg looks a package up by name in the local db
2390pub fn (handle &Handle) find_local_pkg(name string) ?&Package {
2391 mut localdb := handle.get_localdb() or { return none }
2392 mut pkgcache := localdb.get_pkgcache() or { return none }
2393 return pkgcache.pkg_find(name)
2394}
2395
2396// resolve_dep finds what satisfies a dependency string. the installed package
2397// wins, so a tree reflects what is actually on the system, and the sync dbs
2398// answer for everything else
2399pub fn (handle &Handle) resolve_dep(installed &List, sync_dbs &List, depstring string) ?&Package {
2400 if pkg := installed.find_satisfier(depstring) {
2401 return pkg
2402 }
2403 return handle.find_dbs_satisfier(sync_dbs, depstring)
2404}
2405
2406// outdated_deps walks the dependency closure of pkg against the sync dbs and
2407// returns the sync versions of installed packages that are older than the
2408// closure needs. only those are returned, so this is not a full upgrade
2409pub fn (handle &Handle) outdated_deps(sync_dbs &List, pkg &Package) []&Package {
2410 mut out := []&Package{}
2411 mut seen := map[string]bool{}
2412 seen[pkg.get_name()] = true
2413 mut queue := []&Package{}
2414 queue << pkg
2415 mut i := 0
2416 for i < queue.len {
2417 current := queue[i]
2418 i++
2419 for dep in current.get_depends().depends() {
2420 cand := handle.find_dbs_satisfier(sync_dbs, dep.compute_string()) or { continue }
2421 name := cand.get_name()
2422 if seen[name] {
2423 continue
2424 }
2425 seen[name] = true
2426 if installed := handle.find_local_pkg(name) {
2427 if pkg_vercmp(installed.get_version(), cand.get_version()) < 0 {
2428 out << cand
2429 }
2430 }
2431 queue << cand
2432 }
2433 }
2434 return out
2435}
2436
2437// is_unrequired is pacman's -Qdt filter: installed as a dependency, required
2438// by nothing and not an optional dependency of anything
2439pub fn (pkg &Package) is_unrequired() bool {
2440 return pkg.get_reason() == .depend && pkg.compute_required_by().len == 0
2441 && pkg.compute_optional_for().len == 0
2442}
2443
2444// names returns the paths in a file list
2445pub fn (filelist &Filelist) names() []string {
2446 mut out := []string{cap: int(filelist.count)}
2447 for i in 0 .. int(filelist.count) {
2448 out << unsafe { filelist.files[i].name.vstring() }
2449 }
2450 return out
2451}
2452
2453// unneeded_closure extends a set of orphans to everything that becomes
2454// unneeded once they are gone. a dependency is unneeded when every package
2455// that requires it, and every package that optionally requires it, is going
2456// away too. the set is grown to a fixpoint, so one removal is enough
2457pub fn (handle &Handle) unneeded_closure(seed []&Package) []&Package {
2458 mut localdb := handle.get_localdb() or { return seed }
2459 mut pkgcache := localdb.get_pkgcache() or { return seed }
2460 installed := pkgcache.pkgs()
2461
2462 mut removed := map[string]bool{}
2463 mut out := []&Package{}
2464 for p in seed {
2465 removed[p.get_name()] = true
2466 out << p
2467 }
2468 mut changed := true
2469 for changed {
2470 changed = false
2471 for p in installed {
2472 name := p.get_name()
2473 if removed[name] || p.get_reason() != .depend {
2474 continue
2475 }
2476 required := p.compute_required_by()
2477 optional := p.compute_optional_for()
2478 mut kept := false
2479 for r in required {
2480 if !removed[r] {
2481 kept = true
2482 break
2483 }
2484 }
2485 for o in optional {
2486 if !removed[o] {
2487 kept = true
2488 break
2489 }
2490 }
2491 if !kept {
2492 removed[name] = true
2493 out << p
2494 changed = true
2495 }
2496 }
2497 }
2498 return out
2499}
2500
2501// a failed literal match can still be satisfied by one of the package's provisions.
2502pub fn (pkg &Package) satisfies(dep &Depend) bool {
2503 packages := unsafe { (&List(nil)).add(pkg) }
2504 defer { packages.free() }
2505 return C.oracle_alpm_find_satisfier(packages, dep.compute_string().str) != unsafe { nil }
2506}
2507
2508// sync_package finds a package by name in the sync dbs
2509fn sync_package(sync_dbs &List, name string) ?&Package {
2510 mut dbs := unsafe { sync_dbs }
2511 for db in dbs.dbs() {
2512 if p := db.get_pkg(name) {
2513 return p
2514 }
2515 }
2516 return none
2517}
2518
2519// dep_still_met reports whether a dependency of a package that is about to
2520// be installed holds after the upgrades. only an installed provider that is
2521// itself being upgraded can break it
2522fn dep_still_met(pkgcache &List, new_ver map[string]&Package, dep &Depend) bool {
2523 sat := pkgcache.find_satisfier(dep.compute_string()) or { return true }
2524 provider := new_ver[sat.get_name()] or { return true }
2525 return provider.satisfies(dep)
2526}
2527
2528// broken_dependents returns the sync packages that have to go along with an
2529// upgrade. an installed package whose dependency is met by a package being
2530// upgraded, but not by the new version of it, is upgraded to its sync version.
2531// that version must be satisfied by the new versions, or the upgrade is
2532// refused, since nothing sensible can be done with it
2533pub fn (handle &Handle) broken_dependents(upgrades []&Package, sync_dbs &List) ![]&Package {
2534 mut localdb := handle.get_localdb()!
2535 mut pkgcache := localdb.get_pkgcache() or { return error('failed to get pkgcache') }
2536 installed := pkgcache.pkgs()
2537
2538 mut new_ver := map[string]&Package{}
2539 for p in upgrades {
2540 new_ver[p.get_name()] = p
2541 }
2542 mut extra := []&Package{}
2543 mut changed := true
2544 for changed {
2545 changed = false
2546 for pkg in installed {
2547 name := pkg.get_name()
2548 if name in new_ver {
2549 continue
2550 }
2551 for dep in pkg.get_depends().depends() {
2552 sat := pkgcache.find_satisfier(dep.compute_string()) or { continue }
2553 provider := new_ver[sat.get_name()] or { continue }
2554 if provider.satisfies(dep) {
2555 continue
2556 }
2557 replacement := sync_package(sync_dbs, name) or {
2558 return error('${name} needs ${dep.compute_string()}, which the upgrade replaces with ${provider.get_name()} ${provider.get_version()}, and the repos have no ${name} to upgrade with')
2559 }
2560 for d in replacement.get_depends().depends() {
2561 if !dep_still_met(pkgcache, new_ver, d) {
2562 return error('the repo version of ${name} needs ${d.compute_string()}, which the upgrade does not provide')
2563 }
2564 }
2565 new_ver[name] = replacement
2566 extra << replacement
2567 changed = true
2568 break
2569 }
2570 }
2571 }
2572 return extra
2573}
2574