2 # ==============================================================================
3 # portsreinstall library script
4 # - Operations for maintaining the temporary database -
5 # Copyright (C) 2018-2021 Mamoru Sakaue, MwGhennndo, All Rights Reserved.
6 # This software is distributed under the 2-Clause BSD License.
7 # ==============================================================================
10 # ============= Variables =============
12 DATABASE_IS_OBSOLETE=no
15 # ============= Cleaning of the temporary database =============
16 database_maintain_clean_all ()
21 # ============= Reset the execution result flags =============
22 database_maintain_reset_execflag ()
24 rm -rf "${DBDIR}/execflag"
27 # ============= Load a temporary database from an archive =============
28 database_maintain_load ()
30 local filepath dbdir_parent
32 dbdir_parent=`dirname "${DBDIR}"`
33 mkdir -p "$dbdir_parent"
34 tar xzf "$filepath" -C "$dbdir_parent" --exclude "*/.lock"
37 # ============= Save the temporary database to an archive =============
38 database_maintain_save ()
40 local filepath dbdir_parent dbdir_node
42 dbdir_parent=`dirname "${DBDIR}"`
43 dbdir_node=`basename "${DBDIR}"`
44 tar czf "$filepath" -C "$dbdir_parent" "$dbdir_node"
47 # ============= Creation of the temporary database =============
48 database_maintain_create ()
51 [ `id -u` -eq 0 ] && mkdir -p "${DBDIR}"
52 misc_lock_duplicated_executions "${DBDIR}/.lock"
53 if [ -e "${DBDIR}/MYVERSION" ]
55 if ! grep -q -E "$COMPATIBLE_VERSIONS" "${DBDIR}/MYVERSION" 2> /dev/null
57 message_echo "ERROR: The current temporary database is incompatible. You must delete it by" >&2
58 message_echo " ${APPNAME} clean force" >&2
59 message_echo " in order to enable the current version." >&2
62 elif misc_is_superuser_privilege
64 echo "$MYVERSION" > ${DBDIR}/MYVERSION
66 DATABASE_VERSION=`cat "${DBDIR}"/MYVERSION 2> /dev/null || :`
67 misc_is_superuser_privilege || return 0
68 for subdir in initial requires replace targets obsolete backup_packages \
69 stage.loop_list stage.complete stage.reinit_loop stage.depends
71 mkdir -p "${DBDIR}/$subdir"
75 # ============= Mark the use of the temporary database =============
76 database_maintain_mark_use ()
78 touch "${DBDIR}/in_use"
81 # ============= Check the use of the temporary database =============
82 database_maintain_chk_use ()
84 [ -e "${DBDIR}/in_use" ]
87 # ============= Refresh the temporary database =============
88 database_maintain_refresh ()
90 misc_is_superuser_privilege || return
91 [ $opt_suppress_obsolete_db_clean = no ] || return
92 message_echo "INFO: The temporary database is cleaned up."
94 [ -d "${DBDIR}" -a ! -d "${DBDIR}.tmp" ] && mv "${DBDIR}" "${DBDIR}.tmp"
95 database_maintain_create
96 mv "${DBDIR}.tmp/saved_options.sh" "${DBDIR}" 2> /dev/null || :
97 mv "${DBDIR}.tmp/backup_packages" "${DBDIR}" 2> /dev/null || :
98 mv "${DBDIR}.tmp/backup_pkgarcs.lst" "${DBDIR}" 2> /dev/null || :
102 # ============= Clean up the temporary database for upgrade of this utility =============
103 database_maintain_clean_for_self_upgrade ()
105 misc_is_superuser_privilege || return
106 [ $opt_suppress_obsolete_db_clean = no ] || return
108 database_maintain_create
109 [ -e "${DBDIR}/MYVERSION" ] && mv "${DBDIR}/MYVERSION" "${DBDIR}/MYVERSION.prev"
113 # ============= Check whether the temporary database is newer than the ports tree and refresh if so =============
114 database_maintain_refresh_if_obsolete ()
116 if [ "${PORTS_INDEX_DB}" -nt "${DBDIR}"/MYVERSION ] && misc_is_superuser_privilege
118 if [ $opt_suppress_obsolete_db_clean = no -a "z${command}" = zclean ]
120 DATABASE_IS_OBSOLETE=no
121 message_echo "WARNING: The temporary database is older than the ports tree." >&2
122 database_maintain_refresh || DATABASE_IS_OBSOLETE=yes
124 DATABASE_IS_OBSOLETE=yes
127 DATABASE_IS_OBSOLETE=no
131 # ============= Resetting of the temporary database =============
132 database_maintain_reset ()
136 if [ $mode = keepstatus ]
138 if [ ! -d "${DBDIR}/prevset" ]
140 mkdir -p "${DBDIR}/prevset"
147 echo manually_done.list
148 for tag in all run build none
150 for level in full direct
152 echo "success.$tag.$level.list"
155 } | while read content
157 [ -e "${DBDIR}/$content" ] && mv "${DBDIR}/$content" "${DBDIR}/prevset"
161 rm -rf "${DBDIR}"/requires.prev "${DBDIR}"/notes.prev
163 find "${DBDIR}" -depth 1 -maxdepth 1 \
164 -not \( -name saved_options.sh -or -name initial \
165 -or -name fossil_pkgs -or -name moved_from \
166 -or -name MYVERSION -or -name .lock \
167 -or -name journal -or -name prevset \
168 -or -name backup_failure -or -name installed_ports \
169 -or -name installed_ports:pkg_vs_origin.tbl \) \
170 -exec rm -rf {} \; 2> /dev/null || :
171 touch "${DBDIR}/MYVERSION"
174 command_exec_without_pkgtools__notify_reset_options
175 rm -f "${DBDIR}/saved_options.sh" "${DBDIR}/prevset" "${DBDIR}/journal"*
177 keepopts | keepstatus )
182 command_flexconf_update_taboo $srcline
183 done < ${DBDIR}/journal/taboo || :
186 command_flexconf_update_freeze $srcline
187 done < ${DBDIR}/journal/freeze || :
190 command_flexconf_update_need $srcline
191 done < ${DBDIR}/journal/need || :
194 command_flexconf_update_noneed $srcline
195 done < ${DBDIR}/journal/noneed || :
201 # ============= Clear the data of previous progress status =============
202 database_maintain_clear_prevset ()
204 rm -rf "${DBDIR}/prevset"