21255d
From eacb511fc0d1e3c5857cb041ad162fb78b4381cc Mon Sep 17 00:00:00 2001
21255d
From: Ruixin Bao <rubao@redhat.com>
21255d
Date: Sun, 26 Aug 2018 20:00:03 +0000
21255d
Subject: [PATCH] install: small refactor to combine two function calls into
21255d
 one function
21255d
21255d
Combine consecutive function calls of install_info_discover and
21255d
install_info_may_process into one short helper function.
21255d
21255d
(cherry picked from commit 1e475a0ab4c46eb07f3df3fb24f5a7c3e1fa20b1)
21255d
21255d
Related: #1812972
21255d
---
21255d
 src/shared/install.c | 61 ++++++++++++++++++++++----------------------
21255d
 1 file changed, 30 insertions(+), 31 deletions(-)
21255d
21255d
diff --git a/src/shared/install.c b/src/shared/install.c
21255d
index 1d4beaa83b..263b239f10 100644
21255d
--- a/src/shared/install.c
21255d
+++ b/src/shared/install.c
21255d
@@ -1676,6 +1676,25 @@ static int install_info_discover(
21255d
         return r;
21255d
 }
21255d
 
21255d
+static int install_info_discover_and_check(
21255d
+                        UnitFileScope scope,
21255d
+                        InstallContext *c,
21255d
+                        const LookupPaths *paths,
21255d
+                        const char *name,
21255d
+                        SearchFlags flags,
21255d
+                        UnitFileInstallInfo **ret,
21255d
+                        UnitFileChange **changes,
21255d
+                        size_t *n_changes) {
21255d
+
21255d
+        int r;
21255d
+
21255d
+        r = install_info_discover(scope, c, paths, name, flags, ret, changes, n_changes);
21255d
+        if (r < 0)
21255d
+                return r;
21255d
+
21255d
+        return install_info_may_process(ret ? *ret : NULL, paths, changes, n_changes);
21255d
+}
21255d
+
21255d
 static int install_info_symlink_alias(
21255d
                 UnitFileInstallInfo *i,
21255d
                 const LookupPaths *paths,
21255d
@@ -2399,11 +2418,8 @@ int unit_file_add_dependency(
21255d
         if (!config_path)
21255d
                 return -ENXIO;
21255d
 
21255d
-        r = install_info_discover(scope, &c, &paths, target, SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
-                                  &target_info, changes, n_changes);
21255d
-        if (r < 0)
21255d
-                return r;
21255d
-        r = install_info_may_process(target_info, &paths, changes, n_changes);
21255d
+        r = install_info_discover_and_check(scope, &c, &paths, target, SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
+                                            &target_info, changes, n_changes);
21255d
         if (r < 0)
21255d
                 return r;
21255d
 
21255d
@@ -2412,11 +2428,8 @@ int unit_file_add_dependency(
21255d
         STRV_FOREACH(f, files) {
21255d
                 char ***l;
21255d
 
21255d
-                r = install_info_discover(scope, &c, &paths, *f, SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
-                                          &i, changes, n_changes);
21255d
-                if (r < 0)
21255d
-                        return r;
21255d
-                r = install_info_may_process(i, &paths, changes, n_changes);
21255d
+                r = install_info_discover_and_check(scope, &c, &paths, *f, SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
+                                                    &i, changes, n_changes);
21255d
                 if (r < 0)
21255d
                         return r;
21255d
 
21255d
@@ -2467,11 +2480,8 @@ int unit_file_enable(
21255d
                 return -ENXIO;
21255d
 
21255d
         STRV_FOREACH(f, files) {
21255d
-                r = install_info_discover(scope, &c, &paths, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
-                                          &i, changes, n_changes);
21255d
-                if (r < 0)
21255d
-                        return r;
21255d
-                r = install_info_may_process(i, &paths, changes, n_changes);
21255d
+                r = install_info_discover_and_check(scope, &c, &paths, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
+                                                    &i, changes, n_changes);
21255d
                 if (r < 0)
21255d
                         return r;
21255d
 
21255d
@@ -2585,10 +2595,7 @@ int unit_file_set_default(
21255d
         if (r < 0)
21255d
                 return r;
21255d
 
21255d
-        r = install_info_discover(scope, &c, &paths, name, 0, &i, changes, n_changes);
21255d
-        if (r < 0)
21255d
-                return r;
21255d
-        r = install_info_may_process(i, &paths, changes, n_changes);
21255d
+        r = install_info_discover_and_check(scope, &c, &paths, name, 0, &i, changes, n_changes);
21255d
         if (r < 0)
21255d
                 return r;
21255d
 
21255d
@@ -3089,22 +3096,14 @@ static int preset_prepare_one(
21255d
                 if (instance_name_list) {
21255d
                         char **s;
21255d
                         STRV_FOREACH(s, instance_name_list) {
21255d
-                                r = install_info_discover(scope, plus, paths, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
-                                                          &i, changes, n_changes);
21255d
-                                if (r < 0)
21255d
-                                        return r;
21255d
-
21255d
-                                r = install_info_may_process(i, paths, changes, n_changes);
21255d
+                                r = install_info_discover_and_check(scope, plus, paths, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
+                                                                    &i, changes, n_changes);
21255d
                                 if (r < 0)
21255d
                                         return r;
21255d
                         }
21255d
                 } else {
21255d
-                        r = install_info_discover(scope, plus, paths, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
-                                                  &i, changes, n_changes);
21255d
-                        if (r < 0)
21255d
-                                return r;
21255d
-
21255d
-                        r = install_info_may_process(i, paths, changes, n_changes);
21255d
+                        r = install_info_discover_and_check(scope, plus, paths, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
21255d
+                                                            &i, changes, n_changes);
21255d
                         if (r < 0)
21255d
                                 return r;
21255d
                 }