1 |
commit: be107b6d5b572d9f13e64b4b53dc687f74193c56 |
2 |
Author: Göktürk Yüksek <gokturk <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Jan 31 02:56:07 2020 +0000 |
4 |
Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jan 31 07:36:49 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/crossdev.git/commit/?id=be107b6d |
7 |
|
8 |
crossdev: remove the output overlay during uninstallation when possible |
9 |
|
10 |
If the output overlay is created solely for one specific CTARGET, and |
11 |
not modified by the user in any way, it makes no sense to leave it |
12 |
behind. |
13 |
|
14 |
Remove the output overlay if the following conditions are met: |
15 |
- The profiles/categories is empty |
16 |
- metadata/layout.conf is managed by crossdev |
17 |
- The only files in the overlay are profiles/categories and metadata/layout.conf |
18 |
|
19 |
Signed-off-by: Göktürk Yüksek <gokturk <AT> gentoo.org> |
20 |
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org> |
21 |
|
22 |
crossdev | 26 ++++++++++++++++++++++---- |
23 |
1 file changed, 22 insertions(+), 4 deletions(-) |
24 |
|
25 |
diff --git a/crossdev b/crossdev |
26 |
index 9427cf1..4576e0f 100755 |
27 |
--- a/crossdev |
28 |
+++ b/crossdev |
29 |
@@ -562,6 +562,24 @@ uninstall() { |
30 |
sed -e "/cross-${CTARGET}/d" \ |
31 |
-i "${CROSSDEV_OVERLAY}"/profiles/categories |
32 |
fi |
33 |
+ # If profiles/categories is empty, see if we can remove the output overlay entirely |
34 |
+ # The conservative criteria for removal are as follows: |
35 |
+ # - The profiles/categories is empty |
36 |
+ # - metadata/layout.conf is managed by crossdev |
37 |
+ # - The only files in the overlay are profiles/categories and metadata/layout.conf |
38 |
+ # Otherwise, we leave the overlay alone |
39 |
+ if [[ ! -s "${CROSSDEV_OVERLAY}"/profiles/categories ]]; then |
40 |
+ # Check if layout.conf is managed by crossdev |
41 |
+ if grep -qs "^${AUTOGEN_TAG}" "${CROSSDEV_OVERLAY}"/metadata/layout.conf; then |
42 |
+ # Check that there are no other files |
43 |
+ local i=0 |
44 |
+ while IFS="" read -d $'\0' -r; do |
45 |
+ i=$((i + 1)) |
46 |
+ done < <(find "${CROSSDEV_OVERLAY}" -type f -print0) |
47 |
+ # Remove the overlay if we can |
48 |
+ [[ ${i} -eq 2 ]] && rm -r "${CROSSDEV_OVERLAY}" |
49 |
+ fi |
50 |
+ fi |
51 |
# crossdev stopped creating 'package.keywords' in Jan 2020 |
52 |
for f in categories package.{accept_keywords,env,mask,keywords,use} profile/package.use.{force,mask} ; do |
53 |
f="${CONFIGROOT}/${f}" |
54 |
@@ -736,6 +754,7 @@ SEARCH_OVERLAYS="" |
55 |
CROSSDEV_OVERLAY="" |
56 |
CROSSDEV_OVERLAY_NAME="" |
57 |
CROSSDEV_OVERLAY_CREATE_REPOS_CONF="" |
58 |
+AUTOGEN_TAG="# Autogenerated and managed by crossdev" |
59 |
# These flags are always disabled for cross-gcc; either usually/always broken, or |
60 |
# not tested, or doesn't make sense, or no one simply cares about them |
61 |
GUSE_DISABLE="-boundschecking -d -gcj -gtk -libffi -mudflap -objc -objc++ -objc-gc" |
62 |
@@ -1206,7 +1225,6 @@ set_metadata() { |
63 |
# a layout.conf file so portage can find them. this is a crapshoot |
64 |
# when diff overlay sources have conflicting eclasses, but nothing |
65 |
# we really can do about that. |
66 |
- local autogen_tag="# Autogenerated and managed by crossdev" |
67 |
local meta=${CROSSDEV_OVERLAY}/metadata |
68 |
local repo_name |
69 |
local layout=${meta}/layout.conf |
70 |
@@ -1219,7 +1237,7 @@ set_metadata() { |
71 |
|
72 |
xmkdir -p "${meta}" |
73 |
if [[ -e ${layout} ]] ; then |
74 |
- if ! grep -qs "^${autogen_tag}" "${layout}" ; then |
75 |
+ if ! grep -qs "^${AUTOGEN_TAG}" "${layout}" ; then |
76 |
einfo "leaving metadata/layout.conf alone in ${CROSSDEV_OVERLAY}" |
77 |
return |
78 |
fi |
79 |
@@ -1273,7 +1291,7 @@ set_metadata() { |
80 |
|
81 |
# write out that layout.conf! |
82 |
cat <<-EOF > "${layout}" || die "could not write ${layout}" |
83 |
- ${autogen_tag} |
84 |
+ ${AUTOGEN_TAG} |
85 |
# Delete the above line if you want to manage this file yourself |
86 |
masters = ${masters% } |
87 |
repo-name = ${repo_name} |
88 |
@@ -1283,7 +1301,7 @@ set_metadata() { |
89 |
# If there is no repos.conf entry for the output overlay, create one here |
90 |
if [[ -n ${CROSSDEV_OVERLAY_CREATE_REPOS_CONF} ]]; then |
91 |
cat <<-EOF > "${CROSSDEV_OVERLAY_CREATE_REPOS_CONF}" || die "could not create the repo conf" |
92 |
- ${autogen_tag} |
93 |
+ ${AUTOGEN_TAG} |
94 |
[${repo_name}] |
95 |
location = ${CROSSDEV_OVERLAY} |
96 |
masters = ${masters% } |