src.ctf.fs: make ctf_fs_ds_file_create return a unique_ptr
[babeltrace.git] / src / plugins / ctf / fs-src / fs.cpp
index 8bdc1e0c323310e7b73f667cbcdbbade39494d56..1b76a79fa600e9cdfd23c530111726d59da23e64 100644 (file)
@@ -524,7 +524,8 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
      * stream file.
      */
     ds_file =
-        ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, path, ctf_fs_trace->logger);
+        ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, path, ctf_fs_trace->logger)
+            .release();
     if (!ds_file) {
         goto error;
     }
@@ -575,7 +576,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
     index = ctf_fs_ds_file_build_index(ds_file, ds_file_info.get(), msg_iter);
     if (!index) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to index CTF stream file \'{}\'",
-                                     ds_file->file->path->str);
+                                     ds_file->file->path);
         goto error;
     }
 
@@ -640,7 +641,7 @@ error:
     ret = -1;
 
 end:
-    ctf_fs_ds_file_destroy(ds_file);
+    delete ds_file;
 
     if (msg_iter) {
         ctf_msg_iter_destroy(msg_iter);
@@ -666,8 +667,6 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
     }
 
     while ((basename = g_dir_read_name(dir))) {
-        struct ctf_fs_file *file;
-
         if (strcmp(basename, CTF_FS_METADATA_FILENAME) == 0) {
             /* Ignore the metadata stream. */
             BT_CPPLOGI_SPEC(ctf_fs_trace->logger,
@@ -684,7 +683,7 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
         }
 
         /* Create the file. */
-        file = ctf_fs_file_create(ctf_fs_trace->logger).release();
+        const auto file = ctf_fs_file_create(ctf_fs_trace->logger);
         if (!file) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(
                 ctf_fs_trace->logger,
@@ -694,40 +693,33 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
         }
 
         /* 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_CPPLOGI_SPEC(ctf_fs_trace->logger, "Ignoring non-regular file `{}`",
-                            file->path->str);
-            ctf_fs_file_destroy(file);
-            file = NULL;
+        file->path = fmt::format("{}" G_DIR_SEPARATOR_S "{}", ctf_fs_trace->path->str, basename);
+
+        if (!g_file_test(file->path.c_str(), G_FILE_TEST_IS_REGULAR)) {
+            BT_CPPLOGI_SPEC(ctf_fs_trace->logger, "Ignoring non-regular file `{}`", file->path);
             continue;
         }
 
-        ret = ctf_fs_file_open(file, "rb");
+        ret = ctf_fs_file_open(file.get(), "rb");
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Cannot open stream file `{}`",
-                                         file->path->str);
+                                         file->path);
             goto error;
         }
 
         if (file->size == 0) {
             /* Skip empty stream. */
-            BT_CPPLOGI_SPEC(ctf_fs_trace->logger, "Ignoring empty file `{}`", file->path->str);
-            ctf_fs_file_destroy(file);
+            BT_CPPLOGI_SPEC(ctf_fs_trace->logger, "Ignoring empty file `{}`", file->path);
             continue;
         }
 
-        ret = add_ds_file_to_ds_file_group(ctf_fs_trace, file->path->str);
+        ret = add_ds_file_to_ds_file_group(ctf_fs_trace, file->path.c_str());
         if (ret) {
             BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger,
                                          "Cannot add stream file `{}` to stream file group",
-                                         file->path->str);
-            ctf_fs_file_destroy(file);
+                                         file->path);
             goto error;
         }
-
-        ctf_fs_file_destroy(file);
     }
 
     goto end;
@@ -1137,7 +1129,8 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
     BT_ASSERT(index_entry->path);
 
     ds_file = ctf_fs_ds_file_create(ctf_fs_trace, bt2::Stream::Shared {}, index_entry->path,
-                                    ctf_fs_trace->logger);
+                                    ctf_fs_trace->logger)
+                  .release();
     if (!ds_file) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to create a ctf_fs_ds_file");
         ret = -1;
@@ -1202,9 +1195,8 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
     }
 
 end:
-    if (ds_file) {
-        ctf_fs_ds_file_destroy(ds_file);
-    }
+    delete ds_file;
+
     if (msg_iter) {
         ctf_msg_iter_destroy(msg_iter);
     }
This page took 0.023947 seconds and 4 git commands to generate.