@@ -274,9 +274,18 @@ let with_updateinfo_xml gz_path f =
274
274
let clean_yum_cache name =
275
275
try
276
276
let params =
277
- [" --disablerepo=*" ; Printf. sprintf " --enablerepo=%s" name; " clean" ; " all" ]
277
+ match name with
278
+ | "*" ->
279
+ [" clean" ; " all" ]
280
+ | _ ->
281
+ [
282
+ " --disablerepo=*"
283
+ ; Printf. sprintf " --enablerepo=%s" name
284
+ ; " clean"
285
+ ; " all"
286
+ ]
278
287
in
279
- ignore (Helpers. call_script ! Xapi_globs. yum_cmd params)
288
+ ignore (Helpers. call_script ( Pkg_mgr. pmgr_cmd () ) params)
280
289
with e ->
281
290
warn " Unable to clean YUM cache for %s: %s" name (ExnHelper. string_of_exn e)
282
291
@@ -349,8 +358,12 @@ let write_yum_config ~source_url ~binary_url ~repo_gpgcheck ~gpgkey_path
349
358
)
350
359
351
360
let get_repo_config repo_name config_name =
352
- let config_params = [repo_name] in
353
- Helpers. call_script ! Xapi_globs. yum_config_manager_cmd config_params
361
+ let open Pkg_mgr in
362
+ let config_params =
363
+ (match active () with Yum -> [] | Dnf -> [" --dump" ]) @ [repo_name]
364
+ |> add_sub_cmd Repoconfig
365
+ in
366
+ Helpers. call_script (repoconfig_cmd () ) config_params
354
367
|> Astring.String. cuts ~sep: " \n "
355
368
|> List. filter_map (fun kv ->
356
369
let prefix = Printf. sprintf " %s = " config_name in
@@ -434,12 +447,10 @@ let with_local_repositories ~__context f =
434
447
(only to access the repo mirror in the coordinator!) *)
435
448
; repo_name
436
449
]
450
+ |> Pkg_mgr. add_sub_cmd Pkg_mgr. Repoconfig
437
451
in
438
452
ignore
439
- (Helpers. call_script
440
- ! Xapi_globs. yum_config_manager_cmd
441
- config_params
442
- ) ;
453
+ (Helpers. call_script (Pkg_mgr. repoconfig_cmd () ) config_params) ;
443
454
repo_name
444
455
)
445
456
enabled
@@ -484,20 +495,22 @@ let parse_updateinfo_list acc line =
484
495
acc
485
496
486
497
let is_obsoleted pkg_name repositories =
498
+ let open Pkg_mgr in
487
499
let params =
488
500
[
489
501
" -a"
490
- ; " --plugins"
491
502
; " --disablerepo=*"
492
503
; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
493
504
; " --whatobsoletes"
494
505
; pkg_name
495
506
; " --qf"
496
507
; " %{name}"
497
508
]
509
+ @ plugins ()
510
+ |> add_sub_cmd Repoquery
498
511
in
499
512
match
500
- Helpers. call_script ! Xapi_globs. repoquery_cmd params
513
+ Helpers. call_script ( repoquery_cmd () ) params
501
514
|> Astring.String. cuts ~sep: " \n " ~empty: false
502
515
with
503
516
| [] ->
@@ -523,7 +536,7 @@ let get_pkgs_from_yum_updateinfo_list sub_command repositories =
523
536
; sub_command
524
537
]
525
538
in
526
- Helpers. call_script ! Xapi_globs. yum_cmd params
539
+ Helpers. call_script ( Pkg_mgr. pmgr_cmd () ) params
527
540
|> assert_yum_error
528
541
|> Astring.String. cuts ~sep: " \n "
529
542
|> List. map (fun x ->
@@ -698,9 +711,20 @@ let parse_line_of_repoquery acc line =
698
711
acc
699
712
700
713
let get_installed_pkgs () =
714
+ let open Pkg_mgr in
701
715
let fmt = get_repoquery_fmt () in
702
- let params = [" -a" ; " --pkgnarrow=installed" ; " --qf" ; fmt] in
703
- Helpers. call_script ! Xapi_globs. repoquery_cmd params
716
+ let params =
717
+ ([" -a" ; " --qf" ; fmt]
718
+ @
719
+ match active () with
720
+ | Yum ->
721
+ [" --pkgnarrow=installed" ]
722
+ | Dnf ->
723
+ [" --installed" ]
724
+ )
725
+ |> add_sub_cmd Repoquery
726
+ in
727
+ Helpers. call_script (repoquery_cmd () ) params
704
728
|> Astring.String. cuts ~sep: " \n "
705
729
|> List. map (fun x ->
706
730
debug " repoquery installed: %s" x ;
@@ -710,19 +734,27 @@ let get_installed_pkgs () =
710
734
|> List. map (fun (pkg , _ ) -> (Pkg. to_name_arch_string pkg, pkg))
711
735
712
736
let get_pkgs_from_repoquery pkg_narrow repositories =
737
+ let open Pkg_mgr in
713
738
let fmt = get_repoquery_fmt () in
714
739
let params =
715
- [
716
- " -a"
717
- ; " --plugins"
718
- ; " --disablerepo=*"
719
- ; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
720
- ; Printf. sprintf " --pkgnarrow=%s" pkg_narrow
721
- ; " --qf"
722
- ; fmt
723
- ]
740
+ ([
741
+ " -a"
742
+ ; " --disablerepo=*"
743
+ ; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
744
+ ; " --qf"
745
+ ; fmt
746
+ ]
747
+ @
748
+ match active () with
749
+ | Yum ->
750
+ [Printf. sprintf " --pkgnarrow=%s" pkg_narrow; " --plugins" ]
751
+ | Dnf ->
752
+ [Printf. sprintf " --%s" pkg_narrow]
753
+ )
754
+ |> add_sub_cmd Repoquery
724
755
in
725
- Helpers. call_script ! Xapi_globs. repoquery_cmd params
756
+
757
+ Helpers. call_script (repoquery_cmd () ) params
726
758
|> Astring.String. cuts ~sep: " \n "
727
759
|> List. map (fun x ->
728
760
debug " repoquery available: %s" x ;
@@ -731,9 +763,13 @@ let get_pkgs_from_repoquery pkg_narrow repositories =
731
763
|> List. fold_left parse_line_of_repoquery []
732
764
733
765
let get_updates_from_repoquery repositories =
766
+ let open Pkg_mgr in
767
+ let updates_arg =
768
+ match active () with Yum -> " updates" | Dnf -> " upgrades"
769
+ in
734
770
List. iter (fun r -> clean_yum_cache r) repositories ;
735
771
(* Use 'updates' to decrease the number of packages to apply 'is_obsoleted' *)
736
- let updates = get_pkgs_from_repoquery " updates " repositories in
772
+ let updates = get_pkgs_from_repoquery updates_arg repositories in
737
773
(* 'new_updates' are a list of RPM packages to be installed, rather than updated *)
738
774
let new_updates =
739
775
get_pkgs_from_repoquery " available" repositories
@@ -936,20 +972,25 @@ module YumUpgradeOutput = struct
936
972
end
937
973
938
974
let get_updates_from_yum_upgrade_dry_run repositories =
975
+ let open Pkg_mgr in
939
976
let params =
940
- [
941
- " --disablerepo=* "
942
- ; Printf. sprintf " --enablerepo=%s " ( String. concat " , " repositories)
943
- ; " --assumeno "
944
- ; " --quiet "
945
- ; " upgrade"
946
- ]
977
+ ( match active () with Dnf -> [] | Yum -> [ " --quiet " ])
978
+ @ [
979
+ " --disablerepo=* "
980
+ ; Printf. sprintf " --enablerepo=%s " ( String. concat " , " repositories)
981
+ ; " --assumeno "
982
+ ; " upgrade"
983
+ ]
947
984
in
948
- match Forkhelpers. execute_command_get_output ! Xapi_globs. yum_cmd params with
985
+ match Forkhelpers. execute_command_get_output (pmgr_cmd () ) params with
949
986
| _ , _ ->
950
987
Some []
951
- | exception Forkhelpers. Spawn_internal_error (stderr , _ , Unix. WEXITED 1 ) -> (
952
- stderr |> YumUpgradeOutput. parse_output_of_dry_run |> function
988
+ | exception Forkhelpers .Spawn_internal_error (stderr, stdout, Unix. WEXITED 1 )
989
+ -> (
990
+ (* Yum put the details to stderr while dnf to stdout*)
991
+ (match active () with Yum -> stderr | Dnf -> stdout)
992
+ |> YumUpgradeOutput. parse_output_of_dry_run
993
+ |> function
953
994
| Ok (pkgs , Some txn_file ) ->
954
995
Unixext. unlink_safe txn_file ;
955
996
Some pkgs
0 commit comments