- /* Not empty, abort. */
- DBG("Directory \"%s\" is not empty; refusing to remove directory",
- current_path.data);
- ret = -1;
- goto end;
+ if (flags & LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG) {
+ current_frame->empty = false;
+ break;
+ } else {
+ /* Not empty, abort. */
+ DBG("Directory \"%s\" is not empty; refusing to remove directory",
+ current_path.data);
+ ret = -1;
+ goto end;
+ }
+ } else {
+ struct rmdir_frame new_frame = {
+ .path_size = current_path.size,
+ .dir = lttng_directory_handle_opendir(
+ handle,
+ current_path.data),
+ .empty = true,
+ .parent_frame_idx = current_frame_idx,
+ };
+
+ if (!new_frame.dir) {
+ if (flags & LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG &&
+ errno == ENOENT) {
+ DBG("Non-existing directory stream during recursive directory removal");
+ break;
+ } else {
+ PERROR("Failed to open directory stream during recursive directory removal");
+ ret = -1;
+ goto end;
+ }
+ }
+ ret = lttng_dynamic_array_add_element(
+ &frames, &new_frame);
+ if (ret) {
+ ERR("Failed to push context frame during recursive directory removal");
+ rmdir_frame_fini(&new_frame);
+ goto end;
+ }
+ current_frame_idx++;
+ /* We break iteration on readdir. */
+ break;