Skip to content

Commit

Permalink
need a little more treatment for path normalization on linux
Browse files Browse the repository at this point in the history
Needed more explicit handling of backslashes. Also removed case-insensitive file tests
  • Loading branch information
mkoohafkan committed Dec 19, 2023
1 parent 1064222 commit bf411d4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
3 changes: 2 additions & 1 deletion R/files.r
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@
#' @keywords internal
normalize_path = function(filename, exists) {
sep = "/"
filename = gsub("\\\\", sep, filename)
if (exists || file.exists(filename)) {
normalizePath(filename, winslash = sep, mustWork = TRUE)
} else if (dirname(filename) == filename) {
file.path(filename)
file.path(dirname(filename), basename(filename), fsep = sep)
} else {
normalizePath(file.path(Recall(dirname(filename), exists),
basename(filename), fsep = sep), winslash = sep,
Expand Down
12 changes: 0 additions & 12 deletions tests/testthat/test-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ test_that("File path normalization works", {
cwd = normalizePath(getwd(), winslash = "/", mustWork = TRUE)

tf1 = paste0(td, "\\file.txt")
tf2 = paste0(toupper(td), "/file.txt")
tf3 = "file.txt"
tf4 = "./file.txt"
tf5 = "/file.txt"
Expand All @@ -20,21 +19,10 @@ test_that("File path normalization works", {
expect_error(normalize_path(tf1, TRUE))

expect_identical(normalize_path(tf1, FALSE), vf1)
expect_identical(normalize_path(tf2, FALSE), vf1)
expect_identical(normalize_path(tf3, FALSE), vf2)
expect_identical(normalize_path(tf4, FALSE), vf2)
expect_identical(normalize_path(tf5, FALSE), vf3)

file.create(tf2)
on.exit(unlink(c(tf2)))
expect_identical(normalize_path(tf2, TRUE), vf1)

tf6 = "Q:\\foo/bar\\baz.txt"
vf4 = "Q:/foo/bar/baz.txt"

expect_identical(normalize_path(tf6, FALSE), vf4)
expect_identical(normalize_path(toupper(tf6), FALSE), toupper(vf4))

})


Expand Down

0 comments on commit bf411d4

Please sign in to comment.