2 # ==============================================================================
3 # portsreinstall library script
4 # - Operations for maintaining the temporary database -
5 # Copyright (C) 2018 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 # ============= Load a temporary database from an archive =============
22 database_maintain_load ()
24 local filepath dbdir_parent
26 dbdir_parent=`dirname "${DBDIR}"`
27 mkdir -p "$dbdir_parent"
28 tar xzf "$filepath" -C "$dbdir_parent" --exclude "*/.lock"
31 # ============= Save the temporary database to an archive =============
32 database_maintain_save ()
34 local filepath dbdir_parent dbdir_node
36 dbdir_parent=`dirname "${DBDIR}"`
37 dbdir_node=`basename "${DBDIR}"`
38 tar czf "$filepath" -C "$dbdir_parent" "$dbdir_node"
41 # ============= Creation of the temporary database =============
42 database_maintain_create ()
45 [ `id -u` -eq 0 ] && mkdir -p "${DBDIR}"
46 misc_lock_duplicated_executions "${DBDIR}/.lock"
47 if [ -e "${DBDIR}/MYVERSION" ]
49 if ! grep -q -E "$COMPATIBLE_VERSIONS" "${DBDIR}/MYVERSION" 2> /dev/null
51 message_echo "ERROR: The current temporary database is incompatible. You must delete it by" >&2
52 message_echo " ${APPNAME} clean force" >&2
53 message_echo " in order to enable the current version." >&2
56 elif misc_is_superuser_privilege
58 echo "$MYVERSION" > ${DBDIR}/MYVERSION
60 DATABASE_VERSION=`cat "${DBDIR}"/MYVERSION 2> /dev/null || :`
61 misc_is_superuser_privilege || return 0
62 for subdir in initial requires replace targets obsolete backup_packages \
63 stage.loop_list stage.complete stage.reinit_loop stage.depends
65 mkdir -p "${DBDIR}/$subdir"
69 # ============= Mark the use of the temporary database =============
70 database_maintain_mark_use ()
72 touch "${DBDIR}/in_use"
75 # ============= Check the use of the temporary database =============
76 database_maintain_chk_use ()
78 [ -e "${DBDIR}/in_use" ]
81 # ============= Refresh the temporary database =============
82 database_maintain_refresh ()
84 misc_is_superuser_privilege || return
85 [ $opt_suppress_obsolete_db_clean = no ] || return
86 message_echo "INFO: The temporary database is cleaned up."
88 [ -d "${DBDIR}" -a ! -d "${DBDIR}.tmp" ] && mv "${DBDIR}" "${DBDIR}.tmp"
89 database_maintain_create
90 mv "${DBDIR}.tmp/saved_options.sh" "${DBDIR}" 2> /dev/null || :
91 mv "${DBDIR}.tmp/backup_packages" "${DBDIR}" 2> /dev/null || :
92 mv "${DBDIR}.tmp/backup_pkgarcs.lst" "${DBDIR}" 2> /dev/null || :
96 # ============= Clean up the temporary database for upgrade of this utility =============
97 database_maintain_clean_for_self_upgrade ()
99 misc_is_superuser_privilege || return
100 [ $opt_suppress_obsolete_db_clean = no ] || return
102 database_maintain_create
103 [ -e "${DBDIR}/MYVERSION" ] && mv "${DBDIR}/MYVERSION" "${DBDIR}/MYVERSION.prev"
107 # ============= Check whether the temporary database is newer than the ports tree and refresh if so =============
108 database_maintain_refresh_if_obsolete ()
110 if [ "${PORTS_INDEX_DB}" -nt "${DBDIR}"/MYVERSION ] && misc_is_superuser_privilege
112 if [ $opt_suppress_obsolete_db_clean = no -a "z${command}" = zclean ]
114 DATABASE_IS_OBSOLETE=no
115 message_echo "WARNING: The temporary database is older than the ports tree." >&2
116 database_maintain_refresh || DATABASE_IS_OBSOLETE=yes
118 DATABASE_IS_OBSOLETE=yes
121 DATABASE_IS_OBSOLETE=no
125 # ============= Resetting of the temporary database =============
126 database_maintain_reset ()
130 if [ $mode = keepstatus ]
132 if [ ! -d "${DBDIR}/prevset" ]
134 mkdir -p "${DBDIR}/prevset"
141 echo manually_done.list
142 for tag in all run build none
144 for level in full direct
146 echo "success.$tag.$level.list"
149 } | while read content
151 [ -e "${DBDIR}/$content" ] && mv "${DBDIR}/$content" "${DBDIR}/prevset"
155 rm -rf "${DBDIR}"/requires.prev "${DBDIR}"/notes.prev
157 find "${DBDIR}" -depth 1 \
158 -not \( -name saved_options.sh \
159 -or -name MYVERSION -or -name .lock \
160 -or -name journal -or -name prevset \
161 -or -name backup_failure -or -name installed_ports \) \
162 -exec rm -rf {} \; 2> /dev/null || :
163 touch "${DBDIR}/MYVERSION"
166 command_exec_without_pkgtools__notify_reset_options
167 rm -f "${DBDIR}/saved_options.sh" "${DBDIR}/prevset" "${DBDIR}/journal"*
169 keepopts | keepstatus )
174 command_flexconf_update_taboo $srcline
175 done < ${DBDIR}/journal/taboo || :
178 command_flexconf_update_freeze $srcline
179 done < ${DBDIR}/journal/freeze || :
182 command_flexconf_update_need $srcline
183 done < ${DBDIR}/journal/need || :
186 command_flexconf_update_noneed $srcline
187 done < ${DBDIR}/journal/noneed || :
193 # ============= Clear the data of previous progress status =============
194 database_maintain_clear_prevset ()
196 rm -rf "${DBDIR}/prevset"