diff options
author | Göktürk Yüksek <gokturk@gentoo.org> | 2020-01-30 21:56:07 -0500 |
---|---|---|
committer | Sergei Trofimovich <slyfox@gentoo.org> | 2020-01-31 07:36:49 +0000 |
commit | be107b6d5b572d9f13e64b4b53dc687f74193c56 (patch) | |
tree | 206674f985da9c933851b17c51f679522b67d9e6 | |
parent | crossdev: update profiles/categories during uninstall (diff) | |
download | crossdev-be107b6d5b572d9f13e64b4b53dc687f74193c56.tar.gz crossdev-be107b6d5b572d9f13e64b4b53dc687f74193c56.tar.bz2 crossdev-be107b6d5b572d9f13e64b4b53dc687f74193c56.zip |
crossdev: remove the output overlay during uninstallation when possible
If the output overlay is created solely for one specific CTARGET, and
not modified by the user in any way, it makes no sense to leave it
behind.
Remove the output overlay if the following conditions are met:
- The profiles/categories is empty
- metadata/layout.conf is managed by crossdev
- The only files in the overlay are profiles/categories and metadata/layout.conf
Signed-off-by: Göktürk Yüksek <gokturk@gentoo.org>
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
-rwxr-xr-x | crossdev | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -562,6 +562,24 @@ uninstall() { sed -e "/cross-${CTARGET}/d" \ -i "${CROSSDEV_OVERLAY}"/profiles/categories fi + # If profiles/categories is empty, see if we can remove the output overlay entirely + # The conservative criteria for removal are as follows: + # - The profiles/categories is empty + # - metadata/layout.conf is managed by crossdev + # - The only files in the overlay are profiles/categories and metadata/layout.conf + # Otherwise, we leave the overlay alone + if [[ ! -s "${CROSSDEV_OVERLAY}"/profiles/categories ]]; then + # Check if layout.conf is managed by crossdev + if grep -qs "^${AUTOGEN_TAG}" "${CROSSDEV_OVERLAY}"/metadata/layout.conf; then + # Check that there are no other files + local i=0 + while IFS="" read -d $'\0' -r; do + i=$((i + 1)) + done < <(find "${CROSSDEV_OVERLAY}" -type f -print0) + # Remove the overlay if we can + [[ ${i} -eq 2 ]] && rm -r "${CROSSDEV_OVERLAY}" + fi + fi # crossdev stopped creating 'package.keywords' in Jan 2020 for f in categories package.{accept_keywords,env,mask,keywords,use} profile/package.use.{force,mask} ; do f="${CONFIGROOT}/${f}" @@ -736,6 +754,7 @@ SEARCH_OVERLAYS="" CROSSDEV_OVERLAY="" CROSSDEV_OVERLAY_NAME="" CROSSDEV_OVERLAY_CREATE_REPOS_CONF="" +AUTOGEN_TAG="# Autogenerated and managed by crossdev" # These flags are always disabled for cross-gcc; either usually/always broken, or # not tested, or doesn't make sense, or no one simply cares about them GUSE_DISABLE="-boundschecking -d -gcj -gtk -libffi -mudflap -objc -objc++ -objc-gc" @@ -1206,7 +1225,6 @@ set_metadata() { # a layout.conf file so portage can find them. this is a crapshoot # when diff overlay sources have conflicting eclasses, but nothing # we really can do about that. - local autogen_tag="# Autogenerated and managed by crossdev" local meta=${CROSSDEV_OVERLAY}/metadata local repo_name local layout=${meta}/layout.conf @@ -1219,7 +1237,7 @@ set_metadata() { xmkdir -p "${meta}" if [[ -e ${layout} ]] ; then - if ! grep -qs "^${autogen_tag}" "${layout}" ; then + if ! grep -qs "^${AUTOGEN_TAG}" "${layout}" ; then einfo "leaving metadata/layout.conf alone in ${CROSSDEV_OVERLAY}" return fi @@ -1273,7 +1291,7 @@ set_metadata() { # write out that layout.conf! cat <<-EOF > "${layout}" || die "could not write ${layout}" - ${autogen_tag} + ${AUTOGEN_TAG} # Delete the above line if you want to manage this file yourself masters = ${masters% } repo-name = ${repo_name} @@ -1283,7 +1301,7 @@ set_metadata() { # If there is no repos.conf entry for the output overlay, create one here if [[ -n ${CROSSDEV_OVERLAY_CREATE_REPOS_CONF} ]]; then cat <<-EOF > "${CROSSDEV_OVERLAY_CREATE_REPOS_CONF}" || die "could not create the repo conf" - ${autogen_tag} + ${AUTOGEN_TAG} [${repo_name}] location = ${CROSSDEV_OVERLAY} masters = ${masters% } |