+/*
+ * Create a non-empty folder hierarchy from a directory handle:
+ *
+ * test_root_name
+ * └── a
+ * └── b
+ * ├── c
+ * │ └── d
+ * └── e
+ * ├── f
+ * └── file1
+ */
+static int create_non_empty_hierarchy_with_root(
+ struct lttng_directory_handle *test_dir_handle,
+ const char *test_root_name)
+{
+ int ret;
+ const int file_flags = O_WRONLY | O_CREAT | O_TRUNC;
+ const mode_t file_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
+ char *branch_name = NULL;
+
+ ret = asprintf(&branch_name, "%s/%s", test_root_name, "a/b/c/d");
+ if (ret < 0) {
+ diag("Failed to format folder path");
+ goto end;
+ }
+ ret = lttng_directory_handle_create_subdirectory_recursive(
+ test_dir_handle,
+ branch_name,
+ DIR_CREATION_MODE);
+ if (ret) {
+ diag("Failed to create test folder hierarchy %s", branch_name);
+ goto end;
+ }
+
+ free(branch_name);
+ ret = asprintf(&branch_name, "%s/%s", test_root_name, "a/b/e/f");
+ if (ret < 0) {
+ diag("Failed to format folder path");
+ goto end;
+ }
+ ret = lttng_directory_handle_create_subdirectory_recursive(
+ test_dir_handle,
+ branch_name,
+ DIR_CREATION_MODE);
+ if (ret) {
+ diag("Failed to create test folder hierarchy %s", branch_name);
+ goto end;
+ }
+
+ free(branch_name);
+ ret = asprintf(&branch_name, "%s/%s", test_root_name, "a/b/e/file1");
+ if (ret < 0) {
+ diag("Failed to format file path");
+ goto end;
+ }
+ ret = lttng_directory_handle_open_file(
+ test_dir_handle, branch_name, file_flags, file_mode);
+ if (ret < 0) {
+ diag("Failed to create file %s", branch_name);
+ goto end;
+ }
+ ret = close(ret);
+ if (ret) {
+ PERROR("Failed to close fd to newly created file %s",
+ branch_name);
+ goto end;
+ }
+end:
+ free(branch_name);
+ return ret;
+}
+
+/* Remove "file1" from the test folder hierarchy. */
+int remove_file_from_hierarchy(struct lttng_directory_handle *test_dir_handle,
+ const char *test_root_name)