private void cleanupPath(Instant deleteBefore, Path pathLocalDir) {
    LOG.info("Cleaning up files older than {} from {}", deleteBefore, pathLocalDir);

    try (Stream<Path> files = Files.walk(pathLocalDir)) {
      files.filter(f -> {
        try {
          FileTime modified = Files.getLastModifiedTime(f);
          LOG.debug("Checking: {}, modified: {}", f, modified);
          return Files.isRegularFile(f) && modified.toInstant().isBefore(deleteBefore);
        } catch (IOException ex) {
          LOG.warn("IOException caught while checking file for deletion", ex);
          return false;
        }
      }).forEach(f -> {
        try {
          LOG.info("Delete old local file: {}", f);
          Files.delete(f);
        } catch (IOException ex) {
          LOG.warn("Failed to delete file", ex);
        }
      });
    } catch (IOException e) {
      LOG.warn("IOException caught while walking over local files", e);
    }
  }
LocalDirCleaner is an LLAP daemon service to clean up old local files. Under normal circumstances,
intermediate/local files are cleaned up (typically at end of the DAG), but daemons crash sometimes,
and the attached local disk might end up being the same when a new daemon starts (this applies to
on-prem as well as cloud scenarios).
llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/LocalDirCleaner.java