@@ -16,6 +16,12 @@ type mgr = Yum | Dnf
16
16
17
17
type cmd_line = {cmd : string ; params : string list }
18
18
19
+ module Updateinfo = struct
20
+ type t = Available | Updates
21
+
22
+ let to_string = function Available -> " available" | Updates -> " updates"
23
+ end
24
+
19
25
let active () =
20
26
match Sys. file_exists ! Xapi_globs. dnf_cmd with true -> Dnf | false -> Yum
21
27
@@ -27,7 +33,7 @@ module type S = sig
27
33
val clean_cache : repo_name :string -> cmd_line
28
34
29
35
val get_pkgs_from_updateinfo :
30
- sub_command : string -> repositories :string list -> cmd_line
36
+ Updateinfo .t -> repositories :string list -> cmd_line
31
37
32
38
val get_updates_from_upgrade_dry_run : repositories :string list -> cmd_line
33
39
@@ -61,7 +67,7 @@ module type Args = sig
61
67
62
68
val clean_cache : string -> string list
63
69
64
- val get_pkgs_from_updateinfo : string -> string list -> string list
70
+ val get_pkgs_from_updateinfo : Updateinfo .t -> string list -> string list
65
71
66
72
val get_updates_from_upgrade_dry_run : string list -> string list
67
73
84
90
85
91
let repoquery_sep = " :|"
86
92
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
-
92
93
module 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
+
93
99
let clean_cache = function
94
100
| "*" ->
95
101
[" clean" ; " all" ]
@@ -101,20 +107,9 @@ module Common_args = struct
101
107
; " all"
102
108
]
103
109
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
-
114
110
let is_obsoleted pkg_name repositories =
115
111
[
116
- " -a"
117
- ; " --disablerepo=*"
112
+ " --disablerepo=*"
118
113
; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
119
114
; " --whatobsoletes"
120
115
; pkg_name
@@ -132,14 +127,14 @@ module Common_args = struct
132
127
133
128
let repoquery repositories =
134
129
[
135
- " -a"
136
- ; " --disablerepo=*"
130
+ " --disablerepo=*"
137
131
; Printf. sprintf " --enablerepo=%s" (String. concat " ," repositories)
138
- ; " --qf"
139
- ; fmt
140
132
]
141
133
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]
143
138
144
139
let make_cache repo_name =
145
140
[
@@ -153,7 +148,6 @@ module Common_args = struct
153
148
[
154
149
" -p"
155
150
; ! Xapi_globs. local_pool_repo_dir
156
- ; " --downloadcomps"
157
151
; " --download-metadata"
158
152
; " --delete"
159
153
; " --newest-only"
172
166
module Yum_args : Args = struct
173
167
include Common_args
174
168
175
- let repoquery_installed () = [" -a " ; " --pkgnarrow=installed" ; " --qf" ; fmt]
169
+ let repoquery_installed () = [" --all " ; " --pkgnarrow=installed" ; " --qf" ; fmt]
176
170
177
171
let pkg_cmd = ! Xapi_globs. yum_cmd
178
172
@@ -186,21 +180,35 @@ module Yum_args : Args = struct
186
180
[" --quiet" ] @ Common_args. get_updates_from_upgrade_dry_run repositories
187
181
188
182
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" ]
190
184
191
185
let repoquery_available repositories =
192
186
Common_args. repoquery repositories
193
- @ [" --pkgnarrow" ; " available" ; " --plugins" ]
187
+ @ [" --qf " ; fmt; " --all " ; " -- pkgnarrow" ; " available" ; " --plugins" ]
194
188
195
189
let repoquery_updates repositories =
196
- Common_args. repoquery repositories @ [" --pkgnarrow" ; " updates" ; " --plugins" ]
190
+ Common_args. repoquery repositories
191
+ @ [" --qf" ; fmt; " --all" ; " --pkgnarrow" ; " updates" ; " --plugins" ]
197
192
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" ]
199
195
200
196
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
+ ]
201
207
end
202
208
203
209
module Dnf_args : Args = struct
210
+ include Common_args
211
+
204
212
let pkg_cmd = ! Xapi_globs. dnf_cmd
205
213
206
214
let repoquery_cmd = ! Xapi_globs. dnf_cmd
@@ -209,6 +217,9 @@ module Dnf_args : Args = struct
209
217
210
218
let reposync_cmd = ! Xapi_globs. dnf_cmd
211
219
220
+ (* dnf5 removed ending line breaker, we need to add it back *)
221
+ let fmt = Printf. sprintf " %s\n " Common_args. fmt
222
+
212
223
type sub_cmd = Repoquery | Repoconfig | Reposync
213
224
214
225
let sub_cmd_to_string = function
@@ -221,29 +232,39 @@ module Dnf_args : Args = struct
221
232
222
233
let add_sub_cmd sub_cmd params = [sub_cmd_to_string sub_cmd] @ params
223
234
224
- include Common_args
225
-
226
235
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
228
241
229
242
let is_obsoleted pkg_name repositories =
230
243
Common_args. is_obsoleted pkg_name repositories |> add_sub_cmd Repoquery
231
244
232
245
let repoquery_available repositories =
233
- Common_args. repoquery repositories @ [" --available" ]
246
+ Common_args. repoquery repositories @ [" --qf " ; fmt; " -- available" ]
234
247
|> add_sub_cmd Repoquery
235
248
236
249
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
241
252
242
253
let sync_repo repo_name =
243
254
Common_args. sync_repo repo_name |> add_sub_cmd Reposync
244
255
245
256
let get_repo_config repo_name =
246
257
[" --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
+ ]
247
268
end
248
269
249
270
module Cmd_line (M : Args ) : S = struct
@@ -256,11 +277,8 @@ module Cmd_line (M : Args) : S = struct
256
277
257
278
let clean_cache ~repo_name = {cmd= M. pkg_cmd; params= M. clean_cache repo_name}
258
279
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}
264
282
265
283
let get_updates_from_upgrade_dry_run ~repositories =
266
284
{cmd= M. pkg_cmd; params= M. get_updates_from_upgrade_dry_run repositories}
0 commit comments