OSDN Git Service

[IMPROVE] Custom make environment variables and arguments are changed to be reflected...
authorMamoru Sakaue / MwGhennndo <glmwghennndo@users.sourceforge.jp>
Thu, 26 Apr 2012 03:06:00 +0000 (12:06 +0900)
committerMamoru Sakaue / MwGhennndo <glmwghennndo@users.sourceforge.jp>
Thu, 26 Apr 2012 03:06:00 +0000 (12:06 +0900)
[BUG FIX] Deletion of MOVED-back packages is now prevented.

modified:   portsreinstall
modified:   portsreinstall.8
modified:   portsreinstall.8~
modified:   portsreinstall~

portsreinstall
portsreinstall.8
portsreinstall.8~
portsreinstall~

index 5aaefb5..138502a 100755 (executable)
@@ -10,7 +10,7 @@
 # ================================================
 
 APPNAME=`basename $0`
-MYVERSION=1.0.0+toward_1.1.0_20120425212835
+MYVERSION=1.0.0+toward_1.1.0_20120426115858
 
 PREFIX=${PREFIX:-/usr/local}
 CONFFILE=${PREFIX}/etc/${APPNAME}.conf
@@ -569,8 +569,8 @@ build_conflist_target_val_pair ()
                        eval val=\$\{`echo $var | sed "s/^_CONF_${section}_${tag_target}_/_CONF_${section}_${tag_val}_/"`\}
                        expand_glob_pattern_to_origins "$glob_pattern" | while read origin
                        do
-                               path=${DBDIR}/requires/$origin
-                               [ -d "$path" ] || continue
+                               path=${DBDIR}/requires_conflist/$origin
+                               [ -d "$path" ] || mkdir -p "$path"
                                echo $val > $path/${section}.conflist
                        done
                done
@@ -651,12 +651,20 @@ inspect_dependencies ()
                fi
                if [ $port_exists = yes ]
                then
+                       rm_a_line "$origin" "${DBDIR}/moved_or_lost.list"
                        cd "${PORTSDIR}/$origin"
-                       make config-conditional
-                       [ -d "${DBDIR}/requires/$origin/status" ] || mkdir -p "${DBDIR}/requires/$origin/status"
+                       target_dir=${DBDIR}/requires/$origin
+                       [ -d "$target_dir/status" ] || mkdir -p "$target_dir/status"
+                       if [ -d "${DBDIR}/requires_conflist/$origin" ]
+                       then
+                               cp -R "${DBDIR}/requires_conflist/$origin/"* "$target_dir/" > /dev/null 2> /dev/null || :
+                       fi
+                       MAKE_ARGS="FORCE_PKG_REGISTER=yes DISABLE_VULNERABILITIES=yes `cat "$target_dir/MARG.conflist" 2> /dev/null || :`"
+                       MAKE_ENVS=`cat "$target_dir/MENV.conflist" 2> /dev/null || :`
+                       env ${MAKE_ENVS} make config-conditional ${MAKE_ARGS}
                        pkg=`pkg_info -qO "$origin"`
-                       [ -n "$pkg" ] && echo $pkg > ${DBDIR}/requires/$origin/installed_version
-                       pkg_new=`(cd "${PORTSDIR}/$origin" && make package-name)`
+                       [ -n "$pkg" ] && echo $pkg > $target_dir/installed_version
+                       pkg_new=`(cd "${PORTSDIR}/$origin" && env ${MAKE_ENVS} make package-name ${MAKE_ARGS})`
                        pkgtag=$pkg
                        [ -n "$pkgtag" ] || pkgtag=$pkg_new
                        if [ -z "$pkgtag" ]
@@ -666,15 +674,15 @@ inspect_dependencies ()
                        elif [ "z$pkg" != "z$pkg_new" ]
                        then
                                pkgtag="$pkg => $pkg_new"
-                               echo $pkg_new > ${DBDIR}/requires/$origin/new_version
+                               echo $pkg_new > $target_dir/new_version
                        fi
-                       echo $pkgtag > ${DBDIR}/requires/$origin/pkgtag
-                       make all-depends-list | sed "s|^${PORTSDIR}/||" > "${DBDIR}/requires/$origin/requires" || :
-                       grep -E -f "${DBDIR}/REPLACE.grep_from_pattern.conflist" "${DBDIR}/requires/$origin/requires" | grep -v -E "^`str_escape_regexp $origin`$" > ${TMPDIR}/replaced_target.tmp || :
-                       mv "${DBDIR}/requires/$origin/requires" "${DBDIR}/requires/$origin/requires.orig"
-                       sed -E -f "${DBDIR}/REPLACE.replace_pattern.conflist" "${DBDIR}/requires/$origin/requires.orig" | grep -v '^$' > ${DBDIR}/requires/$origin/requires || :
+                       echo $pkgtag > $target_dir/pkgtag
+                       env ${MAKE_ENVS} make all-depends-list ${MAKE_ARGS} | sed "s|^${PORTSDIR}/||" > "$target_dir/requires" || :
+                       grep -E -f "${DBDIR}/REPLACE.grep_from_pattern.conflist" "$target_dir/requires" | grep -v -E "^`str_escape_regexp $origin`$" > ${TMPDIR}/replaced_target.tmp || :
+                       mv "$target_dir/requires" "$target_dir/requires.orig"
+                       sed -E -f "${DBDIR}/REPLACE.replace_pattern.conflist" "$target_dir/requires.orig" | grep -v '^$' > $target_dir/requires || :
                        add_lines_if_new "${DBDIR}/replaced_target.list" < ${TMPDIR}/replaced_target.tmp
