- /* Recursively walk directory */
- while (!readdir_r(directory, entry, &result) && result) {
- struct stat st;
- int stat_ret;
- size_t file_name_len;
-
- if (result->d_name[0] == '.') {
- /* Skip hidden files, . and .. */
- continue;
- }
-
- file_name_len = strlen(result->d_name);
-
- if (path_len + file_name_len >= PATH_MAX) {
- continue;
- }
-
- strncpy(file_path + path_len, result->d_name, file_name_len);
- file_path[path_len + file_name_len] = '\0';
- stat_ret = stat(file_path, &st);
- if (stat_ret < 0) {
- /* Continue to next file / directory. */
- printf_perror("Failed to stat() plugin file\n");
- continue;
- }
-
- if (S_ISDIR(st.st_mode) && recurse) {
- ret = bt_plugin_create_append_all_from_dir(plugin_set,
- file_path, true);
- if (ret < 0) {
- goto end;
- }
- } else if (S_ISREG(st.st_mode)) {
- struct bt_plugin_set *plugins_from_file =
- bt_plugin_create_all_from_file(file_path);
-
- if (plugins_from_file) {
- size_t j;
-
- for (j = 0; j < plugins_from_file->plugins->len; j++) {
- struct bt_plugin *plugin =
- g_ptr_array_index(plugins_from_file->plugins, j);
-
- bt_plugin_set_add_plugin(plugin_set,
- plugin);
- }
-
- bt_put(plugins_from_file);
- }
- }
- }
-end:
- if (directory) {
- if (closedir(directory)) {
- /*
- * We don't want to override the error since there is
- * nothing could do.
- */
- perror("Failed to close plug-in directory");
- }
- }
- free(entry);
- free(file_path);