OSDN Git Service

Fixed the wrong implementation of show errormessage.
[portsreinstall/current.git] / lib / libcommand_forget.sh
1 #!/bin/sh -e
2 # ==============================================================================
3 # portsreinstall library script
4 # - "forget" command operation -
5 # Copyright (C) 2018 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
6 # This software is distributed under the 2-Clause BSD License.
7 # ==============================================================================
8
9 # ============= Operation of forget command =============
10 command_forget ()
11 {
12         message_echo "The temporary database is trying to forget about the specified ports as much as possible."
13         message_echo "Concretely, the data on each of the specified ports and their requirements/dependents is removed unless initially installed or required by other preserved ports."
14         message_echo
15         
16         # Preparation for inspection of the specified ports
17         PROGRAM_DEPENDS=''
18         _program_exec_and_record_completion__operation ()
19         {
20                 message_section_title "Preparation for inspection of the specified ports"
21                 rm -rf "${DBDIR}/forget"
22                 mkdir "${DBDIR}/forget"
23                 for list in masters remove_scope
24                 do
25                         rm -f "${DBDIR}/stage.loop_list/forget_$list"*
26                 done
27                 message_echo
28         }
29         program_exec_and_record_completion FORGET::PREPARATION_INSPECT_MASTER
30         
31         # (Re)initialization of the specified ports to inspect
32         pkgsys_eval_ports_glob "$@" > ${DBDIR}/stage.loop_list/forget_masters
33         
34         # Inspection of the specified ports
35         PROGRAM_DEPENDS='FORGET::PREPARATION_INSPECT_MASTER'
36         _program_exec_restartable_loop_operation__routine ()
37         {
38                 local origin origins_init
39                 origin=$1
40                 origins_init=`database_query_initial_orgins "$origin"`
41                 if [ -z "$origins_init" \
42                         -a `cat "${DBDIR}/requires/$origin/dependents.all.full" 2> /dev/null | wc -l` -eq 0 ]
43                 then
44                         message_echo "$origin"
45                         echo "$origin" >> ${DBDIR}/forget/remove.master
46                         cat "${DBDIR}/requires/$origin/requirements.all.full" \
47                                 2> /dev/null >> ${DBDIR}/forget/remove.scope || :
48                         database_build_forget "$origin"
49                 fi
50         }
51         _program_exec_and_record_completion__operation ()
52         {
53                 message_section_title "Inspection of the specified ports"
54                 message_echo "----------------"
55                 program_exec_restartable_loop_operation forget_masters
56                 message_echo "----------------"
57                 cat "${DBDIR}/forget/remove.scope" 2> /dev/null \
58                         | sort -u > ${DBDIR}/forget/remove.scope.tmp
59                 mv "${DBDIR}/forget/remove.scope.tmp" "${DBDIR}/forget/remove.scope"
60                 {
61                         cat "${DBDIR}/forget/remove.master" || :
62                         cat "${DBDIR}/forget/remove.scope" || :
63                 } 2> /dev/null | sort -u > ${DBDIR}/forget/remove.scope.filter
64                 ln -f "${DBDIR}/forget/remove.scope" "${DBDIR}/stage.loop_list/forget_remove_scope"
65                 message_echo
66         }
67         program_exec_and_record_completion FORGET::INSPECT_MASTER
68         
69         # Inspection of the requirements of the specified ports to remove
70         PROGRAM_DEPENDS='FORGET::INSPECT_MASTER'
71         _program_exec_restartable_loop_operation__routine ()
72         {
73                 local origin origins_init
74                 origin=$1
75                 origins_init=`database_query_initial_orgins "$origin"`
76                 if [ -z "$origins_init" ] \
77                         && ! grep -qv -Fx -f "${DBDIR}/forget/remove.scope.filter" \
78                                 "${DBDIR}/requires/$origin/dependents.all.full" \
79                                 2> /dev/null
80                 then
81                         message_echo "$origin"
82                         database_build_forget "$origin"
83                         echo "$origin" >> ${DBDIR}/forget/remove
84                 fi
85         }
86         _program_exec_and_record_completion__operation ()
87         {
88                 message_section_title "Inspection of the requirements of the specified ports to remove"
89                 message_echo "----------------"
90                 program_exec_restartable_loop_operation forget_remove_scope
91                 message_echo "----------------"
92                 {
93                         cat "${DBDIR}/forget/remove.master" || :
94                         cat "${DBDIR}/forget/remove" || :
95                 } 2> /dev/null | sort -u > ${DBDIR}/forget/remove.filter
96                 cat "${DBDIR}/inspected_ports.update" 2> /dev/null | sort -u \
97                         | grep -v -Fx -f "${DBDIR}/forget/remove.filter" \
98                                 > ${DBDIR}/inspected_ports.update.tmp 2> /dev/null || :
99                 mv "${DBDIR}/inspected_ports.update.tmp" "${DBDIR}/inspected_ports.update"
100                 message_echo
101         }
102         program_exec_and_record_completion FORGET::INSPECT_REQUIREMENTS_OF_REMOVED_PORTS
103         
104         # Set up so that ports are inspected again in the building process of the temporary database
105         program_deregister_stage_complete PREPARE_FOR_INSPECT_ALL_DEPENDENCIES
106         
107         # Clean up the database for this command because it is no more effective
108         program_deregister_stage_complete FORGET::PREPARATION_INSPECT_MASTER
109         
110         # Invalidate the completion
111         program_deregister_stage_complete ALL_COMPLETE
112 }