OSDN Git Service

[IMPROVED] The treatment of backup packages is modified to be safer by considering...
authorMamoru Sakaue / MwGhennndo <glmwghennndo@users.sourceforge.jp>
Thu, 17 Jan 2013 08:04:01 +0000 (17:04 +0900)
committerMamoru Sakaue / MwGhennndo <glmwghennndo@users.sourceforge.jp>
Thu, 17 Jan 2013 08:04:01 +0000 (17:04 +0900)
modified:   portsreinstall
modified:   portsreinstall.8

portsreinstall
portsreinstall.8

index 8e8b4b4..ce2dc98 100755 (executable)
@@ -10,7 +10,7 @@
 # ================================================
 
 APPNAME=`basename "$0"`
-MYVERSION=2.2.2+toward_2.2.3_20130114225853
+MYVERSION=2.2.2+toward_2.2.3_20130117165752
 
 PREFIX=${PREFIX:-/usr/local}
 CONFFILE=${PREFIX}/etc/${APPNAME}.conf
@@ -444,7 +444,7 @@ then
        }
        pkg_create_b ()
        {
-               pkg create -f tbz "$@"
+               pkg create "$@"
        }
        pkg_delete_f ()
        {
@@ -580,6 +580,28 @@ str_escape_regexp ()
        echo "$*" | str_escape_regexp_filter
 }
 
