Skip to contents

Deletes files sitting in the lake's data path that are not tracked in the DuckLake metadata at all – for example, leftovers from a crashed write.

Usage

delete_orphaned_files(
  ducklake_name = NULL,
  older_than = NULL,
  cleanup_all = FALSE,
  dry_run = FALSE
)

Arguments

ducklake_name

Name of the attached DuckLake catalog. If NULL, the current database is used.

older_than

Only delete files scheduled for deletion before this timestamp (POSIXct, converted to UTC, or character already in UTC). One of older_than or cleanup_all is required.

cleanup_all

If TRUE, delete all scheduled files regardless of when they were scheduled.

dry_run

If TRUE, only lists the files that would be deleted.

Value

A data frame listing the deleted (or deletable) files.

Details

This differs from cleanup_old_files(), which removes files that were tracked but are scheduled for deletion.

Always run with dry_run = TRUE first and check the file list. Anything in the data path that DuckLake does not recognise is fair game, and the comparison is by exact path string: a data path registered with an irregularity such as a doubled slash (as R's tempdir() produces on macOS) makes live files look orphaned, and deleting them breaks the lake.

Examples

lake_dir <- tempfile("orphan_lake_")
dir.create(lake_dir)
attach_ducklake("orphan_lake", lake_path = lake_dir)
create_table(mtcars, "cars")

# Always preview orphan deletion first
delete_orphaned_files(dry_run = TRUE, cleanup_all = TRUE)
#> Dry run: 0 orphaned file would be deleted.
#> [1] path
#> <0 rows> (or 0-length row.names)

detach_ducklake("orphan_lake", shutdown = TRUE)
unlink(lake_dir, recursive = TRUE)