Skip to content
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

Realize relative symlinks properly in dir_exists() #397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* inputs to `path_real()` and `path_join()` are coerced to character for consistency with other functions (@raymondben, #370)

* `dir_exists()` follows relative symlinks in non-current directories (@heavywatal, #395)

# fs 1.5.2

* `file_create()` and `dir_create()` now return the correct path when `...` arguments are used (@davidchall, #333).
Expand Down
2 changes: 1 addition & 1 deletion R/access.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dir_exists <- function(path) {
res <- is_dir(path)

links <- is_link(path)
res[links] <- is_dir(link_path(path[links]))
res[links] <- is_dir(path_real(path[links]))

!is.na(res) & res
}
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-access.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("file_access", {

with_dir_tree(list("foo/bar" = "test"), {
link_create(path_abs("foo"), "loo")
link_create("foo", "relloo")

describe("file_exists", {
it("returns true for files that exist, false for those that do not", {
Expand Down Expand Up @@ -60,6 +61,11 @@ with_dir_tree(list("foo/bar" = "test"), {
})
it("returns true for links to directories, like -d in bash", {
expect_equal(dir_exists("loo"), c(loo = TRUE))
expect_equal(dir_exists("relloo"), c(relloo = TRUE))
.old_wd <- setwd("foo")
expect_equal(dir_exists("../loo"), c("../loo" = TRUE))
expect_equal(dir_exists("../relloo"), c("../relloo" = TRUE))
setwd(.old_wd)
})
it("returns FALSE on missing input", {
expect_identical(dir_exists(NA_character_), structure(names = NA, FALSE))
Expand Down