+create_backup_pkg ()
+{
+       local pkgname dstdir backup_pkg
+       pkgname=$1
+       dstdir=$2
+       rm -rf "${TMPDIR}"/package.tmp
+       mkdir "${TMPDIR}"/package.tmp
+       if ( cd "${TMPDIR}"/package.tmp && pkg_create_b "$pkgname" )
+       then
+               backup_pkg=`ls "${TMPDIR}"/package.tmp | \
+                       grep -m 1 -E "^`str_escape_regexp \"$pkgname\"`\.(txz|tbz|tgz|tar)$"` || :
+       fi
+       if [ -z "$backup_pkg" ]
+       then
+               echo "WARNING: Failed to create backup package for $pkgname" >&2
+               return 1
+       fi
+       [ -d "$dstdir" ] || mkdir -p "$dstdir"
+       mv "${TMPDIR}/package.tmp/$backup_pkg" "$dstdir"
+       echo "$dstdir/$backup_pkg"
+}
+
 rm_a_line ()
 {
        local item dstpath pattern
@@ -1187,8 +1209,7 @@ then
                                echo "INFO: The ports tree has a new version of ${APPNAME}. It will be updated first."
                                echo "Updating $self_origin ($self_pkg_current => $self_pkg_new)..."
                                echo "Backing up the installed package..."
-                               [ -d "${PORTSDIR}"/packages/All ] || mkdir -p "${PORTSDIR}"/packages/All
-                               ( cd "${PORTSDIR}"/packages/All/ && pkg_create_b "$self_pkg_current" )
+                               backup_pkg=`create_backup_pkg "$self_pkg_current" "${PORTSDIR}"/packages/All` || :
                                echo "Reinstalling ${APPNAME}..."
                                pkg_delete_f "$self_pkg_current"
                                if ( cd "${PORTSDIR}/$self_origin" && make reinstall )
@@ -1209,7 +1230,7 @@ then
                                        echo "WARNING: Reinstallation failed. Restoring the old package..." >&2
                                        ( cd "${PORTSDIR}/$self_origin" && make deinstall ) || :
                                        ( cd "${PORTSDIR}/$self_origin" && make clean ) || :
-                                       pkg_add_f "${PORTSDIR}"/packages/All/"$self_pkg_current.tbz"
+                                       [ -n "$backup_pkg" ] && pkg_add_f "$backup_pkg"
                                        echo "INFO: Continuing with the old version..."
                                fi
                        fi
@@ -2227,7 +2248,6 @@ then
        [ -d "${DBDIR}/status_deinst" ] || mkdir -p "${DBDIR}/status_deinst"
        if [ `cat "${DBDIR}/moved_or_lost.list" | wc -l` -gt 0 ]
        then
-               savedir=`pwd`
                if [ -f "${DBDIR}/moved_or_lost.list.remained" ]
                then
                        echo "INFO: Restarting from the previously terminated point"
@@ -2237,7 +2257,6 @@ then
                cp -p "${DBDIR}/moved_or_lost.list.remained" "${TMPDIR}/moved_or_lost.tmp"
                nlines=`cat "${TMPDIR}/moved_or_lost.tmp" | wc -l`
                iline=1
-               cd "${DBDIR}/backup_obsolete"
                while [ $iline -le $nlines ]
                do
                        origin=`sed -n ${iline}p "${TMPDIR}/moved_or_lost.tmp"`
@@ -2270,7 +2289,14 @@ then
                        tag=`echo $origin | sed 's|/|.|'`
                        if [ ! -e "${DBDIR}/status_deinst/$tag.backup" ]
                        then
-                               pkg_create_b "$currentpkg" || { echo "*** Continuating forcibly by hoping success..."; continue; }
+                               backup_pkg=`create_backup_pkg "$currentpkg" "${DBDIR}/backup_obsolete"` || :
+                               if [ -n "$backup_pkg" ]
+                               then
+                                       echo "$backup_pkg" > ${DBDIR}/requires/$origin/backedup_pkgfile
+                               else
+                                       echo "*** Continuating forcibly by keeping the installed package"
+                                       continue
+                               fi
                                touch "${DBDIR}/status_deinst/$tag.backup"
                        fi
                        echo "-- (Deleting package for $origin as $currentpkg)"
@@ -2279,7 +2305,6 @@ then
                        _MSG_CURRENT_STAGE=${_MSG_CURRENT_STAGE_general}
                        echo
                done
-               cd "$savedir"
        fi
        touch "${DBDIR}/COMPLETE_DEINST_OBS_PKGS"
        _MSG_CURRENT_STAGE=
@@ -2601,14 +2626,14 @@ then
                if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_PKG_BACKUP" ]
                then
                        echo "-- (Creating temporal backup package for $position_msg)"
-                       cd "${DBDIR}/backup_failure"
-                       pkg_create_b "$currentpkg" || \
+                       backup_pkg=`create_backup_pkg "$currentpkg" "${DBDIR}/backup_failure"` || \
                        {
-                               rm -f "${DBDIR}/backup_failure/$currentpkg.tbz"
+                               rm -f "$backup_pkg"
                                echo "WARNING: Failed to create the backup package, but ignored by hoping success." >&2
                        }
                        cd "${PORTSDIR}/$origin"
                        echo $currentpkg > ${DBDIR}/requires/$origin/backedup_version
+                       echo $backup_pkg > ${DBDIR}/requires/$origin/backedup_pkgfile
                        touch "${DBDIR}/requires/$origin/status/COMPLETE_PKG_BACKUP"
                fi
                if [ -n "$currentpkg" -a ! -e "${DBDIR}/requires/$origin/status/COMPLETE_BEFOREDEINSTALL" ]
@@ -2668,10 +2693,11 @@ then
                                        if [ -n "$backedup_version" ]
                                        then
                                                echo "*** Restoring the backup of $backedup_version..."
-                                               if [ ! -e "${DBDIR}/backup_failure/$backedup_version.tbz" ]
+                                               backup_pkg=`cat "${DBDIR}/requires/$origin/backedup_pkgfile" || :`
+                                               if [ -z "$backup_pkg" -o ! -e "$backup_pkg" ]
                                                then
                                                        echo "WARNING: No backup exists, gave up." >&2
-                                               elif pkg_add_fF "${DBDIR}/backup_failure/$backedup_version.tbz"
+                                               elif pkg_add_fF "$backup_pkg"
                                                then
                                                        :
                                                else
@@ -2732,7 +2758,8 @@ then
                record_success $origin
                [ -e "${DBDIR}/requires/$origin/failed_requirements" ] && cp "${DBDIR}/requires/$origin/failed_requirements" "${DBDIR}/requires/$origin/failed_requirements.previous"
                rm_a_line "$origin" "${DBDIR}/reinst_todo.list"
-               rm -f "${DBDIR}/backup_failure/$currentpkg.tbz"
+               backup_pkg=`cat "${DBDIR}/requires/$origin/backedup_pkgfile" || :`
+               [ -n "$backup_pkg" -a -e "$backup_pkg" ] && rm -f "$backup_pkg"
                rm "${DBDIR}/requires/$origin/status/in_install"
                _MSG_CURRENT_STAGE=${_MSG_CURRENT_STAGE_general}
                echo
index cfb6f74..0cad9d7 100644 (file)
@@ -288,11 +288,11 @@ Configuration file of portupgrade(1).
 \fBportsreinstall\fR has been developed as below.
 .TP
 2.2.3 (? January 2013)
+[IMPROVED] The treatment of backup packages is modified to be safer by considering possible format fluctuation in case of pkgng.
+
 [MISC] Line feeds of the help and information messages are improved.
 
 [BUG FIX] Meaningless warnings at the end of leave ports are suppressed.
-
-[BUG FIX] The format of backup packages could fluctuate in case of pkgng.
 .TP
 2.2.2 (03 January 2013)
 [BUG FIX] Commands \fBok add\fR and \fBok del\fR failed if no port has reinstalled in the latest do/redo process.