-                       grep -v -E -f "${DBDIR}/installed_ports.grep_pattern" "${DBDIR}/requires/$origin/requires" > ${TMPDIR}/missing.$origin_id || :
+                       grep -v -E -f "${DBDIR}/installed_ports.grep_pattern" "$target_dir/requires" > ${TMPDIR}/missing.$origin_id || :
                        nlines=`cat "${TMPDIR}/missing.$origin_id" | wc -l`
                        iline=1
                        while [ $iline -le $nlines ]
@@ -685,7 +693,7 @@ inspect_dependencies ()
                                inspect_dependencies "$origin_dependency"
                        done
                        rm "${TMPDIR}/missing.$origin_id"
-                       make fetch-urlall-list | sed -E 's|.*/([^/]+)$|\1|' | sort | uniq >> ${DBDIR}/distfiles.list
+                       env ${MAKE_ENVS} make fetch-urlall-list ${MAKE_ARGS} | sed -E 's|.*/([^/]+)$|\1|' | sort | uniq >> ${DBDIR}/distfiles.list
                fi
        fi
        [ "$origin_orig" = "$origin" ] || echo "s|^`str_escape_regexp $origin_orig`$|$origin|" >> ${DBDIR}/REPLACE.complete_replace_pattern.tmp
@@ -927,11 +935,14 @@ show)
        then
                while read origin misc
                do
-                       [ -e "${DBDIR}/requires/$origin/${_filter_skip_unchanged}" -o ] || continue
-                       echo $origin '('`cat ${DBDIR}/requires/$origin/pkgtag`')'
+                       [ -e "${DBDIR}/requires/$origin/${_filter_skip_unchanged}" ] || continue
+                       echo $origin '('`cat "${DBDIR}/requires/$origin/pkgtag"`')'
                done < ${DBDIR}/$list
        else
-               cat "${DBDIR}/$list"
+               while read origin misc
+               do
+                       echo $origin '('`cat "${DBDIR}/requires/$origin/pkgtag"`')'
+               done < ${DBDIR}/$list
        fi
        exit
        ;;
@@ -1189,6 +1200,18 @@ then
 fi
 . "${DBDIR}/setenv.sh"
 
+if [ ! -e "${DBDIR}/COMPLETE_REFLECTCONF_2" ]
+then
+       echo "Starting to reflect settings for each port defined in the configuration file at `timestamp`"
+       build_conflist_target_val_pair MARG TARGET DEF
+       build_conflist_target_val_pair MENV TARGET DEF
+       build_conflist_target_val_pair BEFOREBUILD TARGET COMMAND
+       build_conflist_target_val_pair BEFOREDEINSTALL TARGET COMMAND
+       build_conflist_target_val_pair AFTERINSTALL TARGET COMMAND
+       touch "${DBDIR}/COMPLETE_REFLECTCONF_2"
+       echo
+fi
+
 # ------- Database construction -------
 
 terminate_process_common ()
@@ -1518,18 +1541,6 @@ eof
        echo
 fi
 
-if [ ! -e "${DBDIR}/COMPLETE_REFLECTCONF_2" ]
-then
-       echo "Starting to reflect settings for each port defined in the configuration file at `timestamp`"
-       build_conflist_target_val_pair MARG TARGET DEF
-       build_conflist_target_val_pair MENV TARGET DEF
-       build_conflist_target_val_pair BEFOREBUILD TARGET COMMAND
-       build_conflist_target_val_pair BEFOREDEINSTALL TARGET COMMAND
-       build_conflist_target_val_pair AFTERINSTALL TARGET COMMAND
-       touch "${DBDIR}/COMPLETE_REFLECTCONF_2"
-       echo
-fi
-
 # ------- Main operations -------
 
 if [ "$command" = prepare ]
@@ -1653,7 +1664,7 @@ then
                then
                        pkgtag='?'
                
-               elif [ "x$currentpkg" != "x$newpkg" ]
+               elif [ -n "$newpkg" -a "x$currentpkg" != "x$newpkg" ]
                then
                        pkgtag="$currentpkg => $newpkg"
                fi
