Skip to content

Commit

Permalink
File move uses fs when installed, instead of file.rename, which r…
Browse files Browse the repository at this point in the history
…equires the source and destination to be on the same disk
  • Loading branch information
dipterix committed Aug 26, 2024
1 parent b89872b commit 9286f7a
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: raveio
Type: Package
Title: File-System Toolbox for RAVE Project
Version: 0.9.0.66
Version: 0.9.0.67
Language: en-US
Authors@R: c(
person("Zhengjia", "Wang", email = "[email protected]", role = c("aut", "cre", "cph")),
Expand Down
2 changes: 1 addition & 1 deletion R/cmd-aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cmd_execute <- function(script, script_path, command = "bash", dry_run = FALSE,
if(file.exists(to_path)) {
unlink(backup_path)
} else {
file.rename(backup_path, to_path)
file_move(backup_path, to_path)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ safe_write_csv <- function(x, file, ..., quiet = FALSE){
if(!quiet){
catgl('Renaming file {file}\n >> {oldfile}')
}
file.rename(file, oldfile)
file_move(file, oldfile)
}
args <- list(...)
rn <- args$row.names
Expand Down
4 changes: 2 additions & 2 deletions R/csv2.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export_table <- function(x, file, format = c("auto", "csv", "csv.zip", "h5", "fs
})
data.table::fwrite(x = x, file = tf, ...)
utils::zip(zipfile = zf, files = tf, extras='-j')
file.rename(zf, file)
file_move(zf, file)
},
"fst" = {
fst::write_fst(x = x, path = file, compress = 99)
Expand Down Expand Up @@ -211,7 +211,7 @@ export_table <- function(x, file, format = c("auto", "csv", "csv.zip", "h5", "fs
# save meta information
save_h5(x = jsonlite::serializeJSON(meta), file = h5file, name = "__meta__", replace = TRUE, ctype = "character", quiet = TRUE)

file.rename(h5file, file)
file_move(h5file, file)
},
"rds" = {
saveRDS(object = x, file = file, ...)
Expand Down
2 changes: 1 addition & 1 deletion R/pipeline-serializer.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ tfmtreg_filearray <- function() {
copy.date = TRUE, recursive = TRUE,
overwrite = TRUE)
orig_name <- basename(filebase_orig)
file.rename(
file_move(
file.path(filebase_dir, orig_name),
filebase
)
Expand Down
2 changes: 1 addition & 1 deletion R/units.R
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ backup_file <- function(path, remove = FALSE, quiet = FALSE) {
path2 <- file.path(dname, bname2)

if( remove ) {
file.rename(from = path, to = path2)
file_move(from = path, to = path2)
} else {
if(is_dir) {
dir_create2(path2)
Expand Down
4 changes: 2 additions & 2 deletions R/utils-archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ archive_subject <- function(
if(file.exists(path)) {
backup_file(path, remove = TRUE)
}
file.rename(zipfile_name, path)
file_move(zipfile_name, path)
} else {
path <- zipfile_name
}
Expand Down Expand Up @@ -545,7 +545,7 @@ install_subject <- function(

if( backup ) {
new_path <- backup_file(subject$preprocess_settings$raw_path, remove = TRUE)
file.rename(subject$path, file.path(dirname(subject$path), filenames(new_path)))
file_move(subject$path, file.path(dirname(subject$path), filenames(new_path)))
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ normalize_path <- function(path, must_work = NA) {
gsub("[/|\\\\]+", "/", path)
}

file_move <- function(from, to) {
if(dipsaus::package_installed("fs")) {
fs <- asNamespace("fs")
impl <- fs$file_move
if(is.function(impl)) {
impl(path = from, new_path = to)
return(invisible(to))
}
}
file.rename(from = from, to = to)
return(invisible(to))
}

safe_system <- function(cmd, ..., intern = TRUE, ignore.stderr = TRUE,
minimized = TRUE, invisible = TRUE, show.output.on.console = TRUE){
suppressWarnings({
Expand Down

0 comments on commit 9286f7a

Please sign in to comment.