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

Misleading ENOENT when attempting to `file_copy` to the same location twice #95

Closed
nealrichardson opened this Issue Mar 27, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@nealrichardson

nealrichardson commented Mar 27, 2018

If you try to file_copy a single file with overwrite = FALSE and the destinationnew_path already exists, you get a EEXIST error. file_copy is vectorized, and if you have any duplicates in new_path, you might expect to get the same error: the first copy would succeed, and the second one would fail with "file already exists". Instead, you get an incorrect "no such file or directory" (ENOENT) error, which points you in the wrong direction for debugging your code.

This test:

test_that("file_copy errors usefully", {
  tmp <- tempfile()
  dir_create(tmp)
  cat("", file=file.path(tmp, "a.txt"))
  
  expect_error(
    file_copy(rep(file.path(tmp, "a.txt"), 2), rep(file.path(tmp, "b.txt"), 2)),
    "EEXIST"
  )
})

fails like this:

`file_copy(...)` threw an error with unexpected message.
Expected match: "EEXIST"
Actual message: "[ENOENT] Failed to copy '/var/folders/ly/dnxts6pd22q98109b0nsbq2h0000gp/T/RtmpvSTXbY/fileb73b130ed4bb/a.txt' to '/var/folders/ly/dnxts6pd22q98109b0nsbq2h0000gp/T/RtmpvSTXbY/fileb73b130ed4bb/b.txt': no such file or directory"
@jimhester

This comment has been minimized.

Member

jimhester commented Mar 30, 2018

So I was able to reproduce this and track down the cause to the system logging functions in the copyfile() implementation on macOS. See http://www.jimhester.com/2018/03/30/debugging-journey/ for more details.

@nealrichardson

This comment has been minimized.

nealrichardson commented Mar 30, 2018

Wow! That is a weird bug! So great that you were able to track it down, and thanks for sharing the story.

@jimhester

This comment has been minimized.

Member

jimhester commented Apr 2, 2018

So since this should happen only the first error, only on macOS, and only on macOS versions <= 10.12.6 I am going to close it. We could add a conditional for this case, but I am not sure it is worth the added complexity.

If we run into any more cases like this we can revisit it.

@jimhester jimhester closed this Apr 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment