-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/transaction_files.c: allow replacing file with alternative #253
base: master
Are you sure you want to change the base?
Conversation
This seems to fix the broken test cases, but with comments like "Leave removing alternative to dedicated phase." I think the test cases are not really correct, i.e. still depend on order of and/or that an alternative wasn't replaced with a non alternative symlink like it is the case with the gcc, clang to cc symlink replacing. I think for the future it would be good to open an RFC issue to get input before writing code, because I've also worked on this and my conclusion is that to actually fix all edge cases we have to know what alternatives are set, switched to and removed before starting the transaction. |
I believe this is as reliable as checking of current clobber, like file-directory, with order awareness. I couldn't come up with transaction sequence that causes wrong result and is not limitation of transaction_files too, like overwriting file of package that is not in transaction. Can you? By "Leave removing alternative to dedicated phase" I mean if there is nothing to install instead of removed alternative, let xbps_alternatives_unregister do the job, because there may be other providers installed. Probably I should open issue first but I feel they do not work well either, there are some of them with no conclusions for years. |
This is one of the ways this doesn't solve the problem, I really think to solve all edge cases a rewrite of the alternatives is necessary. From 16d00405bf05cde3a44ac9c1e8bb65f978eac7dc Mon Sep 17 00:00:00 2001
From: Duncan Overbruck <[email protected]>
Date: Tue, 24 Mar 2020 20:54:00 +0100
Subject: [PATCH] tests: add test case for cc alternatives removal
---
tests/xbps/xbps-alternatives/main_test.sh | 44 ++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/tests/xbps/xbps-alternatives/main_test.sh b/tests/xbps/xbps-alternatives/main_test.sh
index 6f11b906..f5e8e4c9 100644
--- a/tests/xbps/xbps-alternatives/main_test.sh
+++ b/tests/xbps/xbps-alternatives/main_test.sh
@@ -891,12 +891,53 @@ replace_file_with_alternative_body() {
xbps-install -r root --repository=repo -ydv -Su
atf_check_equal $? 0
- test -L root/usr/bin/file
+ test -h root/usr/bin/file
atf_check_equal $? 0
lnk=$(readlink -f root/usr/bin/file)
atf_check_equal $lnk "$PWD/root/usr/bin/pkg-a-file"
}
+atf_test_case cc_alternatives_removal
+
+cc_alternatives_removal_head() {
+ atf_set "descr" "xbps-alternatives: removal of the cc alternatives group"
+}
+cc_alternatives_removal_body() {
+ mkdir -p repo pkg_A/usr/bin
+ mkdir -p repo pkg_B/usr/bin
+ touch pkg_A/usr/bin/gcc
+ touch pkg_B/usr/bin/clang
+
+ cd repo
+ xbps-create -A noarch -n gcc-1.1_1 -s "gcc pkg" --alternatives "cc:cc:/usr/bin/gcc" ../pkg_A
+ atf_check_equal $? 0
+ xbps-create -A noarch -n clang-1.1_1 -s "clang pkg" --alternatives "cc:cc:/usr/bin/clang" ../pkg_B
+ atf_check_equal $? 0
+ xbps-rindex -d -a $PWD/*.xbps
+ atf_check_equal $? 0
+ cd ..
+
+ xbps-install -r root --repository=repo -ydv clang gcc
+ atf_check_equal $? 0
+
+ ln -s gcc pkg_A/usr/bin/cc
+ cd repo
+ rm -f *.xbps
+ xbps-create -A noarch -n gcc-1.1_2 -s "gcc pkg" ../pkg_A
+ atf_check_equal $? 0
+ xbps-create -A noarch -n clang-1.1_2 -s "clang pkg" ../pkg_B
+ atf_check_equal $? 0
+ xbps-rindex -d -a $PWD/*.xbps
+ atf_check_equal $? 0
+ cd ..
+
+ xbps-install -r root --repository=repo -dvyu gcc clang
+ atf_check_equal $? 0
+
+ test -h root/usr/bin/cc
+ atf_check_equal $? 0
+}
+
atf_init_test_cases() {
atf_add_test_case register_one
atf_add_test_case register_one_dangling
@@ -919,4 +960,5 @@ atf_init_test_cases() {
atf_add_test_case replace_alternative_with_symlink
atf_add_test_case keep_provider_on_update
atf_add_test_case replace_file_with_alternative
+ atf_add_test_case cc_alternatives_removal
}
--
2.25.2
Even if there are some without resolution, I could have given my thoughts on this so we don't end up writing the same things or come up with incomplete fixes that work around the current test cases. |
This is the main problem, file conflicts are completely independent of order and can be detected anyways. Alternatives are different in this regard, the alternatives code is broken by itself and IMHO needs to be rewritten and properly designed to fix this issue. |
Ok, cc example indeed shows there will be always unexpected case. Your proposed solution is better, but is still complicated. What about following process?
|
I was also thinking about simplifying this, but things like hooks that potentially use alternatives like awk and the old cc alternative make this complicated. I think the only complete solution would be something that takes the transaction and creates an "alternatives changeset" which can be fed into As example pkg A is removed and switches to the next next alternative group from pkg B, then B is removed and switches to the next alternative C which then is also removed. |
I think we have to come up with a spec/design for alternatives in general to actually start solving this problem. |
Pre-install hook run during extract means we also need to reorder transaction to avoid: uninstall gawk - use awk - install nawk. This is going too far. Maybe solution is to remove all alternatives for time of unpacking to guarantee fail of using awk and not to care about order. |
I think hooks are fine, but I would like to reduce the need for them in the long term. |
Oh yea I see, there could be INSTALL scripts from unrelated packages where the alternative is theoretically installed but not available. The transaction order tbh is something I was thinking about a bit too, I reverted some code I wrote that recursively adds revdeps if there are shlib issues but I wasn't really sure if the order is important. The readline revbump and the resulting update of bash is a good example for something that we really can not solve and makes hooks really fragile. Edit: |
Sounds good. |
With pre-install hooks run before unpacking, assuring that there is some provider of alternative in middle of transaction seems to not be a problem. Are there any more concerns with this simplified approach? |
It would simplifies it so far that we can compute the end result of all alternative chanegs before starting the transaction and feed the changes into I have a WIP branch that moves the hooks at the beginning of the transaction, but because I still need to solve some issues and optimize it to avoid having to open each archive twice at the beginning of the transaction, once for Not sure yet about |
|
The part about moving hooks has been implemented and merged already, right? |
Fix alternative-file clobber by adding alternatives to obsolete files processing. More test cases, like removing one alternative provider when other is installed and not in transaction, are already written, so not adding duplicates.
Other commit is not related to topic, just found it breaking compilation with -Og.