summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2013-08-25 16:45:00 +0200
committerGuillem Jover <guillem@debian.org>2013-10-15 06:56:46 +0200
commit1558f713929859db6a68594898bd3a4f59529a16 (patch)
tree756b225adace02d451d723ca415d37df1d85c7e5 /utils
parentc23a480b1dddd36dcdad3c08b3b692da55ccc7e0 (diff)
downloaddpkg-1558f713929859db6a68594898bd3a4f59529a16.tar.gz
u-a: Refactor alternative_evolve_slave() out of alternative_evolve()
Diffstat (limited to 'utils')
-rw-r--r--utils/update-alternatives.c86
1 files changed, 45 insertions, 41 deletions
diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index 7d74d1bd9..dfe34cdc6 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -2199,11 +2199,53 @@ alternative_select_mode(struct alternative *a, const char *current_choice)
}
static void
+alternative_evolve_slave(struct alternative *a, const char *cur_choice,
+ struct slave_link *sl, struct fileset *fs)
+{
+ struct stat st;
+ char *new_file = NULL;
+ const char *old, *new;
+
+ old = alternative_get_slave(a, sl->name)->link;
+ new = sl->link;
+
+ if (cur_choice && strcmp(cur_choice, fs->master_file) == 0) {
+ new_file = xstrdup(fileset_get_slave(fs, sl->name));
+ } else {
+ char *lnk;
+
+ xasprintf(&lnk, "%s/%s", altdir, sl->name);
+ new_file = areadlink(lnk);
+ free(lnk);
+ }
+ if (strcmp(old, new) != 0 &&
+ alternative_path_classify(old) == ALT_PATH_SYMLINK) {
+ bool rename_link = false;
+
+ if (new_file) {
+ errno = 0;
+ if (stat(new_file, &st) == -1 && errno != ENOENT)
+ syserr(_("cannot stat file '%s'"),
+ new_file);
+ rename_link = (errno == 0);
+ }
+
+ if (rename_link) {
+ info(_("renaming %s slave link from %s to %s"),
+ sl->name, old, new);
+ checked_mv(old, new);
+ } else {
+ checked_rm(old);
+ }
+ }
+ free(new_file);
+}
+
+static void
alternative_evolve(struct alternative *a, struct alternative *b,
const char *cur_choice, struct fileset *fs)
{
struct slave_link *sl;
- struct stat st;
bool is_link;
is_link = alternative_path_classify(a->master_link) == ALT_PATH_SYMLINK;
@@ -2217,46 +2259,8 @@ alternative_evolve(struct alternative *a, struct alternative *b,
/* Check if new slaves have been added, or existing
* ones renamed. */
for (sl = b->slaves; sl; sl = sl->next) {
- char *new_file = NULL;
- const char *old, *new;
-
- if (!alternative_has_slave(a, sl->name)) {
- alternative_add_slave(a, xstrdup(sl->name),
- xstrdup(sl->link));
- continue;
- }
- old = alternative_get_slave(a, sl->name)->link;
- new = sl->link;
- if (cur_choice && strcmp(cur_choice, fs->master_file) == 0) {
- new_file = xstrdup(fileset_get_slave(fs, sl->name));
- } else {
- char *lnk;
-
- xasprintf(&lnk, "%s/%s", altdir, sl->name);
- new_file = areadlink(lnk);
- free(lnk);
- }
- if (strcmp(old, new) != 0 &&
- alternative_path_classify(old) == ALT_PATH_SYMLINK) {
- bool rename_link = false;
-
- if (new_file) {
- errno = 0;
- if (stat(new_file, &st) == -1 && errno != ENOENT)
- syserr(_("cannot stat file '%s'"),
- new_file);
- rename_link = (errno == 0);
- }
-
- if (rename_link) {
- info(_("renaming %s slave link from %s to %s"),
- sl->name, old, new);
- checked_mv(old, new);
- } else {
- checked_rm(old);
- }
- }
- free(new_file);
+ if (alternative_has_slave(a, sl->name))
+ alternative_evolve_slave(a, cur_choice, sl, fs);
alternative_add_slave(a, xstrdup(sl->name), xstrdup(sl->link));
}
}