Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2770a24

Browse files
authored
fix #804: use xfun::file_rename() because file.rename() would fail to rename files across different disk volumes (#1476)
1 parent 5dcce03 commit 2770a24

File tree

12 files changed

+16
-49
lines changed

12 files changed

+16
-49
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: bookdown
22
Type: Package
33
Title: Authoring Books and Technical Documents with R Markdown
4-
Version: 0.40.1
4+
Version: 0.40.2
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
77
person("Christophe", "Dervieux", , "[email protected]", role = c("ctb"),
@@ -65,7 +65,7 @@ Imports:
6565
knitr (>= 1.38),
6666
rmarkdown (>= 2.14),
6767
jquerylib,
68-
xfun (>= 0.39),
68+
xfun (>= 0.47.12),
6969
tinytex (>= 0.12),
7070
yaml (>= 2.1.19)
7171
Suggests:
@@ -94,3 +94,4 @@ Config/Needs/book: remotes, webshot, svglite
9494
Config/Needs/website: pkgdown, tidyverse/tidytemplate, rstudio/quillt
9595
Config/testthat/edition: 3
9696
VignetteBuilder: knitr
97+
Remotes: yihui/xfun

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import(utils)
4343
importFrom(xfun,dir_create)
4444
importFrom(xfun,dir_exists)
4545
importFrom(xfun,existing_files)
46+
importFrom(xfun,file_rename)
4647
importFrom(xfun,in_dir)
4748
importFrom(xfun,read_utf8)
4849
importFrom(xfun,same_path)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- If set to `TeX-AMS-MML_HTMLorMML` renders equations in HTML + CSS (which may look nicer for some equations).
66
- If set to `TeX-MML-AM_SVG` renders equations in SVG.
77

8+
- Fixed the bug that `render_book()` fails due to `file.rename()` being unable to rename files across different disk volumes (thanks, @Giqles @katrinabrock, #804).
9+
810
# CHANGES IN bookdown VERSION 0.40
911

1012
- Footnotes are not rendered correctly when `katex` is used to render LaTeX math expressions (thanks, @pbreheny, #1470).

R/bookdown-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"_PACKAGE"
77

88
## usethis namespace: start
9-
#' @importFrom xfun dir_create dir_exists
9+
#' @importFrom xfun dir_create dir_exists file_rename
1010
## usethis namespace: end
1111
NULL

R/ebook.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ epub_book = function(
7676
move_output = function(output) {
7777
if (is.null(opts$get('output_dir'))) return(output)
7878
output2 = output_path(output)
79-
file.rename(output, output2)
79+
file_rename(output, output2)
8080
output2
8181
}
8282

R/html.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ clean_html_tags = function(x) {
534534
move_to_output_dir = function(files) {
535535
files2 = output_path(files)
536536
i = file.exists(files) & (files != files2)
537-
file.rename(files[i], files2[i])
537+
file_rename(files[i], files2[i])
538538
files2
539539
}
540540

R/latex.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ pdf_book = function(
7575
if (is.null(o)) return(output)
7676

7777
output2 = file.path(o, output)
78-
file.rename(output, output2)
79-
if (keep_tex) file.rename(f, file.path(o, f))
78+
file_rename(output, output2)
79+
if (keep_tex) file_rename(f, file.path(o, f))
8080
output2
8181
}
8282
# always enable tables (use packages booktabs, longtable, ...)

R/render.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ render_book = function(
121121
aux_diro = '_bookdown_files'
122122
# move _files and _cache from _bookdown_files to ./, then from ./ to _bookdown_files
123123
aux_dirs = files_cache_dirs(aux_diro)
124-
move_dirs(aux_dirs, basename(aux_dirs))
124+
file_rename(aux_dirs, basename(aux_dirs))
125125
on.exit({
126126
aux_dirs = files_cache_dirs('.')
127127
if (length(aux_dirs)) {
128128
dir_create(aux_diro)
129-
move_dirs(aux_dirs, file.path(aux_diro, basename(aux_dirs)))
129+
file_rename(aux_dirs, file.path(aux_diro, basename(aux_dirs)))
130130
}
131131
}, add = TRUE)
132132

@@ -215,7 +215,7 @@ render_new_session = function(files, main, config, output_format, clean, envir,
215215

216216
meta = clean_meta(render_meta, files)
217217
move = !(unlist(meta) %in% files) # do not move input files to output dir
218-
on.exit(file.rename(unlist(meta)[move], files_md[move]), add = TRUE)
218+
on.exit(file_rename(unlist(meta)[move], files_md[move]), add = TRUE)
219219

220220
merge_chapters(unlist(meta), main, orig = files)
221221

R/skeleton.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bookdown_skeleton = function(path, output_format = skeleton_formats()) {
2020
skeleton_build_index(path, output_format)
2121
skeleton_build_output_yml(path, output_format)
2222
skeleton_build_bookdown_yml(path, output_format)
23-
move_dir(file.path(path, output_format), path) # move left format files
23+
file_rename(file.path(path, output_format), path) # move left format files
2424
skeleton_remove_blocks(path, output_format)
2525

2626
# Get missing assets

R/utils.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -457,19 +457,6 @@ files_cache_dirs = function(dir = '.') {
457457
out
458458
}
459459

460-
# file.rename() does not work if target directory is not empty, so we just copy
461-
# everything from `from` to `to`, and delete `from`
462-
move_dir = function(from, to) {
463-
if (!dir_exists(to)) return(file.rename(from, to))
464-
to_copy = list.files(from, full.names = TRUE)
465-
if (length(to_copy) == 0 ||
466-
any(file.copy(list.files(from, full.names = TRUE), to, recursive = TRUE))
467-
) unlink(from, recursive = TRUE)
468-
invisible(TRUE)
469-
}
470-
471-
move_dirs = function(from, to) mapply(move_dir, from, to)
472-
473460
#' @importFrom xfun existing_files
474461
existing_r = function(base) {
475462
x = apply(expand.grid(base, c('R', 'r')), 1, paste, collapse = '.')

0 commit comments

Comments
 (0)