code: public void clean(final FileSystemDatasetVersion versionToDelete, final Set<Path> possiblyEmptyDirectories) throws IOException {
      log.info("Deleting dataset version " + versionToDelete);
  
      Set<Path> pathsToDelete = versionToDelete.getPaths();
      log.info("Deleting paths: " + Arrays.toString(pathsToDelete.toArray()));
  
      boolean deletedAllPaths = true;
  
      for (Path path : pathsToDelete) {
  
        if (!this.fs.exists(path)) {
          log.info(String.format("Path %s in dataset version %s does not exist", path, versionToDelete));
          continue;
        }
  
        boolean successfullyDeleted = deleteAsOwner ? trash.moveToTrashAsOwner(path) : trash.moveToTrash(path);
  
        if (successfullyDeleted) {
          possiblyEmptyDirectories.add(path.getParent());
        } else {
          log.error("Failed to delete path " + path + " in dataset version " + versionToDelete);
          deletedAllPaths = false;
        }
      }
  
      if (!deletedAllPaths) {
        log.error("Failed to delete some paths in dataset version " + versionToDelete);
      }
    }
docs: Delete a single {@link FileSystemDatasetVersion}. All the parent {@link Path}s are after deletion, are
  added to <code>possiblyEmptyDirectories</code>. Caller need to call {@link #cleanEmptyDirectories(Set, FileSystemDataset)}
  to delete empty parent directories if any.