collapse duplicate branches in save_config code paths to keep things simple
authorMike Frysinger <vapier@gentoo.org>
Wed, 4 Jan 2012 06:19:09 +0000 (06:19 +0000)
committerMike Frysinger <vapier@gentoo.org>
Wed, 4 Jan 2012 06:19:09 +0000 (06:19 +0000)
eclass/savedconfig.eclass

index 626e7e16be5c34e99401bc99ec69dcb874551be7..f07ac8658562385d27866c2a623c079998411485 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.16 2011/12/27 17:55:12 fauli Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/savedconfig.eclass,v 1.17 2012/01/04 06:19:09 vapier Exp $
 
 # @ECLASS: savedconfig.eclass
 # @MAINTAINER:
@@ -29,25 +29,23 @@ save_config() {
        if [[ ${EBUILD_PHASE} != "install" ]]; then
                die "Bad package!  save_config only for use in src_install functions!"
        fi
-       [[ -z "${ED}" ]] && ED=${D}
-       case $# in
-               0) die "Tell me what to save"
-                       ;;
-               1) if [[ -f "$1" ]]; then
-                               dodir /etc/portage/savedconfig/${CATEGORY}
-                               cp "$1" "${ED}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
-                                       || die "Failed to save $1"
-                       else
-                               dodir /etc/portage/savedconfig/${CATEGORY}/${PF}
-                               treecopy "$1" "${ED}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
-                                       || die "Failed to save $1"
-                       fi
-                       ;;
-               *)
-                       dodir "${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF}
-                       treecopy $* "${D}/${PORTAGE_CONFIGROOT}"/etc/portage/savedconfig/${CATEGORY}/${PF} \
-                                       || die "Failed to save $1"
-       esac
+       [[ $# -eq 0 ]] && die "Usage: save_config <files>"
+
+       # Be lazy in our EAPI compat
+       : ${ED:-${D}}
+
+       local dest="/etc/portage/savedconfig/${CATEGORY}"
+       if [[ $# -eq 1 && -f $1 ]] ; then
+               # Just one file, so have the ${PF} be that config file
+               dodir "${dest}"
+               cp "$@" "${ED}/${dest}/${PF}" || die "failed to save $*"
+       else
+               # A dir, or multiple files, so have the ${PF} be a dir
+               # with all the saved stuff below it
+               dodir "${dest}/${PF}"
+               treecopy "$@" "${ED}/${dest}/${PF}" || die "failed to save $*"
+       fi
+
        elog "Your configuration for ${CATEGORY}/${PF} has been saved in "
        elog "/etc/portage/savedconfig/${CATEGORY}/${PF} for your editing pleasure."
        elog "You can edit these files by hand and remerge this package with"