@@ -1867,7 +1878,7 @@ then
                fi
                if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_PKG_BACKUP" ]
                then
-                       echo "-- (Creating temporal backup package for $position_msg as $currentpkg)"
+                       echo "-- (Creating temporal backup package for $position_msg)"
                        cd "${DBDIR}/backup_failure"
                        pkg_create -b "$currentpkg" || \
                        {
@@ -1979,7 +1990,6 @@ then
                        }
                        touch "${DBDIR}/requires/$origin/status/COMPLETE_CLEAN_AFTER_INSTALL"
                fi
-               echo $newpkg > ${DBDIR}/requires/$origin/pkgtag
                record_success $origin
                rm_a_line "$origin" "${DBDIR}/reinst_todo.list"
                rm -f "${DBDIR}/backup_failure/$currentpkg.tbz"
index bc340a4..d145f84 100644 (file)
@@ -236,6 +236,8 @@ Configuration file of portupgrade(1).
 
 [CHANGE] The default option for treating pkgtools.conf(5) is changed to \fB\-p\fR and \fB\-Q\fR is newly added.
 
+[IMPROVE] Custom make environment variables and arguments are changed to be reflected in the phase of inspection of dependencies.
+
 [BUG FIX] Independence from ports\-mgmt/portupgrade* was incomplete.
 
 [BUG FIX] Error messages for show command when the temporal database does not exist are improved.
@@ -243,6 +245,8 @@ Configuration file of portupgrade(1).
 [BUG FIX] Ports with names contaning '+' were not correctly treated.
 
 [BUG FIX] Save and load commands were broken.
+
+[BUG FIX] Deletion of MOVED-back packages is now prevented.
 .TP
 1.0.0 (14 March 2012)
 [MISC] Explanations for \fB\-p\fR and \fB\-P\fR are revised because the previous ones were somewhat confusing.
index eb03d80..717bde9 100644 (file)
@@ -231,7 +231,7 @@ Configuration file of portupgrade(1).
 .SH HISTORY
 \fBportsreinstall\fR has been developed as below.
 .TP
-1.1.0 (17 April 2012)
+1.1.0 (25 April 2012)
 [CHANGE] Origin names in messages and results of show command are changed to be accompanied with package names.
 
 [CHANGE] The default option for treating pkgtools.conf(5) is changed to \fB\-p\fR and \fB\-Q\fR is newly added.
@@ -241,6 +241,10 @@ Configuration file of portupgrade(1).
 [BUG FIX] Error messages for show command when the temporal database does not exist are improved.
 
 [BUG FIX] Ports with names contaning '+' were not correctly treated.
+
+[BUG FIX] Save and load commands were broken.
+
+[BUG FIX] Deletion of MOVED-back packages is now prevented.
 .TP
 1.0.0 (14 March 2012)
 [MISC] Explanations for \fB\-p\fR and \fB\-P\fR are revised because the previous ones were somewhat confusing.
index fe19bd0..30c430e 100755 (executable)
@@ -10,7 +10,7 @@
 # ================================================
 
 APPNAME=`basename $0`
-MYVERSION=1.0.0+toward_1.1.0_20120425110328
+MYVERSION=1.0.0+toward_1.1.0_20120426115237
 
 PREFIX=${PREFIX:-/usr/local}
 CONFFILE=${PREFIX}/etc/${APPNAME}.conf
@@ -336,6 +336,7 @@ command=$1
 PORTSDIR=${PORTSDIR:-/usr/ports}
 
 PORTS_MOVED_DB=${PORTSDIR}/MOVED
