index common code: introduce lttng_index_file_unlink
[lttng-tools.git] / src / common / index / index.c
index 9bfb56fa0b7a6a3c9c475e028473c297a9e5779a..07d2cf3c01ed9bd9c2798fd16be595e9a14f1675 100644 (file)
@@ -78,11 +78,15 @@ struct lttng_index_file *lttng_index_file_create(char *path_name,
         */
        ret = utils_unlink_stream_file(fullpath, stream_name, size, count, uid,
                        gid, DEFAULT_INDEX_FILE_SUFFIX);
+       DBG("utils_unlink_stream_file %s %s ret %d errno %d",
+                       fullpath, stream_name, ret, errno);
        if (ret < 0 && errno != ENOENT) {
                goto error;
        }
        ret = utils_create_stream_file(fullpath, stream_name, size, count, uid,
                        gid, DEFAULT_INDEX_FILE_SUFFIX);
+       DBG("utils_create_stream_file %s %s ret %d errno %d",
+                       fullpath, stream_name, ret, errno);
        if (ret < 0) {
                goto error;
        }
@@ -119,6 +123,34 @@ error:
        return NULL;
 }
 
+int lttng_index_file_unlink(char *path_name,
+               char *stream_name, int uid, int gid,
+               uint64_t tracefile_size,
+               uint64_t tracefile_count_current)
+{
+       int ret;
+       char fullpath[PATH_MAX];
+
+       ret = snprintf(fullpath, sizeof(fullpath), "%s/" DEFAULT_INDEX_DIR,
+                       path_name);
+       if (ret < 0) {
+               PERROR("snprintf index path");
+               goto error;
+       }
+
+       ret = utils_unlink_stream_file(fullpath, stream_name,
+                       tracefile_size, tracefile_count_current, uid,
+                       gid, DEFAULT_INDEX_FILE_SUFFIX);
+       if (ret < 0 && errno != ENOENT) {
+               goto error;
+       }
+
+       return 0;
+
+error:
+       return -1;
+}
+
 /*
  * Write index values to the given index file.
  *
This page took 0.024148 seconds and 5 git commands to generate.