[LIBREPORT PATCH] fixed the symlinks handling in get_file_list abrt/abrt#686

Jiri Moskovcak jmoskovc at redhat.com
Wed Aug 28 16:44:23 UTC 2013


Signed-off-by: Jiri Moskovcak <jmoskovc at redhat.com>
---
 src/include/file_obj.h |  4 ++++
 src/lib/file_list.c    | 50 ++++++++++++++++++++++++++++++++++----------------
 src/lib/file_obj.c     | 10 ++++++++++
 3 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/src/include/file_obj.h b/src/include/file_obj.h
index 08823af..4f46bf6 100644
--- a/src/include/file_obj.h
+++ b/src/include/file_obj.h
@@ -30,3 +30,7 @@ typedef struct file_obj
     char *filename;
     char *fullpath; //the full path with extension
 } file_obj_t;
+
+void free_file_obj(file_obj_t *f);
+const char *fo_get_fullpath(file_obj_t *fo);
+const char *fo_get_filename(file_obj_t *fo);
diff --git a/src/lib/file_list.c b/src/lib/file_list.c
index 49cc4e1..3d0e43d 100644
--- a/src/lib/file_list.c
+++ b/src/lib/file_list.c
@@ -31,14 +31,21 @@ GList *get_file_list(const char *path, const char *ext_filter)
     struct dirent *dent;
     while ((dent = readdir(dir)) != NULL)
     {
-        char *ext = strrchr(dent->d_name, '.');
-        if (!ext)
+        /* skip . and .. */
+        if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0)
             continue;
-        if (ext_filter && strcmp(ext + 1, ext_filter) != 0)
-            continue;
-
         char *fullname = concat_path_file(path, dent->d_name);
-        *ext = '\0';
+        char *ext = NULL;
+
+        if (ext_filter)
+        {
+            ext = strrchr(dent->d_name, '.');
+            if (!ext)
+                continue;
+            if (ext_filter && strcmp(ext + 1, ext_filter) != 0)
+                continue;
+            *ext = '\0';
+        }
 
 //TODO: get rid of special handling of symlinks?
         struct stat buf;
@@ -50,20 +57,31 @@ GList *get_file_list(const char *path, const char *ext_filter)
             GError *error = NULL;
             gchar *link = g_file_read_link(fullname, &error);
             if (error != NULL)
-                error_msg_and_die("Error reading symlink '%s': %s", fullname, error->message);
+            {
+                error_msg("Error reading symlink '%s': %s", fullname, error->message);
+                goto next;
+            }
 
             gchar *target = g_path_get_basename(link);
-            char *ext = strrchr(target, '.');
+            VERB3 log("Symlink '%s' is pointing to '%s'", link, target);
+            if (ext_filter)
+            {
+                char *ext = strrchr(target, '.');
 
-//FIXME: why "xml"? Shouldn't it be ext_filter?
-            if (!ext || 0 != strcmp(ext + 1, "xml"))
-                error_msg_and_die("Invalid event symlink '%s': expected it to"
-                                  " point to another xml file", fullname);
-            *ext = '\0';
-            //@@TODO symlink handling is broken!!
-            //g_hash_table_replace(g_event_config_symlinks, xstrdup(dent->d_name), target);
+    //FIXME: why "xml"? Shouldn't it be ext_filter?
+                if (!ext || 0 != strcmp(ext + 1, ext_filter))
+                {
+                    error_msg("Invalid event symlink '%s': expected it to"
+                              " point to another '%s' file", fullname, ext_filter);
+                    goto next;
+                }
+                *ext = '\0';
+            }
+            free(fullname);
+            fullname = concat_path_file(path, target);
+            files = g_list_prepend(files, new_file_obj(fullname, target));
             g_free(link);
-            /* don't free target, it is owned by the hash table now */
+            g_free(target);
 
             goto next;
         }
diff --git a/src/lib/file_obj.c b/src/lib/file_obj.c
index 4aaffb8..bbb5b9f 100644
--- a/src/lib/file_obj.c
+++ b/src/lib/file_obj.c
@@ -36,3 +36,13 @@ void free_file_obj(file_obj_t *f)
     free(f->filename);
     free(f);
 }
+
+const char *fo_get_fullpath(file_obj_t *fo)
+{
+    return fo->fullpath;
+}
+
+const char *fo_get_filename(file_obj_t *fo)
+{
+    return fo->filename;
+}
\ No newline at end of file
-- 
1.8.3.1



More information about the Crash-catcher mailing list