-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the fs package to copy files. #178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: orderly2 | ||
Title: Orderly Next Generation | ||
Version: 1.99.38 | ||
Version: 1.99.39 | ||
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), | ||
email = "[email protected]"), | ||
person("Robert", "Ashton", role = "aut"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,18 +184,48 @@ expand_dirs <- function(files, workdir) { | |
} | ||
|
||
|
||
copy_files <- function(src, dst, overwrite = FALSE, | ||
copy_mode = TRUE) { | ||
copy_files <- function(src, dst, overwrite = FALSE) { | ||
assert_character(src) | ||
assert_character(dst) | ||
|
||
if (length(src) != length(dst)) { | ||
cli::cli_abort("Source and destination have different lengths") | ||
} | ||
|
||
is_dir <- fs::dir_exists(dst) | ||
if (any(is_dir)) { | ||
paths <- dst[is_dir] | ||
cli::cli_abort(paste( | ||
"Destination path{?s} {?is a directory/are directories}:", | ||
"{.path {paths}}")) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We mostly didn't exploit the old behaviour, apart from one place to copy the report script in |
||
|
||
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]}}") | ||
# For some reason, file_copy does not work when `overwrite = TRUE`, the | ||
# source file is read-only, the destination file is on a Samba file mount, | ||
# and we are on Linux. This seems like a bug in the Linux Samba driver. | ||
# See mrc-5557 for details. | ||
# | ||
# We work around it by always passing `overwrite = FALSE`. Instead we delete | ||
# any existing files manually beforehand. It is vulnerable to race condition, | ||
# as someone could recreate the file between the calls to file_delete and | ||
# file_copy, but that seems unlikely. If any of the files are read-only, we | ||
# refuse to proceed. | ||
# | ||
# If you are going to make changes to this function, make sure to run all | ||
# tests with TMPDIR set to a path on a network drive. | ||
if (overwrite) { | ||
exists <- fs::file_exists(dst) | ||
nonwrite <- !fs::file_access(dst[exists], "write") | ||
if (any(nonwrite)) { | ||
cli::cli_abort( | ||
"Cannot overwrite non-writable file{?s}: {dst[exists][nonwrite]}") | ||
} | ||
fs::file_delete(dst[exists]) | ||
} | ||
|
||
fs::file_copy(src, dst, overwrite = FALSE) | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,7 @@ outpack_packet_end_quietly <- function(...) { | |
|
||
forcibly_truncate_file <- function(path) { | ||
permissions <- fs::file_info(path)$permissions | ||
fs::file_chmod(path, "a+w") | ||
file.create(path) | ||
fs::file_delete(path) | ||
fs::file_create(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow, chmod isn't immediately visible when working over Samba, even after it returns. touch hello.txt
chmod 444 hello.txt; chmod 666 hello.txt; ls -l hello.txt Running the second line many times, it will sometimes print the permissions as |
||
fs::file_chmod(path, permissions) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function only ever gets called with a completely empty
dst
directory. There is no reason to useoverwrite = TRUE
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to add
make_writable = FALSE
here, as even though that's the default you've emphasised this point on the previous call?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry I don't really understand the comment. The only "previous call" in this file also omits the
make_writable
argument.make_writable = FALSE
is a no-op, it is not going to make things read-only (not that we would want that here anyway).Maybe having
copy_files
do the chmod is confusing, and instead I remove themake_writable
argument and move the chmod to the only two places it is actually needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previous call was outpack_store.R:38 where you have
make_writable = FALSE
, but it looks like that should be TRUE :)