-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallation.ml
More file actions
865 lines (809 loc) · 32 KB
/
installation.ml
File metadata and controls
865 lines (809 loc) · 32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
open Util
open Pkg
open Repository
open Repository_search
open Status
open Packed_package
open Installed_package
open Configuration
(* Filters that are useful for constructing pipelines of operations to
* install and remove packages *)
let fetch_package (name : string) (version : version) (arch : arch)
(repo : repository) (status : status option) =
match status with None -> (None, None) | Some status ->
print_string_flush " Fetching the package";
match create_or_clean_tmp_dir () with
| false -> print_failed (); (None, None)
| true ->
match read_package repo name version arch with
| None -> print_failed (); (None, None)
| Some pkg ->
match static_of_dynamic_pkg pkg with
| None -> print_newline (); print_string
" Information is missing in the package";
print_failed (); (None, None)
| Some spkg ->
match unpack_packed_shape repo name version arch with
| false -> print_failed (); (None, None)
| true -> print_ok (); (Some status, Some spkg)
let check_for_file_collisions
(msg : string)
(files : string list)
(status : status option) =
match status with None -> None | Some status ->
print_string_flush msg;
match
List.fold_left
(fun s fn ->
match file_status (form_target_path fn) with
| Directory
| Other_file -> print_newline (); print_string_flush
(" \"" ^ fn ^ "\" exists already"); None
| Read_error -> print_newline (); print_string_flush
(" can not check for \"" ^ fn ^ "\""); None
| Non_existent -> s)
(Some status)
files
with
| None -> print_failed (); None
| Some status -> print_ok (); Some status
let unpack_files_to_filter spkg destination (excluded_files, status) =
match status with None -> None | Some status ->
(* This flushes stdout *)
print_string_flush " Unpacking files";
match unpack_files_to spkg destination excluded_files status with
| false -> print_failed (); None
| true -> print_ok (); Some status
let create_pkg_info_location (spkg : static_pkg) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Creating the package info location";
try
mkdir_p_at_target
(Tpm_config.package_info_location ^ "/" ^ spkg.sn)
0o755;
print_ok ();
Some status
with
| Unix.Unix_error (c,_,_) -> print_newline (); print_string
(" " ^ Unix.error_message c); print_failed (); None
| _ -> print_failed (); None
let remove_pkg_info_location
(spkg : static_pkg)
(status : status option) =
match status with None -> None | Some status ->
print_string_flush " Removing the package info location";
let path =
form_target_path (Tpm_config.package_info_location ^ "/" ^ spkg.sn)
in
if
match file_status path with
| Non_existent -> true
| Directory -> rmdir_r path
| Read_error ->
print_newline ();
print_string " Read error";
false
| Other_file ->
print_newline ();
print_string (" \"" ^ path ^ "\" is not a directory");
false
then
(print_ok (); Some status)
else
(print_failed (); None)
let copy_packaging_scripts (spkg : static_pkg) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Copying files to the package info location";
let package_info_location =
form_target_path (Tpm_config.package_info_location ^ "/" ^ spkg.sn)
in
match
try
Some (List.fold_left
(fun c s ->
let s = Tpm_config.tmp_dir ^ "/" ^ s
in
if Sys.file_exists (s)
then s::c
else c)
[]
all_packaging_scripts)
with
| Sys_error msg ->
print_newline ();
print_string_flush msg;
print_failed ();
None
| _ -> None
with
| None -> print_failed (); None
| Some pkg_scripts ->
try
install_files (0, 0) 0o755 pkg_scripts package_info_location;
print_ok ();
Some status
with
| Unix.Unix_error (c, _, _) ->
print_newline ();
print_string (" " ^ Unix.error_message c);
print_failed (); None
| _ -> print_failed (); None
let determine_files_to_exclude (spkg : static_pkg) (status : status option) =
let conf_determine_files_to_exclude spkg status =
([], status)
in
let sw_determine_files_to_exclude spkg status =
match status with None -> [], None | Some status ->
print_string_flush " Determining wich config files must be excluded";
match
List.fold_left
(fun (status, efs) (csum, cf) ->
match status with None -> (None, []) | Some status ->
let target_path =
form_target_path cf
in
match file_status (target_path) with
| Other_file ->
(match sha512sum_of_file_opt target_path with
| None -> (None, [])
| Some is_sum ->
match is_sum = csum with
| true -> (Some status, efs)
| false ->
print_newline ();
print_endline
(" config file \"" ^ cf ^ "\" does " ^
"already exist and differs");
print_string_flush
(" from the package's version, hence " ^
"not installing it");
(Some status, cf::efs))
| Non_existent -> (Some status, efs)
| Directory -> print_newline (); print_string_flush
(" config file \"" ^ cf ^
"\" does already exist as directory");
(None, [])
| Read_error -> print_newline (); print_string_flush
(" read error while testing for config file \"" ^
cf ^ "\"");
(None, []))
(Some status, [])
(List.rev spkg.scfiles)
with
| (None, _) -> print_failed (); ([], None)
| (Some status, l) -> print_ok (); (l, Some status)
in
match status with None -> [], None | Some status ->
(match spkg.st with
| Conf -> conf_determine_files_to_exclude spkg (Some status)
| Sw -> sw_determine_files_to_exclude spkg (Some status))
let remove_fs_items
((files : string list), (cfiles : (string * string) list),
(dirs : string list))
(force : bool)
(status : status option) =
let determine_files (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Determining wich files must be removed";
let rmfiles =
List.fold_left
(fun fs (cks, n) ->
match fs with None -> None | Some fs ->
match sha512sum_of_file_opt (form_target_path n) with
| None -> print_newline (); print_string_flush
(" failed to calculate sha512sum of file \"" ^
n ^ "\"");
if force then Some (n::fs) else None
| Some rs -> if rs = cks then Some (n::fs)
else
(print_newline ();
print_string_flush (" not removing config " ^
"file \"" ^ n ^ "\" because it was modified");
Some fs))
(* The config files shall be removed last. Hence reverse the
* list. *)
(Some (List.rev files))
cfiles
in
match rmfiles with None -> print_failed (); None | Some rmfiles ->
(* Reverse the list a second time *)
let rmfiles = List.rev rmfiles
in
print_ok ();
Some rmfiles
in
let remove_file n =
try
Sys.remove n;
true
with
| Sys_error msg -> print_newline ();
print_string_flush (" failed to remove \"" ^
n ^ "\": " ^ msg); false
| _ -> print_newline ();
print_string_flush (" failed to remove \"" ^ n ^
"\""); false
in
let remove_directory n =
try
Unix.rmdir n;
true
with
| Unix.Unix_error (c,_,_) -> print_newline(); print_string_flush
(" failed to remove directory \"" ^ n ^ "\": " ^
(Unix.error_message c)); false
| _ -> print_newline (); print_string_flush
(" failed to remove directory \"" ^ n ^ "\""); false
in
let remove_files (files : string list) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Removing files";
let s =
List.fold_left
(fun s fn ->
let fn = form_target_path fn
in
match file_status fn with
| Other_file -> remove_file fn && s
| Non_existent -> (print_newline (); print_string_flush
(" \"" ^ fn ^
"\" does not exist, hence not removing it"); s)
| Read_error -> print_newline (); print_string_flush
(" cannot read \"" ^ fn ^ "\""); false
| Directory -> print_newline (); print_string_flush
(" \"" ^ fn ^ "\" is a directory"); false)
true
files
in
if not s then (print_failed (); None)
else (print_ok (); Some status)
in
let remove_directories (dirs : string list) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Removing directories";
let s =
List.fold_left
(fun s dn ->
let dn = form_target_path dn
in
match file_status dn with
| Directory ->
(try
if Sys.readdir dn |> array_is_empty
then remove_directory dn && s
else s
with
| Sys_error msg -> print_newline ();
print_string msg; false
| _ -> print_newline ();
print_string_flush (" can not read " ^
"from \"" ^ dn ^ "\"");
false)
| Other_file -> print_newline (); print_string_flush
(" \"" ^ dn ^ "\" is not a directory"); false
| Non_existent -> print_newline (); print_string_flush
(" \"" ^ dn ^ "\" does not exist hence not " ^
"removing it");
s
| Read_error -> print_newline (); print_string_flush
(" cannot read from \"" ^ dn ^ "\""); false)
true
(* The directory list is sorted therefore processing it in reverse
* order means processing from inner to outer. *)
(List.rev dirs)
in
if not s then (print_failed (); None)
else (print_ok (); Some status)
in
match determine_files status with
| None -> None
| Some rmfiles ->
remove_files rmfiles status
|> remove_directories dirs
let execute_packaging_script_if_exists
(pkg_name : string)
(script_name : string)
(status : status option) =
match status with None -> None | Some status ->
print_string_flush (" Checking for " ^ script_name);
let spath =
form_target_path (
Tpm_config.package_info_location ^ "/" ^
pkg_name ^ "/" ^
script_name)
in
match file_status spath with
| Non_existent ->
print_ok ();
Some status
| Directory ->
print_newline ();
print_string (" It is a directory");
print_failed ();
None
| Read_error ->
print_newline ();
print_string (" Read error");
print_failed ();
None
| Other_file ->
print_ok ();
print_string_flush (" Running " ^ script_name);
let spath_args =
[| spath |]
in
try
Unix.chdir (form_target_path "/");
match run_program spath_args with
| (_, WEXITED 0) ->
print_ok (); Some status
| (_, WEXITED c) ->
print_newline ();
print_string (" " ^ script_name ^ " failed with code " ^
string_of_int c);
print_failed ();
None
| _ ->
print_newline ();
print_string (" " ^ script_name ^ " failed");
print_failed ();
None
with
Unix.Unix_error (c, _, _) ->
print_newline ();
print_string
(" Executing " ^ script_name ^ " failed: " ^
Unix.error_message c);
print_failed ();
None
let unconfigure_package (name : string) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Checking runtime for unconfiguring";
match !runtime_system with
| Directory_runtime _ ->
print_newline ();
print_string
(" A package can only be unconfigured on a native " ^
"runtime system");
print_failed ();
None
| Native_runtime ->
print_ok ();
execute_packaging_script_if_exists
name
Tpm_config.unconfiguresh_name
(Some status)
(* Install a package from a specific repository and mark it with a specific
* reason for installing it. *)
let elementary_install_package cfg name version reason repo status =
match status with None -> None | Some status ->
print_endline ("Installing package \"" ^ name ^ "\"=" ^
string_of_version version ^ " from " ^ (string_of_repository repo));
let check_not_installed (name : string) (status : status option) =
match status with None -> None | Some status ->
match select_status_tuple_by_name status name with
| None -> Some status
| Some _ ->
print_endline " The package is already registered in the database";
None
in
let mark_change (spkg : static_pkg) (reason : installation_reason)
((excluded_files : string list), (status : status option)) =
match status with None -> [], None | Some status ->
print_string_flush " Marking the change in status";
let status =
unique_insert_status_tuple status
(dynamic_of_static_pkg spkg, reason, Installing)
in
if write_status status |> not then (print_failed (); [], None)
else (print_ok (); (excluded_files, Some status))
in
let confirm_change (name : string) (status : status option) =
match status with None -> None | Some status ->
print_string " Commiting changes to status";
match select_status_tuple_by_name status name with
| None -> print_newline (); print_string
" the package vanished from status";
print_failed (); None
| Some (pkg, reason, _) ->
let status = update_status_tuple status (pkg, reason, Installed)
in
if write_status status
then (print_ok (); Some status)
else (print_failed (); None)
in
let status = check_not_installed name (Some status)
in
match fetch_package name version cfg.a repo status with
| (None, _)
| (Some _, None) -> None
| (Some status, Some spkg) ->
check_for_file_collisions
" Checking if any of the package's files exist already"
spkg.sfiles
(Some status)
|> determine_files_to_exclude spkg
|> mark_change spkg reason
|> unpack_files_to_filter spkg (
match !runtime_system with
| Native_runtime -> "/"
| Directory_runtime d -> d
)
|> create_pkg_info_location spkg
|> copy_packaging_scripts spkg
|> confirm_change name
(* Change a package from a specific repository and mark it with a specific
* reason for installing it. This is the elementary procedure that shall be
* used when a package is upgrades, downgraded or reinstelled. *)
let elementary_change_package cfg name version reason repo status =
match status with None -> None | Some status ->
print_endline ("Changing package \"" ^ name ^ "\" to version " ^
string_of_version version ^ " from " ^ (string_of_repository repo));
let check_current (name : string) (status : status option) =
match status with None -> None | Some status ->
match select_status_tuple_by_name status name with
| None ->
print_endline " The package is not installed";
None
| Some (old_pkg, _, old_state) ->
match static_of_dynamic_pkg old_pkg with
| None ->
print_endline " The current package is invalid";
None
| Some old_spkg ->
print_endline (" Current version is " ^
string_of_version old_spkg.sv);
match old_state with
| Configured
| Configuring
| Changing_unconf
| Changing
| Installed ->
Some (status, old_spkg, old_state)
| Installing
| Removing_unconf
| Removing ->
print_endline
(" No change is possible from the " ^
"package's current state: " ^
string_of_installation_status old_state);
None
in
let split_files
(old_spkg : static_pkg)
(spkg : static_pkg)
(status : status option) =
match status with None -> None | Some status ->
print_string_flush " Determining which files were added or removed";
let (added_files, files_to_remove) =
sorted_bidirectional_difference
compare_names
spkg.sfiles
old_spkg.sfiles
in
let (added_cfiles, cfiles_to_remove) =
sorted_bidirectional_difference
compare_cfile_pair
spkg.scfiles
old_spkg.scfiles
in
let (added_dirs, dirs_to_remove) =
sorted_bidirectional_difference
compare_names
spkg.sdirs
old_spkg.sdirs
in
print_ok ();
Some (
(added_files, added_cfiles, added_dirs),
(files_to_remove, cfiles_to_remove, dirs_to_remove),
status)
in
let change_unconfigure_package
(name : string)
(pkg_state : installation_status)
(status : status option) =
let mark_unconfigure (name : string) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Marking unconfiguration in status";
match select_status_tuple_by_name status name with
| None ->
print_newline ();
print_string " The package disappeared from status";
None
| Some (pkg, reason, _) ->
let status =
update_status_tuple status
(pkg, reason, Changing_unconf)
in
match write_status status with
| false -> print_failed (); None
| true -> print_ok (); Some status
in
match status with None -> None | Some status ->
match pkg_state with
| Installing
| Installed
| Configuring
| Changing
| Removing_unconf
| Removing -> Some status
| Configured
| Changing_unconf ->
(* Check if the runtime system is native before changing the
* system's state *)
match !runtime_system with
| Directory_runtime _ ->
print_string
(" The package needs to be unconfigured but the " ^
"runtime system is not native.");
print_failed ();
None
| Native_runtime ->
mark_unconfigure name (Some status)
|> unconfigure_package name
in
let mark_change
(trans_spkg : static_pkg)
(reason : installation_reason)
(added_files, added_cfiles, added_dirs)
((excluded_files : string list), (status : status option)) =
match status with None -> [], None | Some status ->
print_string_flush " Marking the change in status";
let status =
update_status_tuple status
(dynamic_of_static_pkg trans_spkg, reason, Changing)
in
if write_status status |> not then (print_failed (); [], None)
else (print_ok (); (excluded_files, Some status))
in
let confirm_change
(spkg : static_pkg) (status : status option) =
match status with None -> None | Some status ->
print_string " Commiting changes to status";
let status =
update_status_tuple status
(dynamic_of_static_pkg spkg, reason, Installed)
in
if write_status status
then (print_ok (); Some status)
else (print_failed (); None)
in
match check_current name (Some status) with
| None -> None
| Some (status, old_spkg, old_state) ->
match fetch_package name version cfg.a repo (Some status) with
| (None, _)
| (Some _, None) -> None
| (Some status, Some spkg) ->
match split_files old_spkg spkg (Some status) with
| None -> None
| Some (added_fs_items, fs_items_to_remove, status) ->
let (added_files, added_cfiles, added_dirs) =
added_fs_items
in
(* trans_spkg is the new package but with the old fs items extended by
* the new ones therefore not overwriting cfiles' checksums *)
let trans_spkg =
{spkg with
sfiles = sorted_merge compare_names old_spkg.sfiles added_files;
scfiles = sorted_merge compare_cfile_pair old_spkg.scfiles added_cfiles;
sdirs = sorted_merge compare_names old_spkg.sdirs added_dirs}
in
(* oldconf_spkg is the new package but with the old checksums for previous
* conf files *)
let oldconf_spkg =
let cfiles =
List.map
(fun (c, p) ->
match rassoc_opt p old_spkg.scfiles with
| None -> (c, p)
| Some c -> (c, p))
spkg.scfiles
in
{spkg with scfiles = cfiles}
in
change_unconfigure_package spkg.sn old_state (Some status)
|> check_for_file_collisions
" Checking if any of the added files exist already"
added_files
|> determine_files_to_exclude oldconf_spkg
|> mark_change trans_spkg reason added_fs_items
|> unpack_files_to_filter spkg (
match !runtime_system with
| Native_runtime -> "/"
| Directory_runtime d -> d
)
|> remove_pkg_info_location spkg
|> create_pkg_info_location spkg
|> copy_packaging_scripts spkg
|> remove_fs_items fs_items_to_remove false
|> confirm_change spkg
let elementary_configure_package (name : string) (status : status option) =
match status with None -> None | Some status ->
print_endline ("Configuring package \"" ^ name ^ "\"");
let check (name : string) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Checking for the package and the runtime";
match !runtime_system with
| Directory_runtime _ ->
print_newline ();
print_string
(" Configuring is only supported on a native runtime " ^
"system");
print_failed ();
None
| Native_runtime ->
match select_status_tuple_by_name status name with
| None ->
print_newline ();
print_string " Package not found";
print_failed ();
None
| Some (pkg, reason, pstate) ->
match pstate with
| Installing
| Configured
| Changing
| Changing_unconf
| Removing
| Removing_unconf ->
print_newline ();
print_string
(" Package in invalid state \"" ^
string_of_installation_status pstate ^ "\"");
print_failed ();
None
| Installed
| Configuring ->
print_ok ();
Some ((pkg, reason, pstate), status)
in
let mark_change
(pkg : pkg)
(reason : installation_reason)
(status : status option) =
match status with None -> None | Some status ->
print_string_flush " Marking change in status";
let status =
update_status_tuple status (pkg, reason, Configuring)
in
match write_status status with
| false ->
print_failed ();
None
| true ->
print_ok ();
Some status
in
let commit_change
(pkg : pkg)
(reason : installation_reason)
(status : status option) =
match status with None -> None | Some status ->
print_string_flush " Commiting change to status";
let status =
update_status_tuple status (pkg, reason, Configured)
in
match write_status status with
| false ->
print_failed ();
None
| true ->
print_ok ();
Some status
in
match check name (Some status) with
| None -> None
| Some ((pkg, reason, pstate), status) ->
mark_change pkg reason (Some status)
|> execute_packaging_script_if_exists name Tpm_config.configuresh_name
|> commit_change pkg reason
let elementary_remove_package
(name : string)
(force : bool)
(status : status option) =
match status with None -> None | Some status ->
print_endline ("Removing package \"" ^ name ^ "\":");
let retrieve_package (name : string) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Retrieving the package from status";
match select_status_tuple_by_name status name with
| None ->
print_failed ();
None
| Some (pkg, reason, pstate) ->
match static_of_dynamic_pkg pkg with
| None ->
print_newline ();
print_string " Invalid package in status";
print_failed ();
None
| Some spkg ->
print_ok ();
Some (spkg, reason, pstate, status)
in
let remove_unconfigure_package
(name : string)
(pkg_state : installation_status)
(status : status option) =
let mark_unconfigure (name : string) (status : status option) =
match status with None -> None | Some status ->
print_string_flush " Marking unconfiguration in status";
match select_status_tuple_by_name status name with
| None ->
print_newline ();
print_string " The package disappeared from status";
print_failed ();
None
| Some (pkg, reason, _) ->
let status =
update_status_tuple status
(pkg, reason, Removing_unconf)
in
match write_status status with
| false -> print_failed (); None
| true -> print_ok (); Some status
in
match status with None -> None | Some status ->
match pkg_state with
| Installing
| Installed
| Changing
| Removing -> Some status
| Configured
| Configuring
| Changing_unconf
| Removing_unconf ->
(* Check if the runtime system is native before changing the
* system's state *)
match !runtime_system with
| Directory_runtime _ ->
print_string
(" The package needs to be unconfigured but the " ^
"runtime system is not native.");
print_failed ();
None
| Native_runtime ->
mark_unconfigure name (Some status)
|> unconfigure_package name
in
let mark_removal
(spkg : static_pkg)
(reason : installation_reason)
(status : status option) =
match status with None -> None | Some status ->
print_string_flush " Marking removal in status";
let status =
update_status_tuple status
(dynamic_of_static_pkg spkg, reason, Removing)
in
match write_status status with
| false -> print_failed (); None
| true -> print_ok (); Some status
in
let commit_removal
(spkg : static_pkg)
(reason : installation_reason)
(status : status option) =
match status with None -> None | Some status ->
print_string_flush " Removing package from status";
let status =
delete_status_tuple status
(dynamic_of_static_pkg spkg, reason, Removing)
in
match write_status status with
| false -> print_failed (); None
| true -> print_ok (); Some status
in
match retrieve_package name (Some status) with
| None -> None
| Some (spkg, reason, pstate, status) ->
let fs_items_to_remove =
(spkg.sfiles, spkg.scfiles, spkg.sdirs)
in
remove_unconfigure_package name pstate (Some status)
|> mark_removal spkg reason
|> remove_fs_items fs_items_to_remove force
|> remove_pkg_info_location spkg
|> commit_removal spkg reason