src.ctf.fs: manage lifetime of open file with FileUP
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 29 Jan 2024 16:58:13 +0000 (16:58 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Change-Id: Ic1c5d8be3761e449a154e1fd8cc1f0ec7c957197
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8173
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12269
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/query.cpp

index 05eae0c6ef93c572d44cfbcf6fb52f8366a7692a..95453ada5595eb4db7a10228bfcf95bc6135b10f 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <babeltrace2/babeltrace.h>
 
+#include "cpp-common/bt2c/libc-up.hpp"
+
 #include "../common/src/metadata/tsdl/decoder.hpp"
 #include "fs.hpp"
 #include "query.hpp"
@@ -32,7 +34,7 @@ bt_component_class_query_method_status metadata_info_query(const bt_value *param
     bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK;
     bt_value *result = NULL;
     const bt_value *path_value = NULL;
-    FILE *metadata_fp = NULL;
+    bt2c::FileUP metadata_fp;
     int ret;
     int bo;
     const char *path;
@@ -73,13 +75,13 @@ bt_component_class_query_method_status metadata_info_query(const bt_value *param
     path = bt_value_string_get(path_value);
 
     BT_ASSERT(path);
-    metadata_fp = ctf_fs_metadata_open_file(path, logger);
+    metadata_fp.reset(ctf_fs_metadata_open_file(path, logger));
     if (!metadata_fp) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot open trace metadata: path=\"{}\".", path);
         goto error;
     }
 
-    ret = ctf_metadata_decoder_is_packetized(metadata_fp, &is_packetized, &bo, logger);
+    ret = ctf_metadata_decoder_is_packetized(metadata_fp.get(), &is_packetized, &bo, logger);
     if (ret) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(
             logger, "Cannot check whether or not the metadata stream is packetized: path=\"{}\".",
@@ -94,8 +96,8 @@ bt_component_class_query_method_status metadata_info_query(const bt_value *param
         goto error;
     }
 
-    rewind(metadata_fp);
-    decoder_status = ctf_metadata_decoder_append_content(decoder, metadata_fp);
+    rewind(metadata_fp.get());
+    decoder_status = ctf_metadata_decoder_append_content(decoder, metadata_fp.get());
     if (decoder_status) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(
             logger, "Cannot update metadata decoder's content: path=\"{}\".", path);
@@ -145,14 +147,6 @@ end:
     }
     ctf_metadata_decoder_destroy(decoder);
 
-    if (metadata_fp) {
-        ret = fclose(metadata_fp);
-        if (ret) {
-            BT_CPPLOGE_ERRNO_SPEC(logger, "Cannot close metadata file stream", ": path=\"{}\"",
-                                  path);
-        }
-    }
-
     *user_result = result;
     return status;
 }
This page took 0.0253 seconds and 4 git commands to generate.