aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-10 03:38:23 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-10 03:38:23 +0000
commit4a7ab0e529e65243368defbc9ee44f401700ed71 (patch)
treeed27260d989176a406bd0299ac570329f5154fd7
parent3a161b2c8ccf6a2a5f135a2369d642f662d6bb1e (diff)
downloadpaludis-4a7ab0e529e65243368defbc9ee44f401700ed71.tar.gz
paludis-4a7ab0e529e65243368defbc9ee44f401700ed71.tar.xz
Switch to using our own merger
-rw-r--r--ebuild/builtin_merge.bash14
-rw-r--r--ebuild/utils/Makefile.am11
-rwxr-xr-xebuild/utils/merge87
-rw-r--r--ebuild/utils/merge_TEST.bash90
-rwxr-xr-xebuild/utils/merge_TEST_cleanup.sh10
-rwxr-xr-xebuild/utils/merge_TEST_setup.sh26
-rw-r--r--ebuild/utils/run_test.bash62
7 files changed, 292 insertions, 8 deletions
diff --git a/ebuild/builtin_merge.bash b/ebuild/builtin_merge.bash
index 540e4ad..6eaced5 100644
--- a/ebuild/builtin_merge.bash
+++ b/ebuild/builtin_merge.bash
@@ -21,6 +21,10 @@ builtin_merge()
{
ebuild_section "Merging to '${ROOT:-/}'..."
+ shopt -q dotglob
+ local olddotglob=$?
+ shopt -s dotglob
+
if [[ -n "${D}" ]] && [[ -d "${D}" ]] ; then
if [[ -n "${CONFIG_PROTECT}" ]] ; then
local d f
@@ -36,9 +40,9 @@ builtin_merge()
fi
install -d "${ROOT}/" || die "couldn't make \${ROOT} (\"${ROOT}\")"
- if [[ -d "${D}" ]] && [[ $(echo ${D}/* ) != "${D}/*" ]] ; then
- cp --remove-destination -dfpR "${D}/"* "${ROOT}/" \
- || die "builtin_merge failed"
+ if [[ -d "${D}" ]] ; then
+ ${PALUDIS_EBUILD_MODULES_DIR}/utils/merge "${D}/" "${ROOT}/" \
+ || die "merge failed"
fi
fi
@@ -81,6 +85,10 @@ builtin_merge()
fi
done
fi
+
+ [[ $olddotglob != 0 ]] && shopt -u dotglob
+ shopt -q dotglob
+ [[ $olddotglob == $? ]] || ebuild_notice "warning" "shopt dotglob restore failed"
}
ebuild_f_merge()
diff --git a/ebuild/utils/Makefile.am b/ebuild/utils/Makefile.am
index 4a2da5b..d319a59 100644
--- a/ebuild/utils/Makefile.am
+++ b/ebuild/utils/Makefile.am
@@ -26,6 +26,7 @@ libexecprog_SCRIPTS = \
dosym \
fowners \
fperms \
+ merge \
newbin \
newconfd \
newdoc \
@@ -39,13 +40,13 @@ libexecprog_SCRIPTS = \
newsbin
TESTS_ENVIRONMENT = env \
- PALUDIS_EBUILD_DIR="$(srcdir)/ebuild/" \
+ PALUDIS_EBUILD_DIR="$(top_srcdir)/ebuild/" \
TEST_SCRIPT_DIR="$(srcdir)/" \
- $(SHELL) $(top_srcdir)/ebuild/run_test.bash
+ $(SHELL) $(top_srcdir)/ebuild/utils/run_test.bash
-TESTS =
-EXTRA_DIST = $(libexecprog_SCRIPTS) $(TESTS)
+TESTS = merge_TEST.bash
+EXTRA_DIST = $(libexecprog_SCRIPTS) $(TESTS) run_test.bash
-check_SCRIPTS = $(TESTS)
+check_SCRIPTS = $(TESTS) merge_TEST_setup.sh merge_TEST_cleanup.sh
check_PROGRAMS =
diff --git a/ebuild/utils/merge b/ebuild/utils/merge
new file mode 100755
index 0000000..20c76b6
--- /dev/null
+++ b/ebuild/utils/merge
@@ -0,0 +1,87 @@
+#!/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
+
+if [[ -z "${1}" ]] || [[ -z "${2}" ]] ; then
+ echo "usage: ${0} from to"
+ exit 247
+fi
+
+shopt -s dotglob
+shopt -s nullglob
+
+src=${1%/}/
+dst=${2%/}/
+
+if [[ ! -d ${src} ]] ; then
+ echo "${0}: ${src}: not a directory; aborting" >&2
+ exit 247
+fi
+
+if [[ ! -d ${dst} ]] ; then
+ echo "${0}: ${dst}: not a directory; aborting" >&2
+ exit 247
+fi
+
+merge_this()
+{
+ if [[ ! -d "${1}" ]] || [[ ! -d "${2}" ]] ; then
+ echo "${0}: merge_this called with bad parameters '${1}' '${2}'" >&2
+ exit 247
+ fi
+
+ local f ff r=0
+ for f in "${1}/"* ; do
+
+ ff=$(basename "${f}" )
+ if [[ -L "${f}" ]] ; then
+ if ! ln -s "$(readlink ${f} )" "${2}/${ff}" ; then
+ echo "${0}: error installing link ${f}"
+ r=1
+ fi
+ elif [[ -d ${f} ]] ; then
+ local ok=
+ if [[ -d "${2}/${ff}"/ ]] ; then
+ :
+ elif ! mkdir "${2}/${ff}" ; then
+ echo "${0}: error installing directory ${f}"
+ ok=no
+
+ fi
+
+ if [[ -z "${ok}" ]] ; then
+ if ! merge_this "${1}/${ff}" "${2}/${ff}" ; then
+ echo "${0}: error installing directory contents ${f}"
+ r=1
+ fi
+ else
+ r=1
+ fi
+ else
+ if ! cp -p "${f}" "${2}"/ ; then
+ echo "${0}: error installing file ${f}"
+ r=1
+ fi
+ fi
+ done
+
+ return $r
+}
+
+merge_this "${1}" "${2}"
+
diff --git a/ebuild/utils/merge_TEST.bash b/ebuild/utils/merge_TEST.bash
new file mode 100644
index 0000000..c1aba86
--- /dev/null
+++ b/ebuild/utils/merge_TEST.bash
@@ -0,0 +1,90 @@
+#!/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
+
+merge_empty_TEST()
+{
+ ./merge "merge_TEST_dir/empty_src" "merge_TEST_dir/empty_dst"
+ test_return_code
+}
+
+merge_files_TEST()
+{
+ ./merge "merge_TEST_dir/files_src" "merge_TEST_dir/files_dst"
+ test_return_code
+
+ [[ -f "merge_TEST_dir/files_dst/one" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/files_dst/one)" "contents of one"
+
+ [[ -f "merge_TEST_dir/files_dst/two" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/files_dst/two)" "contents of two"
+}
+
+merge_dirs_TEST()
+{
+ ./merge "merge_TEST_dir/dirs_src" "merge_TEST_dir/dirs_dst"
+ test_return_code
+
+ [[ -d "merge_TEST_dir/dirs_dst/dir_one" ]] ; test_return_code
+ [[ -d "merge_TEST_dir/dirs_dst/dir_two" ]] ; test_return_code
+ [[ -d "merge_TEST_dir/dirs_dst/dir_two/dir_three" ]] ; test_return_code
+
+ [[ -f "merge_TEST_dir/dirs_dst/dir_one/one" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/dirs_dst/dir_one/one)" "contents of one"
+
+ [[ -f "merge_TEST_dir/dirs_dst/dir_two/two" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/dirs_dst/dir_two/two)" "contents of two"
+
+ [[ -f "merge_TEST_dir/dirs_dst/dir_two/dir_three/three" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/dirs_dst/dir_two/dir_three/three)" "contents of three"
+}
+
+merge_dirs_over_TEST()
+{
+ ./merge "merge_TEST_dir/dirs_over_src" "merge_TEST_dir/dirs_over_dst"
+ test_return_code
+
+ [[ -d "merge_TEST_dir/dirs_over_dst/dir_one/" ]] ; test_return_code
+ [[ -d "merge_TEST_dir/dirs_over_dst/dir_two/" ]] ; test_return_code
+ [[ -d "merge_TEST_dir/dirs_over_dst/dir_two/dir_three/" ]] ; test_return_code
+
+ [[ -f "merge_TEST_dir/dirs_over_dst/dir_one/one" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/dirs_over_dst/dir_one/one)" "contents of one"
+
+ [[ -f "merge_TEST_dir/dirs_over_dst/dir_two/two" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/dirs_over_dst/dir_two/two)" "contents of two"
+
+ [[ -f "merge_TEST_dir/dirs_over_dst/dir_two/dir_three/three" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/dirs_over_dst/dir_two/dir_three/three)" "contents of three"
+}
+
+merge_links_TEST()
+{
+ ./merge "merge_TEST_dir/links_src" "merge_TEST_dir/links_dst"
+ test_return_code
+
+ [[ -f "merge_TEST_dir/links_dst/one" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/links_dst/one)" "contents of one"
+
+ [[ -f "merge_TEST_dir/links_dst/two" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/links_dst/two)" "contents of two"
+
+ [[ -f "merge_TEST_dir/links_dst/link_to_two" ]] ; test_return_code
+ [[ -L "merge_TEST_dir/links_dst/link_to_two" ]] ; test_return_code
+ test_equality "$(< merge_TEST_dir/links_dst/link_to_two)" "contents of two"
+}
+
diff --git a/ebuild/utils/merge_TEST_cleanup.sh b/ebuild/utils/merge_TEST_cleanup.sh
new file mode 100755
index 0000000..2fe5c7a
--- /dev/null
+++ b/ebuild/utils/merge_TEST_cleanup.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d merge_TEST_dir ] ; then
+ rm -fr merge_TEST_dir
+else
+ true
+fi
+
+
diff --git a/ebuild/utils/merge_TEST_setup.sh b/ebuild/utils/merge_TEST_setup.sh
new file mode 100755
index 0000000..ce0b146
--- /dev/null
+++ b/ebuild/utils/merge_TEST_setup.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir -p merge_TEST_dir/{empty_src,empty_dst} || exit 2
+
+mkdir -p merge_TEST_dir/{files_src,files_dst} || exit 2
+echo "contents of one" > merge_TEST_dir/files_src/one
+echo "contents of two" > merge_TEST_dir/files_src/two
+
+mkdir -p merge_TEST_dir/{dirs_src/{dir_one,dir_two/dir_three},dirs_dst} || exit 3
+echo "contents of one" > merge_TEST_dir/dirs_src/dir_one/one
+echo "contents of two" > merge_TEST_dir/dirs_src/dir_two/two
+echo "contents of three" > merge_TEST_dir/dirs_src/dir_two/dir_three/three
+
+mkdir -p merge_TEST_dir/{dirs_over_src/{dir_one,dir_two/dir_three},dirs_over_dst} || exit 4
+mkdir -p merge_TEST_dir/dirs_over_dst/{one,real}
+ln -s real merge_TEST_dir/dirs_over_dst/two
+echo "contents of one" > merge_TEST_dir/dirs_over_src/dir_one/one
+echo "contents of two" > merge_TEST_dir/dirs_over_src/dir_two/two
+echo "contents of three" > merge_TEST_dir/dirs_over_src/dir_two/dir_three/three
+
+mkdir -p merge_TEST_dir/{links_src,links_dst} || exit 5
+echo "contents of one" > merge_TEST_dir/links_src/one
+echo "contents of two" > merge_TEST_dir/links_src/two
+ln -s two merge_TEST_dir/links_src/link_to_two
+
diff --git a/ebuild/utils/run_test.bash b/ebuild/utils/run_test.bash
new file mode 100644
index 0000000..1f9db4e
--- /dev/null
+++ b/ebuild/utils/run_test.bash
@@ -0,0 +1,62 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+shopt -s expand_aliases
+shopt -s extglob
+set +o posix
+
+export TEST_STATUS=
+export PALUDIS_IN_TEST_FRAMEWORK="yes"
+
+test_return_code()
+{
+ local r="$?"
+ if [[ "0" == "${r}" ]] ; then
+ echo -n "."
+ else
+ echo -n "!{retcode: ${r}}"
+ export local_test_status="fail"
+ export TEST_STATUS="fail"
+ fi
+}
+
+test_equality()
+{
+ if [[ "${1}" == "${2}" ]] ; then
+ echo -n "."
+ else
+ echo -n "!{'${1}' not equal to '${2}'}"
+ export local_test_status="fail"
+ export TEST_STATUS="fail"
+ fi
+}
+
+if test -f "$TEST_SCRIPT_DIR""${1%.bash}"_"setup.sh" ; then
+ echo ">>> setup for test ${1%.bash}"
+ if ! "$TEST_SCRIPT_DIR""${1%.bash}"_"setup.sh" ; then
+ echo ">>> exiting with error for test ${1%.bash}"
+ exit 255
+ fi
+fi
+
+echo "Test program ${1%.bash}:"
+source "${1}" || exit 200
+
+for testname in $(set | grep '_TEST *() *$' ) ; do
+ [[ ${testname/()} != ${testname} ]] && continue
+ echo -n "* ${testname%_TEST}: "
+ export local_test_status=""
+ ${testname}
+ [[ -z "$local_test_status" ]] && echo " OK" || echo " FAIL"
+done
+
+if test -f "$TEST_SCRIPT_DIR""${1%.bash}"_"cleanup.sh" ; then
+ echo ">>> cleanup for test ${1%.bash}"
+ if ! "$TEST_SCRIPT_DIR""${1%.bash}"_"cleanup.sh" ; then
+ echo ">>> exiting with error for test ${1%.bash}"
+ exit 255
+ fi
+fi
+
+[[ -z "$TEST_STATUS" ]]
+