Bug 17337 - file.copy(directory, file, overwrite=TRUE, recursive=FALSE) makes 0-length file, returns different values on Linux and Windows.
Summary: file.copy(directory, file, overwrite=TRUE, recursive=FALSE) makes 0-length fi...
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: I/O (show other bugs)
Version: R 3.4.1
Hardware: Other Other
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-09-11 18:49 UTC by Bill Dunlap
Modified: 2017-09-11 18:49 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Dunlap 2017-09-11 18:49:15 UTC
I erroneously used file.copy(dir,file,overwrite=TRUE,recursive=FALSE) to try to copy a directory to an ordinary file or to a name not in the file system.  file.copy() then creates a new zero-length file with the given name, whether or not a file by that name previously existed.

Also, file.copy() returns TRUE on Linux and FALSE on Windows.

What is recursive=FALSE expected to do with from=aDirectory?  I might expect it to make an empty directory with the given name.

E.g., on Linux with either R-3.4.1 or R-devel (2017-09-05 r73207):
dir.create(fromDir <- tempfile())
unlink(toFile <- tempfile())
file.copy(fromDir, toFile, overwrite=TRUE, recursive=FALSE)
#[1] TRUE
file.info(toFile)[, c("size", "isdir")]
#                                 size isdir
#/tmp/RtmptZYIef/file736f348b5ac1    0 FALSE

dir.create(fromDir <- tempfile())
cat(file = toFile <- tempfile(), "existing file\n")
file.copy(fromDir, toFile, overwrite=TRUE, recursive=FALSE)
#[1] TRUE
file.info(toFile)[, c("size", "isdir")]
#                                 size isdir
#/tmp/RtmptZYIef/file736f6b10add3    0 FALSE

and on Windows 10 with R-3.4.1
dir.create(fromDir <- tempfile())
unlink(toFile <- tempfile())
file.copy(fromDir, toFile, overwrite=TRUE, recursive=FALSE)
#[1] FALSE
file.info(toFile)[, c("size", "isdir")]
#                                                                      size isdir
#C:\\Users\\wdunlap\\AppData\\Local\\Temp\\RtmpYVNrju\\file16f86d235ce    0 FALSE

dir.create(fromDir <- tempfile())
cat(file = toFile <- tempfile(), "existing file\n")
file.copy(fromDir, toFile, overwrite=TRUE, recursive=FALSE)
#[1] FALSE
file.info(toFile)[, c("size", "isdir")]
#                                                                       size isdir
#C:\\Users\\wdunlap\\AppData\\Local\\Temp\\RtmpYVNrju\\file16f830f75435    0 FALSE


sessionInfo for Linux/R-devel gives
R Under development (unstable) (2017-09-05 r73207)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/atlas-base/libf77blas.so.3.0
LAPACK: /home/R/R-devel/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.5.0

and for Windows/R-3.4.1
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 10586)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.4.1