[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 3/4] kernel2: get_node_in_dir() raussplitten



* kernel2: get_node_in_dir() ist der Teil von lio_get_resource(), der in
  einer gegebenen Verzeichnis-Ressource nach einem Eintrag sucht. Das
  ist auch in anderen Zusammenhängen nützlich.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/kernel2/src/lostio/client.c | 47 +++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/src/kernel2/src/lostio/client.c b/src/kernel2/src/lostio/client.c
index 8f3bcd1..770b675 100644
--- a/src/kernel2/src/lostio/client.c
+++ b/src/kernel2/src/lostio/client.c
@@ -114,6 +114,32 @@ static struct lio_resource* resolve_symlink(struct lio_resource* link,
     return lio_do_get_resource(buf, 1, depth + 1);
 }
 
+static int get_node_in_dir(struct lio_resource* dir, const char* name,
+                           struct lio_node** node)
+{
+    struct lio_node* n;
+    int ret;
+    int i;
+
+    // Falls die Liste der Kinder nicht geladen ist, nachholen
+    if (dir->children == NULL) {
+        ret = dir->tree->service->lio_ops.load_children(dir);
+        if (ret < 0) {
+            return ret;
+        }
+    }
+
+    // Passendes Kind raussuchen
+    for (i = 0; (n = list_get_element_at(dir->children, i)); i++) {
+        if (strcmp(n->name, name) == 0) {
+            *node = n;
+            return 0;
+        }
+    }
+
+    return -ENOENT;
+}
+
 struct lio_resource* lio_do_get_resource(const char* path, int follow_symlinks,
                                          int depth)
 {
@@ -124,7 +150,7 @@ struct lio_resource* lio_do_get_resource(const char* path, int follow_symlinks,
     char* tokenize_path;
     char* name;
     char* old_name = NULL;
-    int i;
+    int ret;
 
     // Passenden Baum raussuchen
     tree = lio_get_tree(path, &rel_path, depth);
@@ -160,24 +186,13 @@ struct lio_resource* lio_do_get_resource(const char* path, int follow_symlinks,
             goto out;
         }
 
-        // Falls die Liste der Kinder nicht geladen ist, nachholen
-        if (res->children == NULL) {
-            if (tree->service->lio_ops.load_children(res)) {
-                res = NULL;
-                goto out;
-            }
-        }
-
         // Passendes Kind raussuchen
-        for (i = 0; (node = list_get_element_at(res->children, i)); i++) {
-            if (strcmp(node->name, name) == 0) {
-                goto found;
-            }
+        ret = get_node_in_dir(res, name, &node);
+        if (ret < 0) {
+            res = NULL;
+            goto out;
         }
-        res = NULL;
-        goto out;
 
-found:
         // Passender Kindknoten wurde gefunden, weiter im Pfad
         old_name = name;
         name = strtok_r(NULL, "/", &saveptr);
-- 
2.1.4