common: index: remove redundant separator for empty channel string
[lttng-tools.git] / src / common / index / index.c
index 7c73dcfbd9e597def9249377348a462e6a86bd75..540294a5eae9f44e38328688e8f693567f8763b3 100644 (file)
@@ -51,6 +51,7 @@ static struct lttng_index_file *_lttng_index_file_create_from_trace_chunk(
        char index_file_path[LTTNG_PATH_MAX];
        const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
        const bool acquired_reference = lttng_trace_chunk_get(chunk);
+       const char *separator;
 
        assert(acquired_reference);
 
@@ -61,8 +62,13 @@ static struct lttng_index_file *_lttng_index_file_create_from_trace_chunk(
        }
 
        index_file->trace_chunk = chunk;
+       if (channel_path[0] == '\0') {
+               separator = "";
+       } else {
+               separator = "/";
+       }
        ret = snprintf(index_directory_path, sizeof(index_directory_path),
-                       "%s/" DEFAULT_INDEX_DIR, channel_path);
+                       "%s%s" DEFAULT_INDEX_DIR, channel_path, separator);
        if (ret < 0 || ret >= sizeof(index_directory_path)) {
                ERR("Failed to format index directory path");
                goto error;
@@ -151,6 +157,7 @@ error:
                        PERROR("Failed to close file descriptor of index file");
                }
        }
+       lttng_trace_chunk_put(chunk);
        free(index_file);
        return NULL;
 }
This page took 0.026115 seconds and 5 git commands to generate.