src.ctf.fs: make ctf_fs_file::path an std::string
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 5 Dec 2023 03:35:00 +0000 (03:35 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Change-Id: Ifbe7cd2c184031465428c28701131a82ba219b02
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8265
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12303
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/data-stream-file.cpp
src/plugins/ctf/fs-src/file.cpp
src/plugins/ctf/fs-src/file.hpp
src/plugins/ctf/fs-src/fs.cpp
src/plugins/ctf/fs-src/metadata.cpp

index dd725ee75ada2d8f21a67e983f67997c5ba1379f..e73f28f3729298fcf8885d722fcc49f09e3a0496 100644 (file)
@@ -52,7 +52,7 @@ static enum ctf_msg_iter_medium_status ds_file_munmap(struct ctf_fs_ds_file *ds_
         BT_CPPLOGE_ERRNO_SPEC(ds_file->logger, "Cannot memory-unmap file",
                               ": address={}, size={}, file_path=\"{}\", file={}",
                               fmt::ptr(ds_file->mmap_addr), ds_file->mmap_len,
-                              ds_file->file ? ds_file->file->path->str : "NULL",
+                              ds_file->file ? ds_file->file->path : "NULL",
                               ds_file->file ? fmt::ptr(ds_file->file->fp) : NULL);
         status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
         goto end;
@@ -121,7 +121,7 @@ static enum ctf_msg_iter_medium_status ds_file_mmap(struct ctf_fs_ds_file *ds_fi
     if (ds_file->mmap_addr == MAP_FAILED) {
         BT_CPPLOGE_SPEC(ds_file->logger,
                         "Cannot memory-map address (size {}) of file \"{}\" ({}) at offset {}: {}",
-                        ds_file->mmap_len, ds_file->file->path->str, fmt::ptr(ds_file->file->fp),
+                        ds_file->mmap_len, ds_file->file->path, fmt::ptr(ds_file->file->fp),
                         (intmax_t) ds_file->mmap_offset_in_file, strerror(errno));
         status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
         goto end;
@@ -184,8 +184,8 @@ static enum ctf_msg_iter_medium_status medop_request_bytes(size_t request_sz, ui
     if (remaining_mmap_bytes(ds_file) == 0) {
         /* Are we at the end of the file? */
         if (ds_file->mmap_offset_in_file >= ds_file->file->size) {
-            BT_CPPLOGD_SPEC(ds_file->logger, "Reached end of file \"{}\" ({})",
-                            ds_file->file->path->str, fmt::ptr(ds_file->file->fp));
+            BT_CPPLOGD_SPEC(ds_file->logger, "Reached end of file \"{}\" ({})", ds_file->file->path,
+                            fmt::ptr(ds_file->file->fp));
             status = CTF_MSG_ITER_MEDIUM_STATUS_EOF;
             goto end;
         }
@@ -198,7 +198,7 @@ static enum ctf_msg_iter_medium_status medop_request_bytes(size_t request_sz, ui
             goto end;
         default:
             BT_CPPLOGE_SPEC(ds_file->logger, "Cannot memory-map next region of file \"{}\" ({})",
-                            ds_file->file->path->str, fmt::ptr(ds_file->file->fp));
+                            ds_file->file->path, fmt::ptr(ds_file->file->fp));
             goto error;
         }
     }
@@ -322,7 +322,7 @@ ctf_fs_ds_group_medops_set_file(struct ctf_fs_ds_group_medops_data *data,
     BT_ASSERT(index_entry);
 
     /* Check if that file is already the one mapped. */
-    if (!data->file || strcmp(index_entry->path, data->file->file->path->str) != 0) {
+    if (!data->file || data->file->file->path != index_entry->path) {
         /* Destroy the previously used file. */
         ctf_fs_ds_file_destroy(data->file);
 
@@ -479,7 +479,7 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
     uint32_t version_major, version_minor;
 
     BT_CPPLOGI_SPEC(ds_file->logger, "Building index from .idx file of stream file {}",
-                    ds_file->file->path->str);
+                    ds_file->file->path);
     ret = ctf_msg_iter_get_packet_properties(msg_iter, &props);
     if (ret) {
         BT_CPPLOGI_STR_SPEC(ds_file->logger,
@@ -495,17 +495,17 @@ static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_f
     }
 
     /* Look for index file in relative path index/name.idx. */
-    basename = g_path_get_basename(ds_file->file->path->str);
+    basename = g_path_get_basename(ds_file->file->path.c_str());
     if (!basename) {
         BT_CPPLOGE_SPEC(ds_file->logger, "Cannot get the basename of datastream file {}",
-                        ds_file->file->path->str);
+                        ds_file->file->path);
         goto error;
     }
 
-    directory = g_path_get_dirname(ds_file->file->path->str);
+    directory = g_path_get_dirname(ds_file->file->path.c_str());
     if (!directory) {
         BT_CPPLOGE_SPEC(ds_file->logger, "Cannot get dirname of datastream file {}",
-                        ds_file->file->path->str);
+                        ds_file->file->path);
         goto error;
     }
 
@@ -730,7 +730,7 @@ static ctf_fs_ds_index::UP build_index_from_stream_file(struct ctf_fs_ds_file *d
     enum ctf_msg_iter_status iter_status = CTF_MSG_ITER_STATUS_OK;
     auto currentPacketOffset = bt2c::DataLen::fromBytes(0);
 
-    BT_CPPLOGI_SPEC(ds_file->logger, "Indexing stream file {}", ds_file->file->path->str);
+    BT_CPPLOGI_SPEC(ds_file->logger, "Indexing stream file {}", ds_file->file->path);
 
     index = ctf_fs_ds_index_create();
     if (!index) {
@@ -773,7 +773,7 @@ static ctf_fs_ds_index::UP build_index_from_stream_file(struct ctf_fs_ds_file *d
                             "Invalid packet size reported in file: stream=\"{}\", "
                             "packet-offset-bytes={}, packet-size-bytes={}, "
                             "file-size-bytes={}",
-                            ds_file->file->path->str, currentPacketOffset.bytes(),
+                            ds_file->file->path, currentPacketOffset.bytes(),
                             currentPacketSize.bytes(), ds_file->file->size);
             goto error;
         }
@@ -830,7 +830,7 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
 
     ds_file->stream = std::move(stream);
     ds_file->metadata = ctf_fs_trace->metadata;
-    g_string_assign(ds_file->file->path, path);
+    ds_file->file->path = path;
     ret = ctf_fs_file_open(ds_file->file.get(), "rb");
     if (ret) {
         goto error;
index 33399d94fbeaee99347d53fb8c12a489c2da46e2..e3f7d7783c1c872ff5b52b30c40df97ad9a85c43 100644 (file)
@@ -18,10 +18,6 @@ void ctf_fs_file_destroy(struct ctf_fs_file *file)
         return;
     }
 
-    if (file->path) {
-        g_string_free(file->path, TRUE);
-    }
-
     delete file;
 }
 
@@ -32,20 +28,7 @@ void ctf_fs_file_deleter::operator()(ctf_fs_file * const file) noexcept
 
 ctf_fs_file::UP ctf_fs_file_create(const bt2c::Logger& parentLogger)
 {
-    ctf_fs_file::UP file {new ctf_fs_file {parentLogger}};
-
-    file->path = g_string_new(NULL);
-    if (!file->path) {
-        goto error;
-    }
-
-    goto end;
-
-error:
-    file.reset();
-
-end:
-    return file;
+    return ctf_fs_file::UP {new ctf_fs_file {parentLogger}};
 }
 
 int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
@@ -53,11 +36,11 @@ int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
     int ret = 0;
     struct stat stat;
 
-    BT_CPPLOGI_SPEC(file->logger, "Opening file \"{}\" with mode \"{}\"", file->path->str, mode);
-    file->fp.reset(fopen(file->path->str, mode));
+    BT_CPPLOGI_SPEC(file->logger, "Opening file \"{}\" with mode \"{}\"", file->path, mode);
+    file->fp.reset(fopen(file->path.c_str(), mode));
     if (!file->fp) {
         BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot open file", ": path={}, mode={}",
-                                           file->path->str, mode);
+                                           file->path, mode);
         goto error;
     }
 
@@ -65,7 +48,7 @@ int ctf_fs_file_open(struct ctf_fs_file *file, const char *mode)
 
     if (fstat(fileno(file->fp.get()), &stat)) {
         BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(file->logger, "Cannot get file information", ": path={}",
-                                           file->path->str);
+                                           file->path);
         goto error;
     }
 
index 33fa10d882f6fb4909acb9091c59ae8cefb6231a..5f0ca39570ec32d3689d8c6438fe4b9cfb236f6c 100644 (file)
@@ -8,6 +8,7 @@
 #define CTF_FS_FILE_H
 
 #include <memory>
+#include <string>
 
 #include <babeltrace2/babeltrace.h>
 
@@ -30,8 +31,7 @@ struct ctf_fs_file
 
     bt2c::Logger logger;
 
-    /* Owned by this */
-    GString *path = nullptr;
+    std::string path;
 
     bt2c::FileUP fp;
 
index c4428431b290d2b01b41983d295722a0aed834c2..272e98d51732abd5c5aa6e0b1b21edaab645906b 100644 (file)
@@ -575,7 +575,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;
     }
 
@@ -692,32 +692,31 @@ 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);
+        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.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);
+            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);
+                                         file->path);
             goto error;
         }
     }
index 842b3eb749834df460e33ce74860b1d47bc3db29..ec60a6a409877ce6ccfbc6a0b73054a7fd82a1d7 100644 (file)
@@ -43,8 +43,7 @@ static ctf_fs_file::UP get_file(const char *trace_path, const bt2c::Logger& logg
         goto error;
     }
 
-    g_string_append(file->path, trace_path);
-    g_string_append(file->path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME);
+    file->path = fmt::format("{}" G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME, trace_path);
 
     if (ctf_fs_file_open(file.get(), "rb")) {
         goto error;
This page took 0.030059 seconds and 4 git commands to generate.