- goto end;
- }
-
- /* Recursively walk directory */
- while (!readdir_r(directory, entry, &result) && result) {
- struct stat st;
- int stat_ret;
- size_t file_name_len;
-
- if (strcmp(result->d_name, ".") == 0 ||
- strcmp(result->d_name, "..") == 0) {
- continue;
- }
-
- if (result->d_name[0] == '.') {
- /* Skip hidden files, . and .. */
- BT_LOGV("Skipping hidden file: path=\"%s/%s\"",
- path, result->d_name);
- continue;
- }
-
- file_name_len = strlen(result->d_name);
-
- if (path_len + file_name_len >= PATH_MAX) {
- BT_LOGD("Skipping file because its path length is too large: continuing: "
- "path=\"%s/%s\", length=%zu",
- path, result->d_name,
- (size_t) (path_len + file_name_len));
- 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. */
- BT_LOGD("Cannot get file information: %s: continuing: "
- "path=\"%s\", errno=%d",
- strerror(errno), file_path, errno);
- continue;
- }
-
- if (S_ISDIR(st.st_mode) && recurse) {
- ret = bt_plugin_create_append_all_from_dir(plugin_set,
- file_path, BT_TRUE);
- if (ret < 0) {
- BT_LOGW("Cannot recurse into directory to find plugins: "
- "path=\"%s\", ret=%d", file_path, ret);
- 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_LOGD("Adding plugin to plugin set: "
- "plugin-path=\"%s\", plugin-addr=%p, plugin-name=\"%s\"",
- file_path, plugin,
- bt_plugin_get_name(plugin));
- bt_plugin_set_add_plugin(plugin_set,
- plugin);
- }
-
- bt_put(plugins_from_file);
- }
- }