+PORTS_INDEX_DB=${PORTSDIR}/INDEX-`uname -r | cut -d . -f 1`
 
 str_escape_regexp_filter ()
 {
@@ -366,16 +367,22 @@ then
 else
        ports_glob ()
        {
-               local glob
+               local glob index
                glob=`convert_portsglob_to_regexp_pattern "$1"`
+               [ -f "${DBDIR}/ports_glob:pkg.lst" ] || cut -d \| -f 1 "${PORTS_INDEX_DB}" > ${DBDIR}/ports_glob:pkg.lst
+               [ -f "${DBDIR}/ports_glob:origin.lst" ] || cut -d \| -f 2 "${PORTS_INDEX_DB}" | sed -E "s/^`str_escape_regexp "${PORTSDIR}"`\///" > ${DBDIR}/ports_glob:origin.lst
                if expr "$glob" : '[^\/][^\/]*\/[^\/][^\/]*$' 2> /dev/null > /dev/null
                then
-                       find -E /usr/ports -maxdepth 2 -type d -regex /usr/ports/"$glob" -and -not -regex '/usr/ports/(Templates|Mk|Tools|distfiles|packages)/.*' | cut -d / -f 4,5 > ${TMPDIR}/ports_glob:matched
+                       grep -E "$glob" "${DBDIR}/ports_glob:origin.lst" > ${TMPDIR}/ports_glob:matched
                        pkg_info -aoq | grep -E "$glob" >> ${TMPDIR}/ports_glob:matched
                else
-                       pkg_info -EqIx "^$glob$" > ${TMPDIR}/ports_glob:matched
+                       grep -n -E "$glob" "${DBDIR}/ports_glob:pkg.lst" | cut -d : -f 1 | while read index
+                       do
+                               sed -n ${index}p "${DBDIR}/ports_glob:origin.lst"
+                       done > ${TMPDIR}/ports_glob:matched
+                       pkg_info -oqx "$glob" >> ${TMPDIR}/ports_glob:matched
                fi
-               
+               sort -u "${TMPDIR}"/ports_glob:matched
        }
 fi
 
@@ -480,7 +487,7 @@ register_globs ()
                        [ -d "${PORTSDIR}/$glob" ] && { echo $glob; continue; }
                fi
                origin=`ports_glob "$glob"`
-               [ "$origin" ] || \
+               [ -n "$origin" ] || \
                {
                        echo "ERROR: Invalid ports/package glob [$glob]" >&2
                        exit 1;
@@ -562,8 +569,8 @@ build_conflist_target_val_pair ()
                        eval val=\$\{`echo $var | sed "s/^_CONF_${section}_${tag_target}_/_CONF_${section}_${tag_val}_/"`\}
                        expand_glob_pattern_to_origins "$glob_pattern" | while read origin
                        do
-                               path=${DBDIR}/requires/$origin
-                               [ -d "$path" ] || continue
+                               path=${DBDIR}/requires_conflist/$origin
+                               [ -d "$path" ] || mkdir -p "$path"
                                echo $val > $path/${section}.conflist
                        done
                done
@@ -583,13 +590,13 @@ convert_origin_if_moved ()
        grep -n -m 1 -E "^`str_escape_regexp $origin`\|" "$recursedb" 2> /dev/null > ${TMPDIR}/moved.info || :
        if [ `cat "${TMPDIR}/moved.info" | wc -l` -eq 0 ]
        then
-               if [ "$recursedb_in" ]
+               if [ -n "$recursedb_in" ]
                then
                        echo "${DEPTH_INDEX}  ===> Disappeared port (MOVED broken?)"
                else
                        echo "${DEPTH_INDEX}  ===> Nonexistent port (your original?)"
                fi
-               [ "$origin_src" ] && add_a_line_if_new "$origin_src" "${DBDIR}/moved_or_lost.list"
+               [ -n "$origin_src" ] && add_a_line_if_new "$origin_src" "${DBDIR}/moved_or_lost.list"
                return 1
        else
                iline_db=`cut -d : -f 1 "${TMPDIR}/moved.info"`
@@ -597,13 +604,13 @@ convert_origin_if_moved ()
                origin=`sed -E 's/^[0-9]+://' "${TMPDIR}/moved.info" | cut -d '|' -f 2 || :`
                date_moved=`cut -d '|' -f 3 "${TMPDIR}/moved.info" || :`
                why_moved=`cut -d '|' -f 4 "${TMPDIR}/moved.info" || :`
-               if [ "$origin" ]
+               if [ -n "$origin" ]
                then
                        echo "${DEPTH_INDEX}  ===> Moved to $origin at $date_moved because \"$why_moved\""
                        convert_origin_if_moved "$origin_src" "${TMPDIR}/MOVED.DB" || return 1
                else
                        echo "${DEPTH_INDEX}  ===> Deleted at $date_moved because \"$why_moved\""
-                       [ "$origin_src" ] || return 1
+                       [ -n "$origin_src" ] || return 1
                        origin=$origin_src
                        echo "${DEPTH_INDEX}  ===> Going back to the original port $origin_src"
                        convert_origin_if_moved || return 1
@@ -626,7 +633,7 @@ inspect_dependencies ()
                origin_src=$origin
                origin=`echo $origin_src | sed -E -f "${DBDIR}/REPLACE.replace_pattern.conflist"`
                add_a_line_if_new "$origin_src" "${DBDIR}/moved_or_lost.list"
-               if [ "$origin" ]
+               if [ -n "$origin" ]
                then
                        add_a_line_if_new "$origin" "${DBDIR}/replaced_target.inspected.list"
                        echo "${DEPTH_INDEX}  ===> Replaced with $origin by user configuration"
@@ -634,7 +641,7 @@ inspect_dependencies ()
                        echo "${DEPTH_INDEX}  ===> Deleted by user configuration"
                fi
        fi
-       if [ "$origin" ]
+       if [ -n "$origin" ]
        then
                if convert_origin_if_moved "$origin_src" ''
                then
@@ -644,12 +651,20 @@ inspect_dependencies ()
                fi
                if [ $port_exists = yes ]
                then
+                       rm_a_line "$origin" "${DBDIR}/moved_or_lost.list"
                        cd "${PORTSDIR}/$origin"
-                       make config-conditional
-                       [ -d "${DBDIR}/requires/$origin/status" ] || mkdir -p "${DBDIR}/requires/$origin/status"
+                       target_dir=${DBDIR}/requires/$origin
+                       [ -d "$target_dir/status" ] || mkdir -p "$target_dir/status"
+                       if [ -d "${DBDIR}/requires_conflist/$origin" ]
+                       then
+                               cp -R "${DBDIR}/requires_conflist/$origin/"* "$target_dir/" > /dev/null 2> /dev/null || :
+                       fi
+                       MAKE_ARGS="FORCE_PKG_REGISTER=yes DISABLE_VULNERABILITIES=yes `cat "$target_dir/MARG.conflist" 2> /dev/null || :`"
+                       MAKE_ENVS=`cat "$target_dir/MENV.conflist" 2> /dev/null || :`
+                       env ${MAKE_ENVS} make config-conditional ${MAKE_ARGS}
                        pkg=`pkg_info -qO "$origin"`
-                       [ "$pkg" ] && echo $pkg > ${DBDIR}/requires/$origin/installed_version
-                       pkg_new=`(cd "${PORTSDIR}/$origin" && make package-name)`
+                       [ -n "$pkg" ] && echo $pkg > $target_dir/installed_version
+                       pkg_new=`(cd "${PORTSDIR}/$origin" && env ${MAKE_ENVS} make package-name ${MAKE_ARGS})`
                        pkgtag=$pkg
                        [ -n "$pkgtag" ] || pkgtag=$pkg_new
                        if [ -z "$pkgtag" ]
@@ -659,15 +674,15 @@ inspect_dependencies ()
                        elif [ "z$pkg" != "z$pkg_new" ]
                        then
                                pkgtag="$pkg => $pkg_new"
-                               echo $pkg_new > ${DBDIR}/requires/$origin/new_version
+                               echo $pkg_new > $target_dir/new_version
                        fi
-                       echo $pkgtag > ${DBDIR}/requires/$origin/pkgtag
-                       make all-depends-list | sed "s|^${PORTSDIR}/||" > "${DBDIR}/requires/$origin/requires" || :
-                       grep -E -f "${DBDIR}/REPLACE.grep_from_pattern.conflist" "${DBDIR}/requires/$origin/requires" | grep -v -E "^`str_escape_regexp $origin`$" > ${TMPDIR}/replaced_target.tmp || :
-                       mv "${DBDIR}/requires/$origin/requires" "${DBDIR}/requires/$origin/requires.orig"
-                       sed -E -f "${DBDIR}/REPLACE.replace_pattern.conflist" "${DBDIR}/requires/$origin/requires.orig" | grep -v '^$' > ${DBDIR}/requires/$origin/requires || :
+                       echo $pkgtag > $target_dir/pkgtag
+                       env ${MAKE_ENVS} make all-depends-list ${MAKE_ARGS} | sed "s|^${PORTSDIR}/||" > "$target_dir/requires" || :
+                       grep -E -f "${DBDIR}/REPLACE.grep_from_pattern.conflist" "$target_dir/requires" | grep -v -E "^`str_escape_regexp $origin`$" > ${TMPDIR}/replaced_target.tmp || :
+                       mv "$target_dir/requires" "$target_dir/requires.orig"
+                       sed -E -f "${DBDIR}/REPLACE.replace_pattern.conflist" "$target_dir/requires.orig" | grep -v '^$' > $target_dir/requires || :
                        add_lines_if_new "${DBDIR}/replaced_target.list" < ${TMPDIR}/replaced_target.tmp
-                       grep -v -E -f "${DBDIR}/installed_ports.grep_pattern" "${DBDIR}/requires/$origin/requires" > ${TMPDIR}/missing.$origin_id || :
+                       grep -v -E -f "${DBDIR}/installed_ports.grep_pattern" "$target_dir/requires" > ${TMPDIR}/missing.$origin_id || :
                        nlines=`cat "${TMPDIR}/missing.$origin_id" | wc -l`
                        iline=1
                        while [ $iline -le $nlines ]
@@ -678,13 +693,13 @@ inspect_dependencies ()
                                inspect_dependencies "$origin_dependency"
                        done
                        rm "${TMPDIR}/missing.$origin_id"
-                       make fetch-urlall-list | sed -E 's|.*/([^/]+)$|\1|' | sort | uniq >> ${DBDIR}/distfiles.list
+                       env ${MAKE_ENVS} make fetch-urlall-list ${MAKE_ARGS} | sed -E 's|.*/([^/]+)$|\1|' | sort | uniq >> ${DBDIR}/distfiles.list
                fi
        fi
        [ "$origin_orig" = "$origin" ] || echo "s|^`str_escape_regexp $origin_orig`$|$origin|" >> ${DBDIR}/REPLACE.complete_replace_pattern.tmp
        add_a_line_if_new "$origin" "${DBDIR}/target.inspected.list"
        rm_a_line "$origin" "${DBDIR}/target_ports.remain"
-       if [ "$origin_src" ]
+       if [ -n "$origin_src" ]
        then
                add_a_line_if_new "$origin_src" "${DBDIR}/target.inspected.list"
                rm_a_line "$origin_src" "${DBDIR}/target_ports.remain"
@@ -775,12 +790,12 @@ trap 'errno=$?; warn_update_ports; terminate_process; rm -r'`[ \`uname -s\` = Fr
 [ "$load_pkgtoolsconf" != undef -a -d "${DBDIR}/COMPLETE_IMPORT_PKGTOOLS_CONF" ] && echo "WARN: -p, -P or -Q option is specified but ignored by following the previous settings." >&2
 
 # Check whether the temporal database is newer than the ports tree
-_STATUS_DB_OBSOLETE=no
-ls "${PORTSDIR}"/*.db | while read ref
-do
-       [ "$ref" -nt "${DBDIR}" ] && { _STATUS_DB_OBSOLETE=yes; break; }
-       :
-done
+if [ "${PORTS_INDEX_DB}" -nt "${DBDIR}" ]
+then
+       _STATUS_DB_OBSOLETE=yes
+else
+       _STATUS_DB_OBSOLETE=no
+fi
 
 # Creation of temporal database directory
 if [ -d "${DBDIR}" ]
@@ -795,7 +810,6 @@ fi
 # Taboo list given by options
 register_globs "$taboo_ports" "${DBDIR}/taboo.list"
 
-
 # ------- Commands -------
 
 # Special modes
@@ -847,10 +861,11 @@ taboo)
        exit
        ;;
 save)
+echo $*
        chk_privilege
        [ -d "${DBDIR}" ] || { echo "ERROR: Database has not built yet." >&2; exit 1; }
-       savedir=$2
-       [ "$savedir" ] || { echo "ERROR: Directory to save the temporal database archive is not specified." >&2; exit 1; }
+       savedir=$1
+       [ -n "$savedir" ] || { echo "ERROR: Directory to save the temporal database archive is not specified." >&2; exit 1; }
        [ -d "$savedir" ] || { echo "ERROR: Directory [$savedir] is not found." >&2; exit 1; }
        srcdir=`dirname "${DBDIR}"`
        srcnode=`basename "${DBDIR}"`
@@ -862,8 +877,8 @@ save)
        ;;
 load)
        chk_privilege
-       loadfile=$2
-       [ "$loadfile" ] || { echo "ERROR: Database archive is not specified." >&2; exit 1; }
+       loadfile=$1
+       [ -n "$loadfile" ] || { echo "ERROR: Database archive is not specified." >&2; exit 1; }
        [ -f "$loadfile" ] || { echo "ERROR: Database archive is not found." >&2; exit 1; }
        loadfile=`realpath "$loadfile"`
        echo "Starting to load the temporal database..."
@@ -916,15 +931,18 @@ show)
        esac
        [ -r "${DBDIR}/$list" ] || exit 0
        [ -e "${DBDIR}"/saved_options.sh ] && . "${DBDIR}"/saved_options.sh
-       if [ "${_filter_skip_unchanged}" -a $skip_unchanged = yes ]
+       if [ -n "${_filter_skip_unchanged}" -a $skip_unchanged = yes ]
        then
                while read origin misc
                do
-                       [ -e "${DBDIR}/requires/$origin/${_filter_skip_unchanged}" -o ] || continue
-                       echo $origin '('`cat ${DBDIR}/requires/$origin/pkgtag`')'
+                       [ -e "${DBDIR}/requires/$origin/${_filter_skip_unchanged}" ] || continue
+                       echo $origin '('`cat "${DBDIR}/requires/$origin/pkgtag"`')'
                done < ${DBDIR}/$list
        else
-               cat "${DBDIR}/$list"
+               while read origin misc
+               do
+                       echo $origin '('`cat "${DBDIR}/requires/$origin/pkgtag"`')'
+               done < ${DBDIR}/$list
        fi
        exit
        ;;
@@ -934,7 +952,7 @@ redo)
        touch "${DBDIR}/MODE_REDO"
        rm -f "${DBDIR}/COMPLETE_CLEANUP_REINST_STATUS"
        [ $renew_options = yes ] && rm -f "${DBDIR}/COMPLETE_SAVE_OPTIONS"
-       if [ "$target_required_ports$target_dependent_ports" ]
+       if [ -n "$target_required_ports$target_dependent_ports" ]
        then
                rm -f "${DBDIR}/COMPLETE_PARSE_OPTION_TARGET_PORTS"
                touch "${DBDIR}/REQUIRE_CHK_NEW_TARGET"
@@ -996,10 +1014,10 @@ then
        then
                echo "-- Starting to parse pkgtools.conf at `timestamp` (by using installed portupgrade)"
                portupgrade_pkg=`pkg_info -qO ports-mgmt/portupgrade`
-               [ "$portupgrade_pkg" ] || portupgrade_pkg=`pkg_info -qO ports-mgmt/portupgrade-devel`
+               [ -n "$portupgrade_pkg" ] || portupgrade_pkg=`pkg_info -qO ports-mgmt/portupgrade-devel`
                [ `expr "$portupgrade_pkg" : '^portupgrade-devel-'` -ne 0 ] && echo "WARN: Combination with portupgrade-devel-* has not tested."
                istart=`grep -m 1 -n -e '^def init_global$' "${PORTUPGRADE}" | cut -d : -f 1` || :
-               [ "$istart" ] || { echo "ERROR: The current installed version of portupgrade is unsupported." >&2; }
+               [ -n "$istart" ] || { echo "ERROR: The current installed version of portupgrade is unsupported." >&2; }
                sed 1,$(($istart-1))d "${PORTUPGRADE}" > ${TMPDIR}/portupgrade.0
                iend=`grep -m 1 -n -e '^end$' "${TMPDIR}"/portupgrade.0 | cut -d : -f 1`
                sed -n 1,${iend}p "${TMPDIR}"/portupgrade.0 > ${TMPDIR}/portupgrade.init_global
@@ -1162,15 +1180,9 @@ then
                        expand_glob_pattern_to_origins "$glob_pattern" yes > ${TMPDIR}/origins.2.tmp || :
                        if [ `cat "${TMPDIR}/origins.2.tmp" | wc -l` -eq 0 ]
                        then
-                               if expr "$glob_pattern" : '.*\/' > /dev/null 2>&1
-                               then
-                                       regexp_pattern=`convert_portsglob_to_regexp_pattern "$glob_pattern"`
-                                       echo $glob_pattern | str_escape_regexp_filter | sed 's/\\\*/.*/g' > ${TMPDIR}/origins.2.tmp
-                               else
-                                       echo "WARN: Original package to be replaced [$glob_pattern] is obsolete." >&2
-                                       echo "      If still required, use a pattern for port origins instead." >&2
-                                       continue
-                               fi
+                               echo "WARN: Original package to be replaced [$glob_pattern] is obsolete." >&2
+                               echo "      If still required, use a pattern for port origins instead." >&2
+                               continue
                        fi
                        str_escape_regexp_filter < ${TMPDIR}/origins.2.tmp | sed "s|^|^|; s|$|$|" >> ${DBDIR}/REPLACE.grep_from_pattern.conflist
 
@@ -1188,6 +1200,18 @@ then
 fi
 . "${DBDIR}/setenv.sh"
 
+if [ ! -e "${DBDIR}/COMPLETE_REFLECTCONF_2" ]
+then
+       echo "Starting to reflect settings for each port defined in the configuration file at `timestamp`"
+       build_conflist_target_val_pair MARG TARGET DEF
+       build_conflist_target_val_pair MENV TARGET DEF
+       build_conflist_target_val_pair BEFOREBUILD TARGET COMMAND
+       build_conflist_target_val_pair BEFOREDEINSTALL TARGET COMMAND
+       build_conflist_target_val_pair AFTERINSTALL TARGET COMMAND
+       touch "${DBDIR}/COMPLETE_REFLECTCONF_2"
+       echo
+fi
+
 # ------- Database construction -------
 
 terminate_process_common ()
@@ -1517,18 +1541,6 @@ eof
        echo
 fi
 
-if [ ! -e "${DBDIR}/COMPLETE_REFLECTCONF_2" ]
-then
-       echo "Starting to reflect settings for each port defined in the configuration file at `timestamp`"
-       build_conflist_target_val_pair MARG TARGET DEF
-       build_conflist_target_val_pair MENV TARGET DEF
-       build_conflist_target_val_pair BEFOREBUILD TARGET COMMAND
-       build_conflist_target_val_pair BEFOREDEINSTALL TARGET COMMAND
-       build_conflist_target_val_pair AFTERINSTALL TARGET COMMAND
-       touch "${DBDIR}/COMPLETE_REFLECTCONF_2"
-       echo
-fi
-
 # ------- Main operations -------
 
 if [ "$command" = prepare ]
@@ -1578,7 +1590,7 @@ then
                        origin=`sed -n ${iline}p "${TMPDIR}/moved_or_lost.tmp"`
                        iline=$(($iline+1))
                        currentpkg=`pkg_info -qO "$origin" 2> /dev/null`
-                       [ "$currentpkg" ] || continue
+                       [ -n "$currentpkg" ] || continue
                        origin_ptn=`str_escape_regexp ${origin}`
                        if [ `grep -m 1 -E "^${origin_ptn}$" "${DBDIR}/HOLD_PORTS.conflist" 2> /dev/null | wc -l` -gt 0 ]
                        then
@@ -1652,7 +1664,7 @@ then
                then
                        pkgtag='?'
                
-               elif [ "x$currentpkg" != "x$newpkg" ]
+               elif [ -n "$newpkg" -a "x$currentpkg" != "x$newpkg" ]
                then
                        pkgtag="$currentpkg => $newpkg"
                fi
@@ -1698,7 +1710,7 @@ then
                        then
                                str_escape_regexp_filter < "${DBDIR}/requires/$origin/requires" | sed 's/^/^/;s/$/$/' > "${DBDIR}/requires/$origin/requires.pattern" 2> /dev/null || :
                        fi
-                       if [ "${_is_target}" ] || grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null
+                       if [ -n "${_is_target}" ] || grep -m 1 -E "^`str_escape_regexp $origin`$" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null
                        then
                                _is_target=y
                        elif grep -m 1 -E -f "${DBDIR}/requires/$origin/requires.pattern" "${DBDIR}/target_dependent_ports.specified" > /dev/null 2> /dev/null
@@ -1708,7 +1720,7 @@ then
                fi
                if [ -z "${_is_all}" ]
                then
-                       if [ "${_is_target}${_is_dependent}${_is_required}" ]
+                       if [ -n "${_is_target}${_is_dependent}${_is_required}" ]
                        then
                                [ "${_is_target}" = y ] && echo "(Target port)"
                                [ "${_is_dependent}" = y ] && echo "(Dependent of the target port(s))"
@@ -1864,9 +1876,9 @@ then
                else
                        touch "${DBDIR}/requires/$origin/status/in_install"
                fi
-               if [ "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_PKG_BACKUP" ]
+               if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_PKG_BACKUP" ]
                then
-                       echo "-- (Creating temporal backup package for $position_msg as $currentpkg)"
+                       echo "-- (Creating temporal backup package for $position_msg)"
                        cd "${DBDIR}/backup_failure"
                        pkg_create -b "$currentpkg" || \
                        {
@@ -1876,7 +1888,7 @@ then
                        cd "${PORTSDIR}/$origin"
                        touch "${DBDIR}/requires/$origin/status/COMPLETE_PKG_BACKUP"
                fi
-               if [ "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_BEFOREDEINSTALL" ]
+               if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_BEFOREDEINSTALL" ]
                then
                        if [ -e "${DBDIR}/requires/$origin/BEFOREDEINSTALL.conflist" ]
                        then
@@ -1894,7 +1906,7 @@ then
                        fi
                        touch "${DBDIR}/requires/$origin/status/COMPLETE_BEFOREDEINSTALL"
                fi
-               if [ "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_DEINSTALL" ]
+               if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_DEINSTALL" ]
                then
                        pkg_delete -f $currentpkg || \
                        {
@@ -1926,7 +1938,7 @@ then
                                        pkg_delete -f $currentpkg || :
                                        echo "*** Trying to deinstall by ports to make sure. (This usually ends up with warnings)"
                                        env ${MAKE_ENVS} make deinstall ${MAKE_ARGS} || :
-                                       if [ "$currentpkg" ]
+                                       if [ -n "$currentpkg" ]
                                        then
                                                echo "*** Restoring the backup..."
                                                if [ -e "${DBDIR}/backup_failure/$currentpkg.tbz" ]
@@ -1941,7 +1953,7 @@ then
                                        fi
                                        touch "${DBDIR}/requires/$origin/status/COMPETE.FAILED_INSTALL.RECOVER"
                                fi
-                               if [ "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPETE.FAILED_INSTALL.AFTERINSTALL" -a -e "${DBDIR}/requires/$origin/AFTERINSTALL.conflist" ]
+                               if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPETE.FAILED_INSTALL.AFTERINSTALL" -a -e "${DBDIR}/requires/$origin/AFTERINSTALL.conflist" ]
                                then
                                        echo "-- AFTERINSTALL operations (start)"
                                        sh -e "${DBDIR}/requires/$origin/AFTERINSTALL.conflist" || { echo "-- (This error is ignored)"; }
@@ -1978,7 +1990,6 @@ then
                        }
                        touch "${DBDIR}/requires/$origin/status/COMPLETE_CLEAN_AFTER_INSTALL"
                fi
-               echo $newpkg > ${DBDIR}/requires/$origin/pkgtag
                record_success $origin
                rm_a_line "$origin" "${DBDIR}/reinst_todo.list"
                rm -f "${DBDIR}/backup_failure/$currentpkg.tbz"