Skip to content

Commit

Permalink
speed up file system checking
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Sep 6, 2024
1 parent 15dc793 commit 8e0390b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
8 changes: 6 additions & 2 deletions R/class_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ file_hash <- function(files) {
hash_object(paste(hash, collapse = ""))
}

file_info <- function(files) {
file_info <- function(files, trust_timestamps = NULL) {
out <- file.info(files, extra_cols = FALSE)
out$mtime_numeric <- file_time_numeric(out$mtime)
out$trust_timestamps <- trust_timestamps(files)
if (is.null(trust_timestamps)) {
out$trust_timestamps <- trust_timestamps(files)
} else {
out$trust_timestamps <- rep(trust_timestamps, nrow(out))
}
out
}

Expand Down
16 changes: 13 additions & 3 deletions R/class_runtime.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ runtime_new <- function(
inventories = NULL,
traceback = NULL,
pid_parent = NULL,
file_systems = NULL
file_systems = NULL,
trust_timestamps_store = NULL
) {
force(target)
force(frames)
Expand All @@ -32,6 +33,7 @@ runtime_new <- function(
force(traceback)
force(pid_parent)
force(file_systems)
force(trust_timestamps_store)
environment()
}

Expand Down Expand Up @@ -109,18 +111,26 @@ runtime_validate_extras <- function(x) {
if (!is.null(x$file_systems)) {
tar_assert_chr(x$file_systems)
}
if (!is.null(x$trust_timestamps_store)) {
tar_assert_lgl(x$trust_timestamps_store)
}
}

runtime_set_file_info <- function(runtime, store) {
runtime$trust_timestamps_store <- trust_timestamps(store)
objects <- list.files(
path = path_objects_dir(store),
all.files = TRUE,
full.names = TRUE,
no.. = TRUE
)
runtime$file_systems <- runtime_file_systems()
columns <- c("size", "mtime_numeric", "trust_timestamps")
file_info <- as.list(file_info(objects)[, columns])
file_info <- file_info(objects, trust_timestamps = FALSE)
file_info <- as.list(file_info[, c("size", "mtime_numeric")])
file_info$trust_timestamps <- rep(
runtime$trust_timestamps_store,
length(objects)
)
names(file_info$size) <- objects
names(file_info$mtime_numeric) <- objects
names(file_info$trust_timestamps) <- objects
Expand Down
7 changes: 6 additions & 1 deletion R/utils_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ file_copy <- function(from, to) {
}

trust_timestamps <- function(path) {
store <- .subset2(tar_runtime, "store")
grandparent <- unique(dirname(dirname(path)))
if (identical(store, grandparent)) {
return(rep(TRUE, length(path)))
}
trust <- rep(FALSE, length(path))
exists <- file.exists(path)
exists <- file_exists_runtime(path)
unsafe <- c(
"adfs",
"bfs",
Expand Down

0 comments on commit 8e0390b

Please sign in to comment.