aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-11 19:42:50 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-11 19:42:50 +0000
commit5b88d3a5f606f15259e3c14b0ac416df43d4f0df (patch)
tree5b75f1a077b443fda0a9caf214b2bc8ad7587f0e
parent95002b562ccff00e84ca458e4c00b9ec12dbaeaa (diff)
downloadpaludis-5b88d3a5f606f15259e3c14b0ac416df43d4f0df.tar.gz
paludis-5b88d3a5f606f15259e3c14b0ac416df43d4f0df.tar.xz
Split out unmerge. When reinstalling a package version, unmerge the old build after merging the new build.
-rw-r--r--ebuild/builtin_merge.bash12
-rw-r--r--ebuild/builtin_unmerge.bash78
-rw-r--r--ebuild/utils/Makefile.am10
-rwxr-xr-xebuild/utils/unmerge113
-rw-r--r--ebuild/utils/unmerge_TEST.bash66
-rwxr-xr-xebuild/utils/unmerge_TEST_cleanup.sh11
-rwxr-xr-xebuild/utils/unmerge_TEST_setup.sh8
7 files changed, 219 insertions, 79 deletions
diff --git a/ebuild/builtin_merge.bash b/ebuild/builtin_merge.bash
index 6c0a9d3..3c1be6a 100644
--- a/ebuild/builtin_merge.bash
+++ b/ebuild/builtin_merge.bash
@@ -42,6 +42,12 @@ builtin_merge()
cp "${ECLASSDIR}/${i}".eclass "${dbdir}/" || die "save eclass ${i} failed"
done
+ local reinstall=
+ if [[ -f "${dbdir}/CONTENTS" ]] ; then
+ mv "${dbdir}/CONTENTS" "${dbdir}/OLDCONTENTS" || die "save contents failed"
+ reinstall="yes"
+ fi
+
env | bzip2 > ${dbdir}/environment.bz2
> ${dbdir}/CONTENTS
@@ -66,6 +72,12 @@ builtin_merge()
fi
fi
+ if [[ -n "${reinstall}" ]] ; then
+ ${PALUDIS_EBUILD_MODULES_DIR}/utils/unmerge "${ROOT}/" "${dbdir}/OLDCONTENTS" \
+ || die "unmerge failed"
+ rm -f "${dbdir}/OLDCONTENTS"
+ fi
+
[[ $olddotglob != 0 ]] && shopt -u dotglob
shopt -q dotglob
[[ $olddotglob == $? ]] || ebuild_notice "warning" "shopt dotglob restore failed"
diff --git a/ebuild/builtin_unmerge.bash b/ebuild/builtin_unmerge.bash
index 9582edf..4fd8ae6 100644
--- a/ebuild/builtin_unmerge.bash
+++ b/ebuild/builtin_unmerge.bash
@@ -28,82 +28,8 @@ builtin_unmerge()
eval "${v}='$(< ${dbdir}/${v} )' || die \"Load key ${v} failed\""
done
- sort -r -t ' ' -k 2 < "${dbdir}/CONTENTS" | \
- while read entry ; do
- [[ -z "${entry}" ]] && continue
- local items=( ${entry} )
- case ${items[0]} in
- dir)
- ;;
-
- sym)
- if ! [[ -L "${ROOT}/${items[1]}" ]] ; then
- echo "skip !type ${items[1]}"
- elif [[ $(readlink "${ROOT}/${items[1]}" ) != "${items[3]}" ]] ; then
- echo "skip !dest ${items[1]}"
- elif [[ $(stat -c '%Y' "${ROOT}/${items[1]}" ) != "${items[4]}" ]] ; then
- echo "skip !time ${items[1]}"
- else
- echo "remove ${items[1]}"
- rm -f "${ROOT}/${items[1]}"
- fi
- ;;
-
- obj)
- if ! [[ -f "${ROOT}/${items[1]}" ]] ; then
- echo "skip !type ${items[1]}"
- elif [[ $(md5sum "${ROOT}/${items[1]}" | cut -d' ' -f1 ) != "${items[2]}" ]] ; then
- echo "skip !md5 ${items[1]}"
- elif [[ $(stat -c '%Y' "${ROOT}/${items[1]}" ) != "${items[3]}" ]] ; then
- echo "skip !time ${items[1]}"
- else
- echo "remove ${items[1]}"
- rm -f "${ROOT}/${items[1]}"
- fi
- ;;
-
- misc)
- if [[ -f "${ROOT}/${items[1]}" ]] ; then
- echo "skip !type ${items[1]}"
- elif [[ $(stat -c '%Y' "${ROOT}/${items[1]}" ) != "${items[2]}" ]] ; then
- echo "skip !time ${items[1]}"
- else
- echo "remove ${items[1]}"
- rm -f "${ROOT}/${items[1]}"
- fi
- ;;
-
- *)
- die "Unknown VDB entry kind '${kind}'"
- ;;
- esac
- done
-
- shopt -q dotglob
- local olddotglob=$?
- shopt -s dotglob
-
- sort -r -t ' ' -k 2 < "${dbdir}/CONTENTS" | \
- while read entry ; do
- [[ -z "${entry}" ]] && continue
- local items=( ${entry} )
- case ${items[0]} in
- dir)
- if ! [[ -d "${ROOT}/${items[1]}" ]] ; then
- echo "skip !type ${items[1]}"
- elif [[ $(echo "${ROOT}/${items[1]}"/* ) != "${ROOT}/${items[1]}/*" ]] ; then
- echo "skip !empty ${items[1]}"
- else
- echo "remove ${items[1]}"
- rm -fr "${ROOT}/${items[1]}"
- fi
- ;;
- esac
- done
-
- [[ $olddotglob != 0 ]] && shopt -u dotglob
- shopt -q dotglob
- [[ $olddotglob == $? ]] || ebuild_notice "warning" "shopt dotglob restore failed"
+ ${PALUDIS_EBUILD_MODULES_DIR}/utils/unmerge "${ROOT}/" "${dbdir}/CONTENTS" \
+ || die "unmerge failed"
rm -fr "${dbdir}"
}
diff --git a/ebuild/utils/Makefile.am b/ebuild/utils/Makefile.am
index b7a8182..3c82fe4 100644
--- a/ebuild/utils/Makefile.am
+++ b/ebuild/utils/Makefile.am
@@ -37,7 +37,8 @@ libexecprog_SCRIPTS = \
newlib.a \
newlib.so \
newman \
- newsbin
+ newsbin \
+ unmerge
TESTS_ENVIRONMENT = env \
PALUDIS_EBUILD_DIR="$(top_srcdir)/ebuild/" \
@@ -45,9 +46,12 @@ TESTS_ENVIRONMENT = env \
TEST_SCRIPT_DIR="$(srcdir)/" \
$(SHELL) $(top_srcdir)/ebuild/utils/run_test.bash
-TESTS = merge_TEST.bash dobin_TEST.bash
+TESTS = merge_TEST.bash dobin_TEST.bash unmerge_TEST.bash
EXTRA_DIST = $(libexecprog_SCRIPTS) $(TESTS) run_test.bash
-check_SCRIPTS = $(TESTS) merge_TEST_setup.sh merge_TEST_cleanup.sh
+check_SCRIPTS = $(TESTS) \
+ merge_TEST_setup.sh merge_TEST_cleanup.sh \
+ unmerge_TEST_setup.sh unmerge_TEST_cleanup.sh
+
check_PROGRAMS =
diff --git a/ebuild/utils/unmerge b/ebuild/utils/unmerge
new file mode 100755
index 0000000..06c1868
--- /dev/null
+++ b/ebuild/utils/unmerge
@@ -0,0 +1,113 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License as published by the Free Software Foundation; either version
+# 2 of the License, or (at your option) any later version.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+
+source ${PALUDIS_EBUILD_DIR}/echo_functions.bash
+
+if [[ -z "${1}" ]] || [[ -z "${2}" ]] ; then
+ echo "usage: ${0} from contents"
+ exit 247
+fi
+
+shopt -s dotglob
+shopt -s nullglob
+
+ROOT=$(readlink -f "${1%/}" )
+ROOT="${ROOT//+(\/)/\/}"
+export ROOT
+export contents=${2}
+
+if [[ ! -d ${ROOT} ]] ; then
+ echo "${ROOT}: not a directory; aborting" >&2
+ exit 247
+fi
+
+if [[ ! -f "${contents}" ]] ; then
+ echo "${contents}: not a file; aborting" >&2
+ exit 247
+fi
+
+sort -r -t ' ' -k 2 < "${contents}" | \
+while read entry ; do
+ [[ -z "${entry}" ]] && continue
+ items=( ${entry} )
+ case ${items[0]} in
+ dir)
+ ;;
+
+ sym)
+ if ! [[ -L "${ROOT}/${items[1]}" ]] ; then
+ echo "skip !type ${items[1]}"
+ elif [[ $(readlink "${ROOT}/${items[1]}" ) != "${items[3]}" ]] ; then
+ echo "skip !dest ${items[1]}"
+ elif [[ $(stat -c '%Y' "${ROOT}/${items[1]}" ) != "${items[4]}" ]] ; then
+ echo "skip !time ${items[1]}"
+ else
+ echo "remove ${items[1]}"
+ rm -f "${ROOT}/${items[1]}"
+ fi
+ ;;
+
+ obj)
+ if ! [[ -f "${ROOT}/${items[1]}" ]] ; then
+ echo "skip !type ${items[1]}"
+ elif [[ $(md5sum "${ROOT}/${items[1]}" | cut -d' ' -f1 ) != "${items[2]}" ]] ; then
+ echo "skip !md5 ${items[1]}"
+ elif [[ $(stat -c '%Y' "${ROOT}/${items[1]}" ) != "${items[3]}" ]] ; then
+ echo "skip !time ${items[1]}"
+ else
+ echo "remove ${items[1]}"
+ rm -f "${ROOT}/${items[1]}"
+ fi
+ ;;
+
+ misc)
+ if [[ -f "${ROOT}/${items[1]}" ]] ; then
+ echo "skip !type ${items[1]}"
+ elif [[ $(stat -c '%Y' "${ROOT}/${items[1]}" ) != "${items[2]}" ]] ; then
+ echo "skip !time ${items[1]}"
+ else
+ echo "remove ${items[1]}"
+ rm -f "${ROOT}/${items[1]}"
+ fi
+ ;;
+
+ *)
+ die "Unknown VDB entry kind '${kind}'"
+ ;;
+ esac
+done
+
+sort -r -t ' ' -k 2 < "${contents}" | \
+while read entry ; do
+ [[ -z "${entry}" ]] && continue
+ items=( ${entry} )
+ case ${items[0]} in
+ dir)
+ if ! [[ -d "${ROOT}/${items[1]}" ]] ; then
+ echo "skip !type ${items[1]}"
+ elif [[ $(echo "${ROOT}/${items[1]}"/* ) != "${ROOT}/${items[1]}/*" ]] ; then
+ echo "skip !empty ${items[1]}"
+ else
+ echo "remove ${items[1]}"
+ rm -fr "${ROOT}/${items[1]}"
+ fi
+ ;;
+ esac
+done
+
diff --git a/ebuild/utils/unmerge_TEST.bash b/ebuild/utils/unmerge_TEST.bash
new file mode 100644
index 0000000..a494064
--- /dev/null
+++ b/ebuild/utils/unmerge_TEST.bash
@@ -0,0 +1,66 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+
+unmerge_empty_TEST()
+{
+ ./merge "unmerge_TEST_dir/empty_src" \
+ "unmerge_TEST_dir/empty_dst" \
+ "unmerge_TEST_dir/empty_contents" 1>/dev/null
+ test_return_code
+
+ ./unmerge "unmerge_TEST_dir/empty_dst" \
+ "unmerge_TEST_dir/empty_contents" 1>/dev/null
+ test_return_code
+
+ ok=
+ for a in unmerge_TEST_dir/empty_dst/* ; do
+ [[ -e "$a" ]] || continue
+ test_equality "$a" ""
+ ok=no
+ done
+ test_equality "$ok" ""
+}
+
+unmerge_files_TEST()
+{
+ ./merge "unmerge_TEST_dir/files_src" \
+ "unmerge_TEST_dir/files_dst" \
+ "unmerge_TEST_dir/files_contents" 1>/dev/null
+ test_return_code
+
+ ok=
+ for a in unmerge_TEST_dir/files_dst/* ; do
+ [[ -e "$a" ]] || continue
+ ok=yes
+ break
+ done
+ test_equality "$ok" "yes"
+
+ ./unmerge "unmerge_TEST_dir/files_dst" \
+ "unmerge_TEST_dir/files_contents" 1>/dev/null
+ test_return_code
+
+ ok=
+ for a in unmerge_TEST_dir/files_dst/* ; do
+ [[ -e "$a" ]] || continue
+ test_equality "$a" ""
+ ok=no
+ done
+ test_equality "$ok" ""
+}
+
diff --git a/ebuild/utils/unmerge_TEST_cleanup.sh b/ebuild/utils/unmerge_TEST_cleanup.sh
new file mode 100755
index 0000000..1af2ac4
--- /dev/null
+++ b/ebuild/utils/unmerge_TEST_cleanup.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d unmerge_TEST_dir ] ; then
+ rm -fr unmerge_TEST_dir
+else
+ true
+fi
+
+
+
diff --git a/ebuild/utils/unmerge_TEST_setup.sh b/ebuild/utils/unmerge_TEST_setup.sh
new file mode 100755
index 0000000..8cbfd3a
--- /dev/null
+++ b/ebuild/utils/unmerge_TEST_setup.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir -p unmerge_TEST_dir/{empty_src,empty_dst} || exit 2
+
+mkdir -p unmerge_TEST_dir/{files_src,files_dst} || exit 3
+echo "file one" > unmerge_TEST_dir/files_src/one
+echo "file two" > unmerge_TEST_dir/files_src/two