@@ -16,6 +16,12 @@ type mgr = Yum | Dnf
1616
1717type cmd_line = {cmd : string ; params : string list }
1818
19+ module Updateinfo = struct
20+ type t = Available | Updates
21+
22+ let to_string = function Available -> " available" | Updates -> " updates"
23+ end
24+
1925let active () =
2026 match Sys. file_exists ! Xapi_globs. dnf_cmd with true -> Dnf | false -> Yum
2127
@@ -27,7 +33,7 @@ module type S = sig
2733 val clean_cache : repo_name :string -> cmd_line
2834
2935 val get_pkgs_from_updateinfo :
30- sub_command : string -> repositories :string list -> cmd_line
36+ Updateinfo .t -> repositories :string list -> cmd_line
3137
3238 val get_updates_from_upgrade_dry_run : repositories :string list -> cmd_line
3339
@@ -61,7 +67,7 @@ module type Args = sig
6167
6268 val clean_cache : string -> string list
6369
64- val get_pkgs_from_updateinfo : string -> string list -> string list
70+ val get_pkgs_from_updateinfo : Updateinfo .t -> string list -> string list
6571
6672 val get_updates_from_upgrade_dry_run : string list -> string list
6773
8490
8591let repoquery_sep = " :|"
8692
87- let fmt =
88- [" name" ; " epoch" ; " version" ; " release" ; " arch" ; " repoid" ]
89- |> List. map (fun field -> Printf. sprintf " %%{%s}" field) (* %{field} *)
90- |> String. concat repoquery_sep
91-
9293module Common_args = struct
94+ let fmt =
95+ [" name" ; " epoch" ; " version" ; " release" ; " arch" ; " repoid" ]
96+ |> List. map (fun field -> Printf. sprintf " %%{%s}" field) (* %{field} *)
97+ |> String. concat repoquery_sep
98+
9399 let clean_cache = function
94100 | "*" ->
95101 [" clean" ; " all" ]
@@ -101,20 +107,9 @@ module Common_args = struct
101107 ; " all"
102108 ]
103109
104- let get_pkgs_from_updateinfo sub_command repositories =
105- [
106- " -q"
107- ; " --disablerepo=*"
108- ; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
109- ; " updateinfo"
110- ; " list"
111- ; sub_command
112- ]
113-
114110 let is_obsoleted pkg_name repositories =
115111 [
116- " -a"
117- ; " --disablerepo=*"
112+ " --disablerepo=*"
118113 ; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
119114 ; " --whatobsoletes"
120115 ; pkg_name
@@ -132,14 +127,14 @@ module Common_args = struct
132127
133128 let repoquery repositories =
134129 [
135- " -a"
136- ; " --disablerepo=*"
130+ " --disablerepo=*"
137131 ; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
138- ; " --qf"
139- ; fmt
140132 ]
141133
142- let config_repo repo_name config = config @ [repo_name]
134+ let config_repo repo_name config =
135+ (* Add --setopt to repo options *)
136+ List. map (fun x -> Printf. sprintf " --setopt=%s.%s" repo_name x) config
137+ |> fun x -> [" --save" ] @ x @ [repo_name]
143138
144139 let make_cache repo_name =
145140 [
@@ -153,7 +148,6 @@ module Common_args = struct
153148 [
154149 " -p"
155150 ; ! Xapi_globs. local_pool_repo_dir
156- ; " --downloadcomps"
157151 ; " --download-metadata"
158152 ; " --delete"
159153 ; " --newest-only"
172166module Yum_args : Args = struct
173167 include Common_args
174168
175- let repoquery_installed () = [" -a " ; " --pkgnarrow=installed" ; " --qf" ; fmt]
169+ let repoquery_installed () = [" --all " ; " --pkgnarrow=installed" ; " --qf" ; fmt]
176170
177171 let pkg_cmd = ! Xapi_globs. yum_cmd
178172
@@ -186,21 +180,35 @@ module Yum_args : Args = struct
186180 [" --quiet" ] @ Common_args. get_updates_from_upgrade_dry_run repositories
187181
188182 let is_obsoleted pkg_name repositories =
189- Common_args. is_obsoleted pkg_name repositories @ [" --plugins" ]
183+ [ " --all " ] @ Common_args. is_obsoleted pkg_name repositories @ [" --plugins" ]
190184
191185 let repoquery_available repositories =
192186 Common_args. repoquery repositories
193- @ [" --pkgnarrow" ; " available" ; " --plugins" ]
187+ @ [" --qf " ; fmt; " --all " ; " -- pkgnarrow" ; " available" ; " --plugins" ]
194188
195189 let repoquery_updates repositories =
196- Common_args. repoquery repositories @ [" --pkgnarrow" ; " updates" ; " --plugins" ]
190+ Common_args. repoquery repositories
191+ @ [" --qf" ; fmt; " --all" ; " --pkgnarrow" ; " updates" ; " --plugins" ]
197192
198- let sync_repo repo_name = Common_args. sync_repo repo_name @ [" --plugins" ]
193+ let sync_repo repo_name =
194+ Common_args. sync_repo repo_name @ [" --downloadcomps" ; " --plugins" ]
199195
200196 let get_repo_config repo_name = [repo_name]
197+
198+ let get_pkgs_from_updateinfo updateinfo repositories =
199+ [
200+ " -q"
201+ ; " --disablerepo=*"
202+ ; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
203+ ; " updateinfo"
204+ ; " list"
205+ ; Updateinfo. to_string updateinfo
206+ ]
201207end
202208
203209module Dnf_args : Args = struct
210+ include Common_args
211+
204212 let pkg_cmd = ! Xapi_globs. dnf_cmd
205213
206214 let repoquery_cmd = ! Xapi_globs. dnf_cmd
@@ -209,6 +217,9 @@ module Dnf_args : Args = struct
209217
210218 let reposync_cmd = ! Xapi_globs. dnf_cmd
211219
220+ (* dnf5 removed ending line breaker, we need to add it back *)
221+ let fmt = Printf. sprintf " %s\n " Common_args. fmt
222+
212223 type sub_cmd = Repoquery | Repoconfig | Reposync
213224
214225 let sub_cmd_to_string = function
@@ -221,29 +232,39 @@ module Dnf_args : Args = struct
221232
222233 let add_sub_cmd sub_cmd params = [sub_cmd_to_string sub_cmd] @ params
223234
224- include Common_args
225-
226235 let repoquery_installed () =
227- [" -a" ; " --qf" ; fmt; " --installed" ] |> add_sub_cmd Repoquery
236+ [" --qf" ; fmt; " --installed" ] |> add_sub_cmd Repoquery
237+
238+ let config_repo repo_name config =
239+ config |> List. map (fun x -> Printf. sprintf " %s.%s" repo_name x) |> fun x ->
240+ [" setopt" ] @ x |> add_sub_cmd Repoconfig
228241
229242 let is_obsoleted pkg_name repositories =
230243 Common_args. is_obsoleted pkg_name repositories |> add_sub_cmd Repoquery
231244
232245 let repoquery_available repositories =
233- Common_args. repoquery repositories @ [" --available" ]
246+ Common_args. repoquery repositories @ [" --qf " ; fmt; " -- available" ]
234247 |> add_sub_cmd Repoquery
235248
236249 let repoquery_updates repositories =
237- Common_args. repoquery repositories @ [" --upgrades" ] |> add_sub_cmd Repoquery
238-
239- let config_repo repo_name config =
240- Common_args. config_repo repo_name config |> add_sub_cmd Repoconfig
250+ Common_args. repoquery repositories @ [" --qf" ; fmt; " --upgrades" ]
251+ |> add_sub_cmd Repoquery
241252
242253 let sync_repo repo_name =
243254 Common_args. sync_repo repo_name |> add_sub_cmd Reposync
244255
245256 let get_repo_config repo_name =
246257 [" --dump" ; repo_name] |> add_sub_cmd Repoconfig
258+
259+ let get_pkgs_from_updateinfo updateinfo repositories =
260+ [
261+ " -q"
262+ ; " --disablerepo=*"
263+ ; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
264+ ; " advisory"
265+ ; " list"
266+ ; (updateinfo |> Updateinfo. to_string |> fun x -> Printf. sprintf " --%s" x)
267+ ]
247268end
248269
249270module Cmd_line (M : Args ) : S = struct
@@ -256,11 +277,8 @@ module Cmd_line (M : Args) : S = struct
256277
257278 let clean_cache ~repo_name = {cmd= M. pkg_cmd; params= M. clean_cache repo_name}
258279
259- let get_pkgs_from_updateinfo ~sub_command ~repositories =
260- {
261- cmd= M. pkg_cmd
262- ; params= M. get_pkgs_from_updateinfo sub_command repositories
263- }
280+ let get_pkgs_from_updateinfo updateinfo ~repositories =
281+ {cmd= M. pkg_cmd; params= M. get_pkgs_from_updateinfo updateinfo repositories}
264282
265283 let get_updates_from_upgrade_dry_run ~repositories =
266284 {cmd= M. pkg_cmd; params= M. get_updates_from_upgrade_dry_run repositories}
0 commit comments