static struct ctf_fs_file *get_file(const char *trace_path) { struct ctf_fs_file *file = ctf_fs_file_create(); if (!file) { goto error; } g_string_append(file->path, trace_path); g_string_append(file->path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME); if (ctf_fs_file_open(file, "rb")) { goto error; } goto end; error: if (file) { ctf_fs_file_destroy(file); file = NULL; } end: return file; }
static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) { int ret = 0; const char *basename; GError *error = NULL; GDir *dir = NULL; /* Check each file in the path directory, except specific ones */ dir = g_dir_open(ctf_fs_trace->path->str, 0, &error); if (!dir) { BT_LOGE("Cannot open directory `%s`: %s (code %d)", ctf_fs_trace->path->str, error->message, error->code); goto error; } while ((basename = g_dir_read_name(dir))) { struct ctf_fs_file *file; if (!strcmp(basename, CTF_FS_METADATA_FILENAME)) { /* Ignore the metadata stream. */ BT_LOGD("Ignoring metadata file `%s" G_DIR_SEPARATOR_S "%s`", ctf_fs_trace->path->str, basename); continue; } if (basename[0] == '.') { BT_LOGD("Ignoring hidden file `%s" G_DIR_SEPARATOR_S "%s`", ctf_fs_trace->path->str, basename); continue; } /* Create the file. */ file = ctf_fs_file_create(); if (!file) { BT_LOGE("Cannot create stream file object for file `%s" G_DIR_SEPARATOR_S "%s`", ctf_fs_trace->path->str, basename); goto error; } /* Create full path string. */ g_string_append_printf(file->path, "%s" G_DIR_SEPARATOR_S "%s", ctf_fs_trace->path->str, basename); if (!g_file_test(file->path->str, G_FILE_TEST_IS_REGULAR)) { BT_LOGD("Ignoring non-regular file `%s`", file->path->str); ctf_fs_file_destroy(file); file = NULL; continue; } ret = ctf_fs_file_open(file, "rb"); if (ret) { BT_LOGE("Cannot open stream file `%s`", file->path->str); goto error; } if (file->size == 0) { /* Skip empty stream. */ BT_LOGD("Ignoring empty file `%s`", file->path->str); ctf_fs_file_destroy(file); continue; } ret = add_ds_file_to_ds_file_group(ctf_fs_trace, file->path->str); if (ret) { BT_LOGE("Cannot add stream file `%s` to stream file group", file->path->str); ctf_fs_file_destroy(file); goto error; } ctf_fs_file_destroy(file); } goto end; error: ret = -1; end: if (dir) { g_dir_close(dir); dir = NULL; } if (error) { g_error_free(error); } return ret; }