| 1 | // C reference based on the public API at 3d0a6ea; never a production backend. |
| 2 | module coracle |
| 3 | |
| 4 | #flag -I/usr/include |
| 5 | #flag -lalpm |
| 6 | #flag -std=gnu99 |
| 7 | |
| 8 | #include "@DIR/native_oracle.h" |
| 9 | |
| 10 | struct C.Archive {} |
| 11 | |
| 12 | fn C.archive_error_string(&C.Archive) &char |
| 13 | |
| 14 | struct C.Archive_acl {} |
| 15 | |
| 16 | struct C.Archive_entry {} |
| 17 | |
| 18 | struct C.Archive_entry_linkresolver {} |
| 19 | |
| 20 | type Size_t = u32 |
| 21 | type Ulong = u32 |
| 22 | type Ushort = u16 |
| 23 | type Uint = u32 |
| 24 | type U_int8_t = u8 |
| 25 | type U_int16_t = u16 |
| 26 | type U_int32_t = u32 |
| 27 | type U_int64_t = u64 |
| 28 | |
| 29 | type Time_t = i64 |
| 30 | type Off_t = i64 |
| 31 | type Pid_t = int |
| 32 | type Uid_t = u32 |
| 33 | type Gid_t = u32 |
| 34 | type Mode_t = u32 |
| 35 | type Dev_t = u64 |
| 36 | type Ino_t = u64 |
| 37 | type Nlink_t = u64 |
| 38 | type Blksize_t = i64 |
| 39 | type Blkcnt_t = i64 |
| 40 | type Clock_t = i64 |
| 41 | type Clockid_t = int |
| 42 | type Timer_t = voidptr |
| 43 | type Suseconds_t = i64 |
| 44 | type Useconds_t = u32 |
| 45 | type Syscall_slong_t = i64 |
| 46 | type Off64_t = i64 |
| 47 | |
| 48 | struct C.Timespec { |
| 49 | tv_sec Time_t |
| 50 | tv_nsec Syscall_slong_t |
| 51 | } |
| 52 | |
| 53 | type La_int64_t = i64 |
| 54 | type La_uint64_t = u64 |
| 55 | type La_ssize_t = int |
| 56 | |
| 57 | pub fn (list &List) get_pkg() ?&Package { |
| 58 | data := unsafe { &Package(list.data) } |
| 59 | return if data == unsafe { nil } { none } else { data } |
| 60 | } |
| 61 | |
| 62 | pub fn (list &List) get_db() ?&DB { |
| 63 | data := unsafe { &DB(list.data) } |
| 64 | return if data == unsafe { nil } { none } else { data } |
| 65 | } |
| 66 | |
| 67 | pub 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 | |
| 72 | pub fn (list &List) get_group() ?&Group { |
| 73 | data := unsafe { &Group(list.data) } |
| 74 | return if data == unsafe { nil } { none } else { data } |
| 75 | } |
| 76 | |
| 77 | pub fn (list &List) get_backup() ?&Backup { |
| 78 | if list.data == unsafe { nil } { |
| 79 | return none |
| 80 | } |
| 81 | return &Backup(list.data) |
| 82 | } |
| 83 | |
| 84 | pub fn (b &Backup) get_name() string { |
| 85 | return cstring_to_vstring_or_none(b.name) |
| 86 | } |
| 87 | |
| 88 | pub fn (b &Backup) get_hash() string { |
| 89 | return cstring_to_vstring_or_none(b.hash) |
| 90 | } |
| 91 | |
| 92 | pub fn (list &List) get_depend() ?&Depend { |
| 93 | data := unsafe { &Depend(list.data) } |
| 94 | return if data == unsafe { nil } { none } else { data } |
| 95 | } |
| 96 | |
| 97 | pub 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 | |
| 110 | pub 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 | |
| 123 | pub 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 | |
| 136 | pub 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 | |
| 149 | pub 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 | |
| 162 | pub struct HandleW { |
| 163 | pub mut: |
| 164 | handle &Handle = unsafe { nil } |
| 165 | err Errno |
| 166 | } |
| 167 | |
| 168 | pub struct Handle {} |
| 169 | |
| 170 | pub struct DB {} |
| 171 | |
| 172 | pub struct Package {} |
| 173 | |
| 174 | pub struct PkgXdata { |
| 175 | name &u8 = unsafe { nil } |
| 176 | value &u8 = unsafe { nil } |
| 177 | } |
| 178 | |
| 179 | type Time = i64 |
| 180 | |
| 181 | pub struct File { |
| 182 | name &u8 = unsafe { nil } |
| 183 | size i64 |
| 184 | mode u32 |
| 185 | } |
| 186 | |
| 187 | pub struct Filelist { |
| 188 | count uint |
| 189 | files &File = unsafe { nil } |
| 190 | } |
| 191 | |
| 192 | pub struct Backup { |
| 193 | name &u8 = unsafe { nil } |
| 194 | hash &u8 = unsafe { nil } |
| 195 | } |
| 196 | |
| 197 | fn C.oracle_alpm_filelist_contains(filelist &Filelist, path &u8) &File |
| 198 | |
| 199 | fn C.oracle_alpm_find_group_pkgs(dbs &List, name &u8) &List |
| 200 | |
| 201 | pub 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 | |
| 210 | pub struct Group { |
| 211 | pub mut: |
| 212 | name &u8 = unsafe { nil } |
| 213 | packages &List = unsafe { nil } |
| 214 | } |
| 215 | |
| 216 | pub fn (group &Group) get_name() string { |
| 217 | return cstring_to_vstring_or_none(group.name) |
| 218 | } |
| 219 | |
| 220 | pub fn (dbs &List) find_group_pkgs(name string) &List { |
| 221 | return C.oracle_alpm_find_group_pkgs(dbs, name.str) |
| 222 | } |
| 223 | |
| 224 | pub 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 | |
| 283 | fn C.oracle_alpm_errno(handle &Handle) Errno |
| 284 | |
| 285 | fn C.oracle_alpm_strerror(err Errno) &u8 |
| 286 | |
| 287 | fn C.oracle_alpm_initialize(root &u8, dbpath &u8, err &Errno) &Handle |
| 288 | |
| 289 | fn C.oracle_alpm_release(handle &Handle) int |
| 290 | |
| 291 | pub fn (handle &Handle) errno() Errno { |
| 292 | return C.oracle_alpm_errno(handle) |
| 293 | } |
| 294 | |
| 295 | pub fn (err Errno) strerror() string { |
| 296 | return unsafe { C.oracle_alpm_strerror(err).vstring() } |
| 297 | } |
| 298 | |
| 299 | pub fn (err Errno) ierror() IError { |
| 300 | return error_with_code(err.strerror(), int(err)) |
| 301 | } |
| 302 | |
| 303 | pub fn (handle &Handle) error() IError { |
| 304 | return handle.errno().ierror() |
| 305 | } |
| 306 | |
| 307 | pub 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 | |
| 319 | pub 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] |
| 329 | pub 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 | |
| 341 | pub enum SigStatus { |
| 342 | valid |
| 343 | key_expired |
| 344 | sig_expired |
| 345 | key_unknown |
| 346 | key_disabled |
| 347 | invalid |
| 348 | } |
| 349 | |
| 350 | pub enum SigValidity { |
| 351 | full |
| 352 | marginal |
| 353 | never |
| 354 | unknown |
| 355 | } |
| 356 | |
| 357 | pub struct PGPKey { |
| 358 | pub 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 | |
| 370 | pub struct SigResult { |
| 371 | pub mut: |
| 372 | key PGPKey |
| 373 | status SigStatus |
| 374 | validity SigValidity |
| 375 | } |
| 376 | |
| 377 | pub struct SigList { |
| 378 | pub mut: |
| 379 | count uint |
| 380 | results &SigResult = unsafe { nil } |
| 381 | } |
| 382 | |
| 383 | fn C.oracle_alpm_pkg_check_pgp_signature(pkg &Package, siglist &SigList) int |
| 384 | |
| 385 | fn C.oracle_alpm_db_check_pgp_signature(db &DB, siglist &SigList) int |
| 386 | |
| 387 | fn C.oracle_alpm_siglist_cleanup(siglist &SigList) int |
| 388 | |
| 389 | fn C.oracle_alpm_decode_signature(base64_data &u8, data &&u8, data_len &uint) int |
| 390 | |
| 391 | fn C.oracle_alpm_extract_keyid(handle &Handle, identifier &u8, sig &u8, len uint, keys &&List) int |
| 392 | |
| 393 | pub 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 | |
| 398 | pub 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 | |
| 403 | pub fn (siglist &SigList) cleanup() ! { |
| 404 | if C.oracle_alpm_siglist_cleanup(siglist) != 0 { |
| 405 | return error('failed to cleanup siglist') |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | pub 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 | |
| 419 | fn C.oracle_alpm_decode_signature(&u8, &&u8, &uint) int |
| 420 | fn C.oracle_alpm_extract_keyid(&Handle, &u8, &u8, uint, &&List) int |
| 421 | |
| 422 | pub 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 | |
| 433 | pub enum Depmod { |
| 434 | any = 1 |
| 435 | equal |
| 436 | at_least |
| 437 | at_most |
| 438 | greater_than |
| 439 | less_than |
| 440 | } |
| 441 | |
| 442 | pub enum FileConflictType { |
| 443 | target = 1 |
| 444 | filesystem |
| 445 | } |
| 446 | |
| 447 | pub struct Depend { |
| 448 | pub 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 | |
| 456 | pub fn (dep Depend) get_name() string { |
| 457 | return cstring_to_vstring_or_none(dep.name) |
| 458 | } |
| 459 | |
| 460 | pub fn (dep Depend) get_version() string { |
| 461 | return cstring_to_vstring_or_none(dep.version) |
| 462 | } |
| 463 | |
| 464 | pub fn (dep Depend) get_desc() string { |
| 465 | return cstring_to_vstring_or_none(dep.desc) |
| 466 | } |
| 467 | |
| 468 | pub struct DepMissing { |
| 469 | pub mut: |
| 470 | target &u8 = unsafe { nil } |
| 471 | depend &Depend = unsafe { nil } |
| 472 | causingpkg &u8 = unsafe { nil } |
| 473 | } |
| 474 | |
| 475 | pub struct Conflict { |
| 476 | pub mut: |
| 477 | package1 &Package = unsafe { nil } |
| 478 | package2 &Package = unsafe { nil } |
| 479 | reason &Depend = unsafe { nil } |
| 480 | } |
| 481 | |
| 482 | pub struct FileConflict { |
| 483 | pub mut: |
| 484 | target &u8 = unsafe { nil } |
| 485 | type_ FileConflictType |
| 486 | file &u8 = unsafe { nil } |
| 487 | ctarget &u8 = unsafe { nil } |
| 488 | } |
| 489 | |
| 490 | fn C.oracle_alpm_checkdeps(handle &Handle, pkglist &List, remove &List, upgrade &List, reversedeps int) &List |
| 491 | |
| 492 | fn C.oracle_alpm_find_dbs_satisfier(handle &Handle, dbs &List, depstring &u8) &Package |
| 493 | |
| 494 | fn C.oracle_alpm_checkconflicts(handle &Handle, pkglist &List) &List |
| 495 | |
| 496 | fn C.oracle_alpm_conflict_free(conflict &Conflict) |
| 497 | |
| 498 | pub 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 | |
| 502 | pub 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 | |
| 507 | fn C.oracle_alpm_find_satisfier(&List, &u8) &Package |
| 508 | |
| 509 | pub 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 | |
| 514 | pub 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. |
| 520 | pub 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 | |
| 527 | fn C.oracle_alpm_dep_compute_string(&Depend) &u8 |
| 528 | fn C.oracle_alpm_dep_from_string(&u8) &Depend |
| 529 | fn C.oracle_alpm_dep_free(&Depend) |
| 530 | |
| 531 | pub fn dep_from_string(depstring string) &Depend { |
| 532 | return C.oracle_alpm_dep_from_string(depstring.str) |
| 533 | } |
| 534 | |
| 535 | pub fn (dep &Depend) free() { |
| 536 | if dep == unsafe { nil } { return } |
| 537 | C.oracle_alpm_dep_free(dep) |
| 538 | } |
| 539 | |
| 540 | pub 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 | |
| 548 | pub 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 | |
| 556 | pub fn (conflict &Conflict) free() { |
| 557 | C.oracle_alpm_conflict_free(conflict) |
| 558 | } |
| 559 | |
| 560 | pub 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 | |
| 600 | pub struct EventAny { |
| 601 | type_ EventType |
| 602 | } |
| 603 | |
| 604 | pub enum PackageOperation { |
| 605 | install = 1 |
| 606 | upgrade |
| 607 | reinstall |
| 608 | downgrade |
| 609 | remove |
| 610 | } |
| 611 | |
| 612 | pub struct EventPackageOperation { |
| 613 | pub mut: |
| 614 | type_ EventType |
| 615 | operation PackageOperation |
| 616 | oldpkg &Package = unsafe { nil } |
| 617 | newpkg &Package = unsafe { nil } |
| 618 | } |
| 619 | |
| 620 | pub struct EventOptDepRemoval { |
| 621 | pub mut: |
| 622 | type_ EventType |
| 623 | pkg &Package = unsafe { nil } |
| 624 | optdep &Depend = unsafe { nil } |
| 625 | } |
| 626 | |
| 627 | pub struct EventScriptletInfo { |
| 628 | pub mut: |
| 629 | type_ EventType |
| 630 | line &u8 = unsafe { nil } |
| 631 | } |
| 632 | |
| 633 | pub struct EventDatabaseMissing { |
| 634 | pub mut: |
| 635 | type_ EventType |
| 636 | dbname &u8 = unsafe { nil } |
| 637 | } |
| 638 | |
| 639 | pub struct EventPkgDownload { |
| 640 | pub mut: |
| 641 | type_ EventType |
| 642 | file &u8 = unsafe { nil } |
| 643 | } |
| 644 | |
| 645 | pub struct EventPacnewCreated { |
| 646 | pub 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 | |
| 654 | pub struct EventPacsaveCreated { |
| 655 | pub mut: |
| 656 | type_ EventType |
| 657 | oldpkg &Package = unsafe { nil } |
| 658 | file &u8 = unsafe { nil } |
| 659 | } |
| 660 | |
| 661 | pub enum HookWhen { |
| 662 | pre_transaction = 1 |
| 663 | post_transaction |
| 664 | } |
| 665 | |
| 666 | pub struct EventHook { |
| 667 | pub mut: |
| 668 | type_ EventType |
| 669 | when HookWhen |
| 670 | } |
| 671 | |
| 672 | pub struct EventHookRun { |
| 673 | pub mut: |
| 674 | type_ EventType |
| 675 | name &u8 = unsafe { nil } |
| 676 | desc &u8 = unsafe { nil } |
| 677 | position uint |
| 678 | total uint |
| 679 | } |
| 680 | |
| 681 | pub struct EventPkgRetrieve { |
| 682 | pub mut: |
| 683 | type_ EventType |
| 684 | num uint |
| 685 | total_size i64 |
| 686 | } |
| 687 | |
| 688 | union Event { |
| 689 | pub 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 | |
| 704 | type CbEvent = fn (voidptr, &Event) |
| 705 | |
| 706 | pub 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 | |
| 716 | pub struct QuestionAny { |
| 717 | pub mut: |
| 718 | type_ QuestionType |
| 719 | answer i32 |
| 720 | } |
| 721 | |
| 722 | pub struct QuestionInstallIgnorePkg { |
| 723 | pub mut: |
| 724 | type_ QuestionType |
| 725 | install i32 |
| 726 | pkg &Package = unsafe { nil } |
| 727 | } |
| 728 | |
| 729 | pub struct QuestionReplace { |
| 730 | pub mut: |
| 731 | type_ QuestionType |
| 732 | replace i32 |
| 733 | oldpkg &Package = unsafe { nil } |
| 734 | newpkg &Package = unsafe { nil } |
| 735 | newdb &DB = unsafe { nil } |
| 736 | } |
| 737 | |
| 738 | pub struct QuestionConflict { |
| 739 | pub mut: |
| 740 | type_ QuestionType |
| 741 | remove_ i32 |
| 742 | conflict &Conflict = unsafe { nil } |
| 743 | } |
| 744 | |
| 745 | pub struct QuestionCorrupted { |
| 746 | pub mut: |
| 747 | type_ QuestionType |
| 748 | remove_ i32 |
| 749 | filepath &u8 = unsafe { nil } |
| 750 | reason Errno |
| 751 | } |
| 752 | |
| 753 | pub struct QuestionRemovePkgs { |
| 754 | pub mut: |
| 755 | type_ QuestionType |
| 756 | skip i32 |
| 757 | packages &List = unsafe { nil } |
| 758 | } |
| 759 | |
| 760 | pub struct QuestionSelectProvider { |
| 761 | pub mut: |
| 762 | type_ QuestionType |
| 763 | use_index i32 |
| 764 | providers &List = unsafe { nil } |
| 765 | depend &Depend = unsafe { nil } |
| 766 | } |
| 767 | |
| 768 | pub struct QuestionImportKey { |
| 769 | pub mut: |
| 770 | type_ QuestionType |
| 771 | import_ i32 |
| 772 | uid &u8 = unsafe { nil } |
| 773 | fingerprint &u8 = unsafe { nil } |
| 774 | } |
| 775 | |
| 776 | union Question { |
| 777 | pub 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 | |
| 789 | type CbQuestion = fn (voidptr, &Question) |
| 790 | |
| 791 | pub 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 | |
| 804 | type CbProgress = fn (voidptr, Progress, &u8, i32, uint, uint) |
| 805 | |
| 806 | pub enum DownloadEventType { |
| 807 | init |
| 808 | progress |
| 809 | retry |
| 810 | completed |
| 811 | } |
| 812 | |
| 813 | pub struct DownloadEventInit { |
| 814 | pub mut: |
| 815 | optional i32 |
| 816 | } |
| 817 | |
| 818 | pub struct DownloadEventProgress { |
| 819 | pub mut: |
| 820 | downloaded i64 |
| 821 | total i64 |
| 822 | } |
| 823 | |
| 824 | pub struct DownloadEventRetry { |
| 825 | pub mut: |
| 826 | resume i32 |
| 827 | } |
| 828 | |
| 829 | pub struct DownloadEventCompleted { |
| 830 | pub mut: |
| 831 | total i64 |
| 832 | result i32 |
| 833 | } |
| 834 | |
| 835 | type CbDownload = fn (voidptr, &u8, DownloadEventType, voidptr) |
| 836 | type CbFetch = fn (voidptr, &u8, &u8, i32) i32 |
| 837 | |
| 838 | fn C.oracle_alpm_get_localdb(handle &Handle) &DB |
| 839 | |
| 840 | fn C.oracle_alpm_get_syncdbs(handle &Handle) &List |
| 841 | |
| 842 | fn C.oracle_alpm_register_syncdb(handle &Handle, treename &u8, level int) &DB |
| 843 | |
| 844 | fn C.oracle_alpm_unregister_all_syncdbs(handle &Handle) int |
| 845 | |
| 846 | fn C.oracle_alpm_db_unregister(db &DB) int |
| 847 | |
| 848 | fn C.oracle_alpm_db_get_handle(db &DB) &Handle |
| 849 | |
| 850 | fn C.oracle_alpm_db_get_name(db &DB) &u8 |
| 851 | |
| 852 | fn C.oracle_alpm_db_get_siglevel(db &DB) int |
| 853 | |
| 854 | fn C.oracle_alpm_db_get_valid(db &DB) int |
| 855 | |
| 856 | fn C.oracle_alpm_db_get_servers(db &DB) &List |
| 857 | |
| 858 | fn C.oracle_alpm_db_set_servers(db &DB, servers &List) int |
| 859 | |
| 860 | fn C.oracle_alpm_db_add_server(db &DB, url &u8) int |
| 861 | |
| 862 | fn C.oracle_alpm_db_remove_server(db &DB, url &u8) int |
| 863 | |
| 864 | fn C.oracle_alpm_db_get_cache_servers(db &DB) &List |
| 865 | |
| 866 | fn C.oracle_alpm_db_set_cache_servers(db &DB, servers &List) int |
| 867 | |
| 868 | fn C.oracle_alpm_db_add_cache_server(db &DB, url &u8) int |
| 869 | |
| 870 | fn C.oracle_alpm_db_remove_cache_server(db &DB, url &u8) int |
| 871 | |
| 872 | fn C.oracle_alpm_db_update(handle &Handle, dbs &List, force int) int |
| 873 | |
| 874 | fn C.oracle_alpm_db_get_pkg(db &DB, name &u8) &Package |
| 875 | |
| 876 | fn C.oracle_alpm_db_get_pkgcache(db &DB) &List |
| 877 | |
| 878 | fn C.oracle_alpm_db_get_group(db &DB, name &u8) &Group |
| 879 | |
| 880 | fn C.oracle_alpm_db_get_groupcache(db &DB) &List |
| 881 | |
| 882 | fn C.oracle_alpm_db_search(db &DB, needles &List, ret &&List) int |
| 883 | |
| 884 | pub 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 | |
| 889 | pub 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 | |
| 894 | pub 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 | |
| 899 | pub fn (handle &Handle) unregister_all_syncdbs() ! { |
| 900 | if C.oracle_alpm_unregister_all_syncdbs(handle) != 0 { |
| 901 | return handle.error() |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | pub fn (db &DB) unregister() ! { |
| 906 | if C.oracle_alpm_db_unregister(db) != 0 { |
| 907 | return db.get_handle().error() |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | pub fn (db &DB) get_handle() &Handle { |
| 912 | return C.oracle_alpm_db_get_handle(db) |
| 913 | } |
| 914 | |
| 915 | pub fn (db &DB) get_name() string { |
| 916 | return unsafe { C.oracle_alpm_db_get_name(db).vstring() } |
| 917 | } |
| 918 | |
| 919 | pub fn (db &DB) get_siglevel() SigLevel { |
| 920 | return unsafe { SigLevel(C.oracle_alpm_db_get_siglevel(db)) } |
| 921 | } |
| 922 | |
| 923 | pub 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 | |
| 931 | pub fn (db &DB) get_servers() &List { |
| 932 | return C.oracle_alpm_db_get_servers(db) |
| 933 | } |
| 934 | |
| 935 | pub 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 | |
| 941 | pub 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 | |
| 947 | pub 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 | |
| 953 | pub 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 | |
| 958 | pub 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 | |
| 964 | pub 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 | |
| 970 | pub 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 |
| 980 | pub 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 | |
| 989 | pub 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 | |
| 994 | pub 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 | |
| 999 | pub 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 | |
| 1004 | pub 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 | |
| 1009 | pub 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] |
| 1019 | pub 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 |
| 1028 | pub const db_usage_all = DBUsage.sync | .search | .install | .upgrade |
| 1029 | |
| 1030 | fn C.oracle_alpm_db_set_usage(db &DB, usage int) int |
| 1031 | |
| 1032 | pub 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 | |
| 1038 | fn C.oracle_alpm_db_get_usage(db &DB, usage &int) int |
| 1039 | |
| 1040 | pub 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] |
| 1051 | pub enum LogLevel { |
| 1052 | error = 0 |
| 1053 | warning = 1 |
| 1054 | debug = 2 |
| 1055 | function = 3 |
| 1056 | } |
| 1057 | |
| 1058 | type CbLog = fn (voidptr, LogLevel, &u8, voidptr) |
| 1059 | |
| 1060 | @[c2v_variadic] |
| 1061 | fn C.oracle_alpm_logaction(handle &Handle, prefix &u8, fmt &u8) int |
| 1062 | |
| 1063 | fn C.oracle_alpm_option_get_logcb(handle &Handle) CbLog |
| 1064 | |
| 1065 | fn C.oracle_alpm_option_get_logcb_ctx(handle &Handle) voidptr |
| 1066 | |
| 1067 | fn C.oracle_alpm_option_set_logcb(handle &Handle, cb CbLog, ctx voidptr) int |
| 1068 | |
| 1069 | fn C.oracle_alpm_option_get_dlcb(handle &Handle) CbDownload |
| 1070 | |
| 1071 | fn C.oracle_alpm_option_get_dlcb_ctx(handle &Handle) voidptr |
| 1072 | |
| 1073 | fn C.oracle_alpm_option_set_dlcb(handle &Handle, cb CbDownload, ctx voidptr) int |
| 1074 | |
| 1075 | fn C.oracle_alpm_option_get_fetchcb(handle &Handle) CbFetch |
| 1076 | |
| 1077 | fn C.oracle_alpm_option_get_fetchcb_ctx(handle &Handle) voidptr |
| 1078 | |
| 1079 | fn C.oracle_alpm_option_set_fetchcb(handle &Handle, cb CbFetch, ctx voidptr) int |
| 1080 | |
| 1081 | fn C.oracle_alpm_option_get_eventcb(handle &Handle) CbEvent |
| 1082 | |
| 1083 | fn C.oracle_alpm_option_get_eventcb_ctx(handle &Handle) voidptr |
| 1084 | |
| 1085 | fn C.oracle_alpm_option_set_eventcb(handle &Handle, cb CbEvent, ctx voidptr) int |
| 1086 | |
| 1087 | fn C.oracle_alpm_option_get_questioncb(handle &Handle) CbQuestion |
| 1088 | |
| 1089 | fn C.oracle_alpm_option_get_questioncb_ctx(handle &Handle) voidptr |
| 1090 | |
| 1091 | fn C.oracle_alpm_option_set_questioncb(handle &Handle, cb CbQuestion, ctx voidptr) int |
| 1092 | |
| 1093 | fn C.oracle_alpm_option_get_progresscb(handle &Handle) CbProgress |
| 1094 | |
| 1095 | fn C.oracle_alpm_option_get_progresscb_ctx(handle &Handle) voidptr |
| 1096 | |
| 1097 | fn C.oracle_alpm_option_set_progresscb(handle &Handle, cb CbProgress, ctx voidptr) int |
| 1098 | |
| 1099 | fn C.oracle_alpm_option_get_root(handle &Handle) &u8 |
| 1100 | |
| 1101 | fn C.oracle_alpm_option_get_dbpath(handle &Handle) &u8 |
| 1102 | |
| 1103 | fn C.oracle_alpm_option_get_lockfile(handle &Handle) &u8 |
| 1104 | |
| 1105 | fn C.oracle_alpm_option_get_cachedirs(handle &Handle) &List |
| 1106 | |
| 1107 | fn C.oracle_alpm_option_set_cachedirs(handle &Handle, cachedirs &List) int |
| 1108 | |
| 1109 | fn C.oracle_alpm_option_add_cachedir(handle &Handle, cachedir &u8) int |
| 1110 | |
| 1111 | fn C.oracle_alpm_option_remove_cachedir(handle &Handle, cachedir &u8) int |
| 1112 | |
| 1113 | fn C.oracle_alpm_option_get_hookdirs(handle &Handle) &List |
| 1114 | |
| 1115 | fn C.oracle_alpm_option_set_hookdirs(handle &Handle, hookdirs &List) int |
| 1116 | |
| 1117 | fn C.oracle_alpm_option_add_hookdir(handle &Handle, hookdir &u8) int |
| 1118 | |
| 1119 | fn C.oracle_alpm_option_remove_hookdir(handle &Handle, hookdir &u8) int |
| 1120 | |
| 1121 | fn C.oracle_alpm_option_get_overwrite_files(handle &Handle) &List |
| 1122 | |
| 1123 | fn C.oracle_alpm_option_set_overwrite_files(handle &Handle, globs &List) int |
| 1124 | |
| 1125 | fn C.oracle_alpm_option_add_overwrite_file(handle &Handle, glob &u8) int |
| 1126 | |
| 1127 | fn C.oracle_alpm_option_remove_overwrite_file(handle &Handle, glob &u8) int |
| 1128 | |
| 1129 | fn C.oracle_alpm_option_get_logfile(handle &Handle) &u8 |
| 1130 | |
| 1131 | fn C.oracle_alpm_option_set_logfile(handle &Handle, logfile &u8) int |
| 1132 | |
| 1133 | fn C.oracle_alpm_option_get_gpgdir(handle &Handle) &u8 |
| 1134 | |
| 1135 | fn C.oracle_alpm_option_set_gpgdir(handle &Handle, gpgdir &u8) int |
| 1136 | |
| 1137 | fn C.oracle_alpm_option_get_sandboxuser(handle &Handle) &u8 |
| 1138 | |
| 1139 | fn C.oracle_alpm_option_set_sandboxuser(handle &Handle, sandboxuser &u8) int |
| 1140 | |
| 1141 | fn C.oracle_alpm_option_get_usesyslog(handle &Handle) int |
| 1142 | |
| 1143 | fn C.oracle_alpm_option_set_usesyslog(handle &Handle, usesyslog int) int |
| 1144 | |
| 1145 | fn C.oracle_alpm_option_get_noupgrades(handle &Handle) &List |
| 1146 | |
| 1147 | fn C.oracle_alpm_option_add_noupgrade(handle &Handle, path &u8) int |
| 1148 | |
| 1149 | fn C.oracle_alpm_option_set_noupgrades(handle &Handle, noupgrade &List) int |
| 1150 | |
| 1151 | fn C.oracle_alpm_option_remove_noupgrade(handle &Handle, path &u8) int |
| 1152 | |
| 1153 | fn C.oracle_alpm_option_match_noupgrade(handle &Handle, path &u8) int |
| 1154 | |
| 1155 | fn C.oracle_alpm_option_get_noextracts(handle &Handle) &List |
| 1156 | |
| 1157 | fn C.oracle_alpm_option_add_noextract(handle &Handle, path &u8) int |
| 1158 | |
| 1159 | fn C.oracle_alpm_option_set_noextracts(handle &Handle, noextract &List) int |
| 1160 | |
| 1161 | fn C.oracle_alpm_option_remove_noextract(handle &Handle, path &u8) int |
| 1162 | |
| 1163 | fn C.oracle_alpm_option_match_noextract(handle &Handle, path &u8) int |
| 1164 | |
| 1165 | fn C.oracle_alpm_option_get_ignorepkgs(handle &Handle) &List |
| 1166 | |
| 1167 | fn C.oracle_alpm_option_add_ignorepkg(handle &Handle, pkg &u8) int |
| 1168 | |
| 1169 | fn C.oracle_alpm_option_set_ignorepkgs(handle &Handle, ignorepkgs &List) int |
| 1170 | |
| 1171 | fn C.oracle_alpm_option_remove_ignorepkg(handle &Handle, pkg &u8) int |
| 1172 | |
| 1173 | fn C.oracle_alpm_option_get_ignoregroups(handle &Handle) &List |
| 1174 | |
| 1175 | fn C.oracle_alpm_option_add_ignoregroup(handle &Handle, grp &u8) int |
| 1176 | |
| 1177 | fn C.oracle_alpm_option_set_ignoregroups(handle &Handle, ignoregrps &List) int |
| 1178 | |
| 1179 | fn C.oracle_alpm_option_remove_ignoregroup(handle &Handle, grp &u8) int |
| 1180 | |
| 1181 | fn C.oracle_alpm_option_get_assumeinstalled(handle &Handle) &List |
| 1182 | |
| 1183 | fn C.oracle_alpm_option_add_assumeinstalled(handle &Handle, dep &Depend) int |
| 1184 | |
| 1185 | fn C.oracle_alpm_option_set_assumeinstalled(handle &Handle, deps &List) int |
| 1186 | |
| 1187 | fn C.oracle_alpm_option_remove_assumeinstalled(handle &Handle, dep &Depend) int |
| 1188 | |
| 1189 | fn C.oracle_alpm_option_get_architectures(handle &Handle) &List |
| 1190 | |
| 1191 | fn C.oracle_alpm_option_add_architecture(handle &Handle, arch &u8) int |
| 1192 | |
| 1193 | fn C.oracle_alpm_option_set_architectures(handle &Handle, arches &List) int |
| 1194 | |
| 1195 | fn C.oracle_alpm_option_remove_architecture(handle &Handle, arch &u8) int |
| 1196 | |
| 1197 | fn C.oracle_alpm_option_get_checkspace(handle &Handle) int |
| 1198 | |
| 1199 | fn C.oracle_alpm_option_set_checkspace(handle &Handle, checkspace int) int |
| 1200 | |
| 1201 | fn C.oracle_alpm_option_get_dbext(handle &Handle) &u8 |
| 1202 | |
| 1203 | fn C.oracle_alpm_option_set_dbext(handle &Handle, dbext &u8) int |
| 1204 | |
| 1205 | fn C.oracle_alpm_option_get_default_siglevel(handle &Handle) int |
| 1206 | |
| 1207 | fn C.oracle_alpm_option_set_default_siglevel(handle &Handle, level int) int |
| 1208 | |
| 1209 | fn C.oracle_alpm_option_get_local_file_siglevel(handle &Handle) int |
| 1210 | |
| 1211 | fn C.oracle_alpm_option_set_local_file_siglevel(handle &Handle, level int) int |
| 1212 | |
| 1213 | fn C.oracle_alpm_option_get_remote_file_siglevel(handle &Handle) int |
| 1214 | |
| 1215 | fn C.oracle_alpm_option_set_remote_file_siglevel(handle &Handle, level int) int |
| 1216 | |
| 1217 | fn C.oracle_alpm_option_get_disable_dl_timeout(handle &Handle) int |
| 1218 | |
| 1219 | fn C.oracle_alpm_option_set_disable_dl_timeout(handle &Handle, disable_dl_timeout u16) int |
| 1220 | |
| 1221 | fn C.oracle_alpm_option_get_parallel_downloads(handle &Handle) int |
| 1222 | |
| 1223 | fn C.oracle_alpm_option_set_parallel_downloads(handle &Handle, num_streams u32) int |
| 1224 | |
| 1225 | fn C.oracle_alpm_option_get_disable_sandbox_filesystem(handle &Handle) int |
| 1226 | |
| 1227 | fn C.oracle_alpm_option_set_disable_sandbox_filesystem(handle &Handle, disable_sandbox_filesystem u16) int |
| 1228 | |
| 1229 | fn C.oracle_alpm_option_set_disable_sandbox_syscalls(handle &Handle, disable_sandbox_syscalls u16) int |
| 1230 | |
| 1231 | fn C.oracle_alpm_option_get_disable_sandbox_syscalls(handle &Handle) int |
| 1232 | |
| 1233 | pub 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 | |
| 1239 | pub fn (handle &Handle) option_get_logcb() CbLog { |
| 1240 | return C.oracle_alpm_option_get_logcb(handle) |
| 1241 | } |
| 1242 | |
| 1243 | pub fn (handle &Handle) option_get_logcb_ctx() voidptr { |
| 1244 | return C.oracle_alpm_option_get_logcb_ctx(handle) |
| 1245 | } |
| 1246 | |
| 1247 | pub 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 | |
| 1253 | pub fn (handle &Handle) option_get_dlcb() CbDownload { |
| 1254 | return C.oracle_alpm_option_get_dlcb(handle) |
| 1255 | } |
| 1256 | |
| 1257 | pub fn (handle &Handle) option_get_dlcb_ctx() voidptr { |
| 1258 | return C.oracle_alpm_option_get_dlcb_ctx(handle) |
| 1259 | } |
| 1260 | |
| 1261 | pub 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 | |
| 1267 | pub fn (handle &Handle) option_get_fetchcb() CbFetch { |
| 1268 | return C.oracle_alpm_option_get_fetchcb(handle) |
| 1269 | } |
| 1270 | |
| 1271 | pub fn (handle &Handle) get_fetchcb_ctx() voidptr { |
| 1272 | return C.oracle_alpm_option_get_fetchcb_ctx(handle) |
| 1273 | } |
| 1274 | |
| 1275 | pub 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 | |
| 1281 | pub fn (handle &Handle) option_get_eventcb() CbEvent { |
| 1282 | return C.oracle_alpm_option_get_eventcb(handle) |
| 1283 | } |
| 1284 | |
| 1285 | pub fn (handle &Handle) option_get_eventcb_ctx() voidptr { |
| 1286 | return C.oracle_alpm_option_get_eventcb_ctx(handle) |
| 1287 | } |
| 1288 | |
| 1289 | pub 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 | |
| 1295 | pub fn (handle &Handle) option_get_questioncb() CbQuestion { |
| 1296 | return C.oracle_alpm_option_get_questioncb(handle) |
| 1297 | } |
| 1298 | |
| 1299 | pub fn (handle &Handle) option_get_questioncb_ctx() voidptr { |
| 1300 | return C.oracle_alpm_option_get_questioncb_ctx(handle) |
| 1301 | } |
| 1302 | |
| 1303 | pub 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 | |
| 1309 | pub fn (handle &Handle) option_get_progresscb() CbProgress { |
| 1310 | return C.oracle_alpm_option_get_progresscb(handle) |
| 1311 | } |
| 1312 | |
| 1313 | pub fn (handle &Handle) option_get_progresscb_ctx() voidptr { |
| 1314 | return C.oracle_alpm_option_get_progresscb_ctx(handle) |
| 1315 | } |
| 1316 | |
| 1317 | pub 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 | |
| 1323 | pub fn (handle &Handle) option_get_root() string { |
| 1324 | return unsafe { C.oracle_alpm_option_get_root(handle).vstring() } |
| 1325 | } |
| 1326 | |
| 1327 | pub fn (handle &Handle) option_get_dbpath() string { |
| 1328 | return unsafe { C.oracle_alpm_option_get_dbpath(handle).vstring() } |
| 1329 | } |
| 1330 | |
| 1331 | pub fn (handle &Handle) option_get_lockfile() string { |
| 1332 | return unsafe { C.oracle_alpm_option_get_lockfile(handle).vstring() } |
| 1333 | } |
| 1334 | |
| 1335 | pub fn (handle &Handle) option_get_cachedirs() &List { |
| 1336 | return C.oracle_alpm_option_get_cachedirs(handle) |
| 1337 | } |
| 1338 | |
| 1339 | pub 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 | |
| 1345 | pub 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 | |
| 1351 | pub 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 | |
| 1357 | pub fn (handle &Handle) option_get_hookdirs() ?&List { |
| 1358 | return C.oracle_alpm_option_get_hookdirs(handle) |
| 1359 | } |
| 1360 | |
| 1361 | pub 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 | |
| 1367 | pub 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 | |
| 1373 | pub 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 | |
| 1379 | pub fn (handle &Handle) option_get_overwrite_files() &List { |
| 1380 | return C.oracle_alpm_option_get_overwrite_files(handle) |
| 1381 | } |
| 1382 | |
| 1383 | pub 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 | |
| 1389 | pub 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 | |
| 1395 | pub 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 | |
| 1401 | pub fn (handle &Handle) option_get_logfile() string { |
| 1402 | return unsafe { C.oracle_alpm_option_get_logfile(handle).vstring() } |
| 1403 | } |
| 1404 | |
| 1405 | pub 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 | |
| 1411 | pub fn (handle &Handle) option_get_gpgdir() string { |
| 1412 | return unsafe { C.oracle_alpm_option_get_gpgdir(handle).vstring() } |
| 1413 | } |
| 1414 | |
| 1415 | pub 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 | |
| 1421 | pub fn (handle &Handle) option_get_sandboxuser() string { |
| 1422 | return unsafe { C.oracle_alpm_option_get_sandboxuser(handle).vstring() } |
| 1423 | } |
| 1424 | |
| 1425 | pub 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 | |
| 1431 | pub fn (handle &Handle) option_get_usesyslog() bool { |
| 1432 | return if C.oracle_alpm_option_get_usesyslog(handle) == 0 { false } else { true } |
| 1433 | } |
| 1434 | |
| 1435 | pub 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 | |
| 1441 | pub fn (handle &Handle) option_get_noupgrades() &List { |
| 1442 | return C.oracle_alpm_option_get_noupgrades(handle) |
| 1443 | } |
| 1444 | |
| 1445 | pub 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 | |
| 1451 | pub 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 | |
| 1457 | pub 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 | |
| 1463 | pub 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 | |
| 1467 | pub fn (handle &Handle) option_get_no_extracts() &List { |
| 1468 | return C.oracle_alpm_option_get_noextracts(handle) |
| 1469 | } |
| 1470 | |
| 1471 | pub 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 | |
| 1477 | pub 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 | |
| 1483 | pub 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 | |
| 1489 | pub 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 | |
| 1493 | pub fn (handle &Handle) option_get_ignore_pkgs() &List { |
| 1494 | return C.oracle_alpm_option_get_ignorepkgs(handle) |
| 1495 | } |
| 1496 | |
| 1497 | pub 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 | |
| 1503 | pub 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 | |
| 1509 | pub 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 | |
| 1515 | pub fn (handle &Handle) option_get_ignore_groups() &List { |
| 1516 | return C.oracle_alpm_option_get_ignoregroups(handle) |
| 1517 | } |
| 1518 | |
| 1519 | pub 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 | |
| 1525 | pub 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 | |
| 1531 | pub 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 | |
| 1537 | pub 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 | |
| 1542 | pub 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 | |
| 1548 | pub 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 | |
| 1554 | pub 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 | |
| 1560 | pub 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 | |
| 1565 | pub 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 | |
| 1571 | pub 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 | |
| 1577 | pub 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 | |
| 1583 | pub fn (handle &Handle) option_get_checkspace() bool { |
| 1584 | return if C.oracle_alpm_option_get_checkspace(handle) != 0 { true } else { false } |
| 1585 | } |
| 1586 | |
| 1587 | pub 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 | |
| 1593 | pub fn (handle &Handle) option_get_dbext() string { |
| 1594 | return unsafe { C.oracle_alpm_option_get_dbext(handle).vstring() } |
| 1595 | } |
| 1596 | |
| 1597 | pub 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 | |
| 1603 | pub fn (handle &Handle) option_get_default_siglevel() ?SigLevel { |
| 1604 | return SigLevel.from(C.oracle_alpm_option_get_default_siglevel(handle)) or { none } |
| 1605 | } |
| 1606 | |
| 1607 | pub 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 | |
| 1613 | pub 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 | |
| 1617 | pub 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 | |
| 1623 | pub 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 | |
| 1627 | pub 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 | |
| 1633 | pub 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 | |
| 1637 | pub 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 | |
| 1643 | pub fn (handle &Handle) option_get_parallel_downloads() int { |
| 1644 | return C.oracle_alpm_option_get_parallel_downloads(handle) |
| 1645 | } |
| 1646 | |
| 1647 | pub 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. |
| 1654 | pub fn (handle &Handle) option_get_disable_sandbox() bool { |
| 1655 | return handle.option_get_disable_sandbox_filesystem() || handle.option_get_disable_sandbox_syscalls() |
| 1656 | } |
| 1657 | |
| 1658 | pub 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 | |
| 1663 | pub 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 | |
| 1671 | pub 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 | |
| 1677 | pub 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 | |
| 1681 | pub 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 | |
| 1687 | pub enum PackageReason { |
| 1688 | explicit = 0 |
| 1689 | depend = 1 |
| 1690 | unknown = 2 |
| 1691 | } |
| 1692 | |
| 1693 | pub enum PackageFrom { |
| 1694 | file = 1 |
| 1695 | localdb |
| 1696 | syncdb |
| 1697 | } |
| 1698 | |
| 1699 | pub enum PkgValidation { |
| 1700 | unknown = 0 |
| 1701 | none = 1 << 0 |
| 1702 | md5sum = 1 << 1 |
| 1703 | sha256sum = 1 << 2 |
| 1704 | signature = 1 << 3 |
| 1705 | } |
| 1706 | |
| 1707 | fn C.oracle_alpm_pkg_load(handle &Handle, filename &u8, full int, level int, pkg &&Package) int |
| 1708 | |
| 1709 | fn C.oracle_alpm_fetch_pkgurl(handle &Handle, urls &List, fetched &&List) int |
| 1710 | |
| 1711 | fn C.oracle_alpm_pkg_find(haystack &List, needle &u8) &Package |
| 1712 | |
| 1713 | fn C.oracle_alpm_pkg_free(pkg &Package) int |
| 1714 | |
| 1715 | fn C.oracle_alpm_pkg_checkmd5sum(pkg &Package) int |
| 1716 | |
| 1717 | fn C.oracle_alpm_pkg_compute_requiredby(pkg &Package) &List |
| 1718 | |
| 1719 | fn C.oracle_alpm_pkg_compute_optionalfor(pkg &Package) &List |
| 1720 | |
| 1721 | fn C.oracle_alpm_pkg_should_ignore(handle &Handle, pkg &Package) int |
| 1722 | |
| 1723 | fn C.oracle_alpm_pkg_get_handle(pkg &Package) &Handle |
| 1724 | |
| 1725 | fn C.oracle_alpm_pkg_get_filename(pkg &Package) &u8 |
| 1726 | |
| 1727 | fn C.oracle_alpm_pkg_get_base(pkg &Package) &u8 |
| 1728 | |
| 1729 | fn C.oracle_alpm_pkg_get_name(pkg &Package) &u8 |
| 1730 | |
| 1731 | fn C.oracle_alpm_pkg_get_version(pkg &Package) &u8 |
| 1732 | |
| 1733 | fn C.oracle_alpm_pkg_get_origin(pkg &Package) PackageFrom |
| 1734 | |
| 1735 | fn C.oracle_alpm_pkg_get_desc(pkg &Package) &u8 |
| 1736 | |
| 1737 | fn C.oracle_alpm_pkg_get_url(pkg &Package) &u8 |
| 1738 | |
| 1739 | fn C.oracle_alpm_pkg_get_builddate(pkg &Package) Time |
| 1740 | |
| 1741 | fn C.oracle_alpm_pkg_get_installdate(pkg &Package) Time |
| 1742 | |
| 1743 | fn C.oracle_alpm_pkg_get_packager(pkg &Package) &u8 |
| 1744 | |
| 1745 | fn C.oracle_alpm_pkg_get_md5sum(pkg &Package) &u8 |
| 1746 | |
| 1747 | fn C.oracle_alpm_pkg_get_sha256sum(pkg &Package) &u8 |
| 1748 | |
| 1749 | fn C.oracle_alpm_pkg_get_arch(pkg &Package) &u8 |
| 1750 | |
| 1751 | fn C.oracle_alpm_pkg_get_size(pkg &Package) i64 |
| 1752 | |
| 1753 | fn C.oracle_alpm_pkg_get_isize(pkg &Package) i64 |
| 1754 | |
| 1755 | fn C.oracle_alpm_pkg_get_reason(pkg &Package) PackageReason |
| 1756 | |
| 1757 | fn C.oracle_alpm_pkg_get_licenses(pkg &Package) &List |
| 1758 | |
| 1759 | fn C.oracle_alpm_pkg_get_groups(pkg &Package) &List |
| 1760 | |
| 1761 | fn C.oracle_alpm_pkg_get_depends(pkg &Package) &List |
| 1762 | |
| 1763 | fn C.oracle_alpm_pkg_get_optdepends(pkg &Package) &List |
| 1764 | |
| 1765 | fn C.oracle_alpm_pkg_get_checkdepends(pkg &Package) &List |
| 1766 | |
| 1767 | fn C.oracle_alpm_pkg_get_makedepends(pkg &Package) &List |
| 1768 | |
| 1769 | fn C.oracle_alpm_pkg_get_conflicts(pkg &Package) &List |
| 1770 | |
| 1771 | fn C.oracle_alpm_pkg_get_provides(pkg &Package) &List |
| 1772 | |
| 1773 | fn C.oracle_alpm_pkg_get_replaces(pkg &Package) &List |
| 1774 | |
| 1775 | fn C.oracle_alpm_pkg_get_files(pkg &Package) &Filelist |
| 1776 | |
| 1777 | fn C.oracle_alpm_pkg_get_backup(pkg &Package) &List |
| 1778 | |
| 1779 | fn C.oracle_alpm_pkg_get_db(pkg &Package) &DB |
| 1780 | |
| 1781 | fn C.oracle_alpm_pkg_get_base64_sig(pkg &Package) &u8 |
| 1782 | |
| 1783 | fn C.oracle_alpm_pkg_get_sig(pkg &Package, sig &&u8, sig_len &uint) int |
| 1784 | |
| 1785 | fn C.oracle_alpm_pkg_get_validation(pkg &Package) PkgValidation |
| 1786 | |
| 1787 | fn C.oracle_alpm_pkg_get_xdata(pkg &Package) &List |
| 1788 | |
| 1789 | fn C.oracle_alpm_pkg_has_scriptlet(pkg &Package) int |
| 1790 | |
| 1791 | fn C.oracle_alpm_pkg_download_size(newpkg &Package) i64 |
| 1792 | |
| 1793 | fn C.oracle_alpm_pkg_set_reason(pkg &Package, reason PackageReason) int |
| 1794 | |
| 1795 | fn C.oracle_alpm_pkg_changelog_open(pkg &Package) voidptr |
| 1796 | |
| 1797 | fn C.oracle_alpm_pkg_changelog_read(ptr voidptr, size uint, pkg &Package, fp voidptr) uint |
| 1798 | |
| 1799 | fn C.oracle_alpm_pkg_changelog_close(pkg &Package, fp voidptr) int |
| 1800 | |
| 1801 | fn C.oracle_alpm_pkg_mtree_open(pkg &Package) &C.Archive |
| 1802 | |
| 1803 | fn C.oracle_alpm_pkg_mtree_next(pkg &Package, archive &C.Archive, entry &&C.Archive_entry) int |
| 1804 | |
| 1805 | fn C.oracle_alpm_pkg_mtree_close(pkg &Package, archive &C.Archive) int |
| 1806 | |
| 1807 | pub 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 | |
| 1815 | pub 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 | |
| 1824 | pub 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 | |
| 1829 | pub fn (pkg &Package) free_pkg() ! { |
| 1830 | if C.oracle_alpm_pkg_free(pkg) != 0 { |
| 1831 | return pkg.get_handle().error() |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | pub fn (pkg &Package) checkmd5sum() int { |
| 1836 | return C.oracle_alpm_pkg_checkmd5sum(pkg) |
| 1837 | } |
| 1838 | |
| 1839 | pub fn pkg_vercmp(a string, b string) int { |
| 1840 | return C.oracle_alpm_pkg_vercmp(a.str, b.str) |
| 1841 | } |
| 1842 | |
| 1843 | fn 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 |
| 1850 | pub 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 | |
| 1868 | pub 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 | |
| 1886 | pub fn (handle &Handle) pkg_should_ignore(pkg &Package) int { |
| 1887 | return C.oracle_alpm_pkg_should_ignore(handle, pkg) |
| 1888 | } |
| 1889 | |
| 1890 | pub fn (pkg &Package) get_handle() &Handle { |
| 1891 | return C.oracle_alpm_pkg_get_handle(pkg) |
| 1892 | } |
| 1893 | |
| 1894 | @[inline] |
| 1895 | fn cstring_to_vstring_or_none(s &u8) string { |
| 1896 | return if s == unsafe { nil } { '' } else { unsafe { cstring_to_vstring(s) } } |
| 1897 | } |
| 1898 | |
| 1899 | pub fn (pkg &Package) get_filename() string { |
| 1900 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_filename(pkg)) |
| 1901 | } |
| 1902 | |
| 1903 | pub fn (pkg &Package) get_base() string { |
| 1904 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_base(pkg)) |
| 1905 | } |
| 1906 | |
| 1907 | pub fn (pkg &Package) get_name() string { |
| 1908 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_name(pkg)) |
| 1909 | } |
| 1910 | |
| 1911 | pub fn (pkg &Package) get_version() string { |
| 1912 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_version(pkg)) |
| 1913 | } |
| 1914 | |
| 1915 | pub fn (pkg &Package) get_origin() PackageFrom { |
| 1916 | return C.oracle_alpm_pkg_get_origin(pkg) |
| 1917 | } |
| 1918 | |
| 1919 | pub fn (pkg &Package) get_desc() string { |
| 1920 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_desc(pkg)) |
| 1921 | } |
| 1922 | |
| 1923 | pub fn (pkg &Package) get_url() string { |
| 1924 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_url(pkg)) |
| 1925 | } |
| 1926 | |
| 1927 | pub fn (pkg &Package) get_build_date() Time { |
| 1928 | return C.oracle_alpm_pkg_get_builddate(pkg) |
| 1929 | } |
| 1930 | |
| 1931 | pub fn (pkg &Package) get_install_date() Time { |
| 1932 | return C.oracle_alpm_pkg_get_installdate(pkg) |
| 1933 | } |
| 1934 | |
| 1935 | pub fn (pkg &Package) get_packager() string { |
| 1936 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_packager(pkg)) |
| 1937 | } |
| 1938 | |
| 1939 | pub fn (pkg &Package) get_md5_sum() string { |
| 1940 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_md5sum(pkg)) |
| 1941 | } |
| 1942 | |
| 1943 | pub fn (pkg &Package) get_sha256_sum() string { |
| 1944 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_sha256sum(pkg)) |
| 1945 | } |
| 1946 | |
| 1947 | pub fn (pkg &Package) get_arch() string { |
| 1948 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_arch(pkg)) |
| 1949 | } |
| 1950 | |
| 1951 | pub fn (pkg &Package) get_size() i64 { |
| 1952 | return C.oracle_alpm_pkg_get_size(pkg) |
| 1953 | } |
| 1954 | |
| 1955 | pub fn (pkg &Package) get_isize() i64 { |
| 1956 | return C.oracle_alpm_pkg_get_isize(pkg) |
| 1957 | } |
| 1958 | |
| 1959 | pub fn (pkg &Package) get_reason() PackageReason { |
| 1960 | return C.oracle_alpm_pkg_get_reason(pkg) |
| 1961 | } |
| 1962 | |
| 1963 | pub fn (pkg &Package) get_licenses() &List { |
| 1964 | return C.oracle_alpm_pkg_get_licenses(pkg) |
| 1965 | } |
| 1966 | |
| 1967 | pub fn (pkg &Package) get_groups() &List { |
| 1968 | return C.oracle_alpm_pkg_get_groups(pkg) |
| 1969 | } |
| 1970 | |
| 1971 | pub fn (pkg &Package) get_depends() &List { |
| 1972 | return C.oracle_alpm_pkg_get_depends(pkg) |
| 1973 | } |
| 1974 | |
| 1975 | pub fn (pkg &Package) get_opt_depends() &List { |
| 1976 | return C.oracle_alpm_pkg_get_optdepends(pkg) |
| 1977 | } |
| 1978 | |
| 1979 | pub fn (pkg &Package) get_check_depends() &List { |
| 1980 | return C.oracle_alpm_pkg_get_checkdepends(pkg) |
| 1981 | } |
| 1982 | |
| 1983 | pub fn (pkg &Package) get_make_depends() &List { |
| 1984 | return C.oracle_alpm_pkg_get_makedepends(pkg) |
| 1985 | } |
| 1986 | |
| 1987 | pub fn (pkg &Package) get_conflicts() &List { |
| 1988 | return C.oracle_alpm_pkg_get_conflicts(pkg) |
| 1989 | } |
| 1990 | |
| 1991 | pub fn (pkg &Package) get_provides() &List { |
| 1992 | return C.oracle_alpm_pkg_get_provides(pkg) |
| 1993 | } |
| 1994 | |
| 1995 | pub fn (pkg &Package) get_replaces() &List { |
| 1996 | return C.oracle_alpm_pkg_get_replaces(pkg) |
| 1997 | } |
| 1998 | |
| 1999 | pub fn (pkg &Package) get_files() &Filelist { |
| 2000 | return C.oracle_alpm_pkg_get_files(pkg) |
| 2001 | } |
| 2002 | |
| 2003 | pub fn (pkg &Package) get_backup() &List { |
| 2004 | return C.oracle_alpm_pkg_get_backup(pkg) |
| 2005 | } |
| 2006 | |
| 2007 | pub 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 | |
| 2012 | pub fn (pkg &Package) get_base64_sig() string { |
| 2013 | return cstring_to_vstring_or_none(C.oracle_alpm_pkg_get_base64_sig(pkg)) |
| 2014 | } |
| 2015 | |
| 2016 | pub 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 | |
| 2024 | pub fn (pkg &Package) get_validation() PkgValidation { |
| 2025 | return C.oracle_alpm_pkg_get_validation(pkg) |
| 2026 | } |
| 2027 | |
| 2028 | pub fn (pkg &Package) get_xdata() &List { |
| 2029 | return C.oracle_alpm_pkg_get_xdata(pkg) |
| 2030 | } |
| 2031 | |
| 2032 | pub fn (pkg &Package) has_scriptlet() bool { |
| 2033 | return if C.oracle_alpm_pkg_has_scriptlet(pkg) == 1 { true } else { false } |
| 2034 | } |
| 2035 | |
| 2036 | pub fn (newpkg &Package) download_size() i64 { |
| 2037 | return C.oracle_alpm_pkg_download_size(newpkg) |
| 2038 | } |
| 2039 | |
| 2040 | pub 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 | |
| 2046 | pub fn (pkg &Package) changelog_open() voidptr { |
| 2047 | return C.oracle_alpm_pkg_changelog_open(pkg) |
| 2048 | } |
| 2049 | |
| 2050 | pub 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 | |
| 2054 | pub 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 | |
| 2060 | pub 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. |
| 2066 | pub 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 | |
| 2081 | pub 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 | |
| 2087 | pub 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] |
| 2094 | pub 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 | |
| 2113 | pub const trans_flag_0 = TransFlag.zero() |
| 2114 | |
| 2115 | fn C.oracle_alpm_trans_get_flags(handle &Handle) int |
| 2116 | |
| 2117 | fn C.oracle_alpm_trans_get_add(handle &Handle) &List |
| 2118 | |
| 2119 | fn C.oracle_alpm_trans_get_remove(handle &Handle) &List |
| 2120 | |
| 2121 | fn C.oracle_alpm_trans_init(handle &Handle, flags int) int |
| 2122 | |
| 2123 | fn C.oracle_alpm_trans_prepare(handle &Handle, data &&List) int |
| 2124 | |
| 2125 | fn C.oracle_alpm_trans_commit(handle &Handle, data &&List) int |
| 2126 | |
| 2127 | fn C.oracle_alpm_trans_interrupt(handle &Handle) int |
| 2128 | |
| 2129 | fn C.oracle_alpm_trans_release(handle &Handle) int |
| 2130 | |
| 2131 | fn C.oracle_alpm_sync_sysupgrade(handle &Handle, enable_downgrade int) int |
| 2132 | |
| 2133 | fn C.oracle_alpm_add_pkg(handle &Handle, pkg &Package) int |
| 2134 | |
| 2135 | fn C.oracle_alpm_remove_pkg(handle &Handle, pkg &Package) int |
| 2136 | |
| 2137 | fn C.oracle_alpm_sync_get_new_version(pkg &Package, dbs_sync &List) &Package |
| 2138 | |
| 2139 | fn C.oracle_alpm_unlock(handle &Handle) int |
| 2140 | |
| 2141 | pub fn (handle &Handle) trans_get_flags() TransFlag { |
| 2142 | return unsafe { TransFlag(C.oracle_alpm_trans_get_flags(handle)) } |
| 2143 | } |
| 2144 | |
| 2145 | pub fn (handle &Handle) trans_get_add() &List { |
| 2146 | return C.oracle_alpm_trans_get_add(handle) |
| 2147 | } |
| 2148 | |
| 2149 | pub fn (handle &Handle) trans_get_remove() &List { |
| 2150 | return C.oracle_alpm_trans_get_remove(handle) |
| 2151 | } |
| 2152 | |
| 2153 | pub 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 | |
| 2159 | pub 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 |
| 2170 | pub struct DepProblem { |
| 2171 | pub: |
| 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 |
| 2183 | pub 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 | |
| 2272 | pub 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 | |
| 2280 | pub fn (handle &Handle) trans_interrupt() ! { |
| 2281 | if C.oracle_alpm_trans_interrupt(handle) != 0 { |
| 2282 | return handle.error() |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | pub fn (handle &Handle) trans_release() ! { |
| 2287 | if C.oracle_alpm_trans_release(handle) != 0 { |
| 2288 | return handle.error() |
| 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | pub 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 | |
| 2298 | pub fn (handle &Handle) add_pkg(pkg &Package) ! { |
| 2299 | if C.oracle_alpm_add_pkg(handle, pkg) != 0 { |
| 2300 | return handle.error() |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | pub fn (handle &Handle) remove_pkg(pkg &Package) ! { |
| 2305 | if C.oracle_alpm_remove_pkg(handle, pkg) != 0 { |
| 2306 | return handle.error() |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | pub 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 | |
| 2314 | pub 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 | |
| 2321 | pub 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 | |
| 2328 | fn C.oracle_alpm_compute_md5sum(&u8) &u8 |
| 2329 | fn C.oracle_alpm_compute_sha256sum(&u8) &u8 |
| 2330 | |
| 2331 | pub 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. |
| 2338 | pub fn (handle &Handle) unlock_async() int { |
| 2339 | return C.oracle_alpm_unlock(handle) |
| 2340 | } |
| 2341 | |
| 2342 | // bit positions, as for SigLevel |
| 2343 | @[flag] |
| 2344 | pub enum Caps { |
| 2345 | nls = 0 |
| 2346 | downloader = 1 |
| 2347 | signatures = 2 |
| 2348 | } |
| 2349 | |
| 2350 | fn C.oracle_alpm_version() &u8 |
| 2351 | |
| 2352 | fn C.oracle_alpm_capabilities() int |
| 2353 | |
| 2354 | fn C.oracle_alpm_sandbox_setup_child(handle &Handle, sandboxuser &u8, sandbox_path &u8, restrict_syscalls bool) int |
| 2355 | |
| 2356 | pub fn version() string { |
| 2357 | return unsafe { C.oracle_alpm_version().vstring() } |
| 2358 | } |
| 2359 | |
| 2360 | pub fn capabilities() Caps { |
| 2361 | return unsafe { Caps(C.oracle_alpm_capabilities()) } |
| 2362 | } |
| 2363 | |
| 2364 | pub 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' |
| 2375 | pub 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 |
| 2390 | pub 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 |
| 2399 | pub 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 |
| 2409 | pub 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 |
| 2439 | pub 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 |
| 2445 | pub 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 |
| 2457 | pub 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. |
| 2502 | pub 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 |
| 2509 | fn 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 |
| 2522 | fn 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 |
| 2533 | pub 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 | |