Don't load plug-ins recursively by default
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 24 Feb 2016 22:30:06 +0000 (17:30 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 16:57:26 +0000 (12:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/plugin/component-factory.h
lib/plugin-system/component-factory.c

index 02414c2849056d85070b68ba5bccd6cd39a4abb7..c3190cb1f6df1efe4f11336c10606a4bdbb73098 100644 (file)
@@ -109,6 +109,19 @@ extern struct bt_component_class *bt_component_factory_get_component_class(
                const char *plugin_name, enum bt_component_type type,
                const char *component_name);
 
+/**
+ * Load and register Babeltrace plugins under a given path.
+ *
+ * Path will be traversed if it is a directory, otherwise only the provided file
+ * will be loaded.
+ *
+ * @param factory      A component factory instance
+ * @param path         A path to a file or directory
+ * @returns            One of #bt_component_factory_status values
+ */
+extern enum bt_component_factory_status bt_component_factory_load(
+               struct bt_component_factory *factory, const char *path);
+
 /**
  * Recursively load and register Babeltrace plugins under a given path.
  *
@@ -119,7 +132,7 @@ extern struct bt_component_class *bt_component_factory_get_component_class(
  * @param path         A path to a file or directory
  * @returns            One of #bt_component_factory_status values
  */
-extern enum bt_component_factory_status bt_component_factory_load(
+extern enum bt_component_factory_status bt_component_factory_load_recursive(
                struct bt_component_factory *factory, const char *path);
 
 extern enum bt_component_factory_status
index 65840d4cac79e883b6a025846d2405b099b3d9a2..6d76029170232457f515cbb730ee6d68ba86b1fc 100644 (file)
@@ -145,8 +145,8 @@ end:
 
 static
 enum bt_component_factory_status
-bt_component_factory_load_dir_recursive(struct bt_component_factory *factory,
-               const char *path)
+bt_component_factory_load_dir(struct bt_component_factory *factory,
+               const char *path, bool recurse)
 {
        DIR *directory = NULL;
        struct dirent *entry = NULL, *result = NULL;
@@ -211,9 +211,9 @@ bt_component_factory_load_dir_recursive(struct bt_component_factory *factory,
                        continue;
                }
 
-               if (S_ISDIR(st.st_mode)) {
-                       ret = bt_component_factory_load_dir_recursive(factory,
-                                       file_path);
+               if (S_ISDIR(st.st_mode) && recurse) {
+                       ret = bt_component_factory_load_dir(factory,
+                               file_path, true);
                        if (ret != BT_COMPONENT_FACTORY_STATUS_OK) {
                                goto end;
                        }
@@ -352,8 +352,10 @@ match:
        return bt_get(component_class);
 }
 
-enum bt_component_factory_status bt_component_factory_load(
-               struct bt_component_factory *factory, const char *path)
+static
+enum bt_component_factory_status _bt_component_factory_load(
+               struct bt_component_factory *factory, const char *path,
+               bool recursive)
 {
        enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK;
 
@@ -368,7 +370,7 @@ enum bt_component_factory_status bt_component_factory_load(
        }
 
        if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
-               ret = bt_component_factory_load_dir_recursive(factory, path);
+               ret = bt_component_factory_load_dir(factory, path, recursive);
        } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) ||
                        g_file_test(path, G_FILE_TEST_IS_SYMLINK)) {
                ret = bt_component_factory_load_file(factory, path);
@@ -380,6 +382,18 @@ end:
        return ret;
 }
 
+enum bt_component_factory_status bt_component_factory_load_recursive(
+               struct bt_component_factory *factory, const char *path)
+{
+       return _bt_component_factory_load(factory, path, true);
+}
+
+enum bt_component_factory_status bt_component_factory_load(
+               struct bt_component_factory *factory, const char *path)
+{
+       return _bt_component_factory_load(factory, path, false);
+}
+
 static
 enum bt_component_factory_status
 add_component_class(struct bt_component_factory *factory, const char *name,
This page took 0.027875 seconds and 4 git commands to generate.