Skip to content

Commit

Permalink
use ps_fs_mount_point() and ps_disk_partitions()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Sep 6, 2024
1 parent da90f3e commit 15dc793
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ importFrom(igraph,topo_sort)
importFrom(knitr,engine_output)
importFrom(knitr,knit_engines)
importFrom(ps,ps_create_time)
importFrom(ps,ps_disk_partitions)
importFrom(ps,ps_fs_mount_point)
importFrom(ps,ps_handle)
importFrom(rlang,abort)
importFrom(rlang,as_function)
Expand Down
22 changes: 16 additions & 6 deletions R/class_runtime.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ runtime_new <- function(
nanonext = NULL,
inventories = NULL,
traceback = NULL,
pid_parent = NULL
pid_parent = NULL,
file_systems = NULL
) {
force(target)
force(frames)
Expand All @@ -30,6 +31,7 @@ runtime_new <- function(
force(inventories)
force(traceback)
force(pid_parent)
force(file_systems)
environment()
}

Expand Down Expand Up @@ -104,6 +106,9 @@ runtime_validate_extras <- function(x) {
tar_assert_none_na(x$pid_parent)
tar_assert_ge(x$pid_parent, 0L)
}
if (!is.null(x$file_systems)) {
tar_assert_chr(x$file_systems)
}
}

runtime_set_file_info <- function(runtime, store) {
Expand All @@ -113,11 +118,9 @@ runtime_set_file_info <- function(runtime, store) {
full.names = TRUE,
no.. = TRUE
)
file_info <- as.list(file_info(objects)[, c("size", "mtime_numeric")])
file_info$trust_timestamps <- rep(
trust_timestamps(path_objects_dir(store)),
length(objects)
)
runtime$file_systems <- runtime_file_systems()
columns <- c("size", "mtime_numeric", "trust_timestamps")
file_info <- as.list(file_info(objects)[, columns])
names(file_info$size) <- objects
names(file_info$mtime_numeric) <- objects
names(file_info$trust_timestamps) <- objects
Expand All @@ -126,6 +129,13 @@ runtime_set_file_info <- function(runtime, store) {
runtime$file_info_exist <- tar_counter(names = objects)
}

runtime_file_systems <- function() {
info <- ps::ps_disk_partitions()
out <- .subset2(info, "fstype")
names(out) <- .subset2(info, "mountpoint")
out
}

runtime_reset <- function(x) {
for (field in names(x)) {
x[[field]] <- NULL
Expand Down
3 changes: 2 additions & 1 deletion R/tar_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#' graph_from_data_frame igraph_opt igraph_options is_dag simplify topo_sort
#' V
#' @importFrom knitr engine_output knit_engines
#' @importFrom ps ps_create_time ps_handle
#' @importFrom ps ps_create_time ps_disk_partitions ps_fs_mount_point
#' ps_handle
#' @importFrom R6 R6Class
#' @importFrom rlang abort as_function check_installed enquo inform
#' is_installed quo_squash warn
Expand Down
15 changes: 11 additions & 4 deletions R/utils_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ file_copy <- function(from, to) {
}

trust_timestamps <- function(path) {
out <- rep(FALSE, length(path))
trust <- rep(FALSE, length(path))
exists <- file.exists(path)
unsafe <- c(
"adfs",
Expand All @@ -98,8 +98,15 @@ trust_timestamps <- function(path) {
"tux3"
)
if (any(exists)) {
types <- tolower(ps::ps_fs_info(path = path[exists])$type)
out[exists] <- !(types %in% unsafe)
existing <- path[exists]
file_systems <- .subset2(tar_runtime, "file_systems")
if (is.null(file_systems)) {
file_systems <- runtime_file_systems()
tar_runtime$file_systems <- file_systems
}
mounts <- ps::ps_fs_mount_point(existing)
types <- as.character(file_systems[mounts])
trust[exists] <- !(types %in% unsafe)
}
out
trust
}

0 comments on commit 15dc793

Please sign in to comment.