+ 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. */
+static int remove_file_from_hierarchy(
+ struct lttng_directory_handle *test_dir_handle,
+ const char *test_root_name)
+{
+ int ret;
+ char *file_name = NULL;
+
+ ret = asprintf(&file_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_unlink_file(test_dir_handle,
+ file_name);
+ if (ret) {
+ PERROR("Failed to unlink file %s", file_name);
+ goto end;
+ }
+end:
+ free(file_name);
+ return ret;
+}
+
+static int test_rmdir_fail_non_empty(const char *test_dir)
+{
+ int ret, tests_ran = 0;
+ struct lttng_directory_handle *test_dir_handle;