Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into znk/fix-broken-gith…
Browse files Browse the repository at this point in the history
…ub-urls
  • Loading branch information
richfitz committed Aug 14, 2024
2 parents 3e93979 + 534c743 commit 432dc8e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion R/location_path.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ orderly_location_path <- R6::R6Class(
stop(sprintf("Hash '%s' not found at location", hash))
}
}
fs::file_copy(path, dest, overwrite = TRUE)
copy_files(path, dest, overwrite = TRUE)
dest
},

Expand Down
5 changes: 3 additions & 2 deletions R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ orderly_resource <- function(files) {
files_expanded <- expand_dirs(files, src)
if (!is.null(p)) {
if (p$orderly2$strict$enabled) {
copy_files(src, p$path, files_expanded)
copy_files(file.path(src, files_expanded),
file.path(p$path, files_expanded))
} else {
## Above we're looking in the underlying source directory, here
## we're looking within the running directory; it's not obvious
Expand Down Expand Up @@ -408,7 +409,7 @@ copy_shared_resource <- function(path_root, path_dest, config, files, call) {
there <- replace_ragged(there, is_dir, Map(file.path, there[is_dir], files))
}
if (any(!is_dir)) {
fs::file_copy(src[!is_dir], dst[!is_dir], overwrite = TRUE)
copy_files(src[!is_dir], dst[!is_dir], overwrite = TRUE)
}

data_frame(here = here, there = there)
Expand Down
16 changes: 9 additions & 7 deletions R/outpack_root.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ file_export <- function(root, id, there, here, dest, overwrite, call = NULL) {
call = call)
})
}
fs::file_copy(there_full, here_full, overwrite)
}

# Files in the archive and file store are (generally) read-only.
# When exporting for interactive use, it's easier on the user if we make them
# writable again.
fs::file_chmod(here_full, "u+w")
# Set copy_mode = FALSE: files in the archive are read-only. It's easier on
# the user if we make them writable again.
copy_files(there_full, here_full, overwrite = overwrite, copy_mode = FALSE)
}
}


Expand Down Expand Up @@ -109,8 +107,12 @@ file_import_archive <- function(root, path, file_path, name, id) {
## store version, but not of orderly.
file_path_dest <- file.path(dest, file_path)
fs::dir_create(dirname(file_path_dest))

## overwrite = FALSE; see assertion above
fs::file_copy(file.path(path, file_path), file_path_dest, overwrite = FALSE)
copy_files(file.path(path, file_path),
file_path_dest,
overwrite = FALSE)

if (length(file_path_dest) > 0) {
fs::file_chmod(file_path_dest, "a-w")
}
Expand Down
8 changes: 6 additions & 2 deletions R/outpack_store.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ file_store <- R6::R6Class(
stop(not_found_error(message, missing))
}
fs::dir_create(dirname(dst))
fs::file_copy(src, dst, overwrite)

# Set copy_mode = FALSE: files in the store are read-only. It's easier on
# the user if we make them writable again.
copy_files(src, dst, overwrite = overwrite, copy_mode = FALSE)

invisible(dst)
},

Expand All @@ -55,7 +59,7 @@ file_store <- R6::R6Class(
if (move) {
fs::file_move(src, dst)
} else {
fs::file_copy(src, dst, overwrite = FALSE)
copy_files(src, dst, overwrite = FALSE)
}
fs::file_chmod(dst, "a-w")
} else if (move) {
Expand Down
11 changes: 6 additions & 5 deletions R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ orderly_run <- function(name, parameters = NULL, envir = NULL, echo = TRUE,

if (dat$strict$enabled) {
inputs_info <- NULL
fs::file_copy(file.path(src, entrypoint_filename), path)
copy_files(file.path(src, entrypoint_filename), path)
} else {
inputs_info <- copy_resources_implicit(src, path, dat$resources,
dat$artefacts)
Expand Down Expand Up @@ -471,10 +471,11 @@ copy_resources_implicit <- function(src, dst, resources, artefacts) {
to_copy <- setdiff(to_copy, exclude)
}
}
fs::dir_create(unique(file.path(dst, dirname(to_copy))))
fs::file_copy(file.path(src, to_copy),
file.path(dst, to_copy),
overwrite = TRUE)

copy_files(file.path(src, to_copy),
file.path(dst, to_copy),
overwrite = TRUE)

withr::with_dir(dst, fs::file_info(to_copy))
}

Expand Down
17 changes: 12 additions & 5 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,18 @@ expand_dirs <- function(paths, workdir) {
}


copy_files <- function(src, dst, files, overwrite = FALSE) {
fs::dir_create(unique(file.path(dst, dirname(files))))
fs::file_copy(file.path(src, files),
file.path(dst, files),
overwrite = overwrite)
copy_files <- function(src, dst, overwrite = FALSE,
copy_mode = TRUE) {
fs::dir_create(unique(dirname(dst)))

# mrc-5557: We intentionally don't use fs::file_copy, as it does not work
# reliably on mounted Samba file systems.
ok <- file.copy(src, dst, overwrite = overwrite,
copy.mode = copy_mode,
copy.date = TRUE)
if (any(!ok)) {
cli::cli_abort("Could not copy file{?s} {.file {src[!ok]}}")
}
}


Expand Down

0 comments on commit 432dc8e

Please sign in to comment.