diff --git a/r/R/filesystem.R b/r/R/filesystem.R index d20edcc6c024c..7357ca35a1396 100644 --- a/r/R/filesystem.R +++ b/r/R/filesystem.R @@ -108,7 +108,10 @@ Selector <- R6Class("Selector", ) Selector$create <- function(base_dir, allow_non_existent = FALSE, recursive = FALSE) { - shared_ptr(Selector, fs___Selector__create(base_dir, allow_non_existent, recursive)) + shared_ptr( + Selector, + fs___Selector__create(clean_path(base_dir), allow_non_existent, recursive) + ) } #' @title FileSystem classes @@ -165,53 +168,61 @@ FileSystem <- R6Class("FileSystem", inherit = Object, public = list( GetTargetStats = function(x) { if (inherits(x, "Selector")) { - map(fs___FileSystem__GetTargetStats_Selector(self, x), shared_ptr, class = FileStats) + map( + fs___FileSystem__GetTargetStats_Selector(self, x), + shared_ptr, + class = FileStats + ) } else if (is.character(x)){ - map(fs___FileSystem__GetTargetStats_Paths(self, x), shared_ptr, class = FileStats) + map( + fs___FileSystem__GetTargetStats_Paths(self, clean_path(x)), + shared_ptr, + class = FileStats + ) } else { - abort("incompatible type for FileSystem$GetTargetStarts()") + abort("incompatible type for FileSystem$GetTargetStats()") } }, CreateDir = function(path, recursive = TRUE) { - fs___FileSystem__CreateDir(self, path, isTRUE(recursive)) + fs___FileSystem__CreateDir(self, clean_path(path), isTRUE(recursive)) }, DeleteDir = function(path) { - fs___FileSystem__DeleteDir(self, path) + fs___FileSystem__DeleteDir(self, clean_path(path)) }, DeleteDirContents = function(path) { - fs___FileSystem__DeleteDirContents(self, path) + fs___FileSystem__DeleteDirContents(self, clean_path(path)) }, DeleteFile = function(path) { - fs___FileSystem__DeleteFile(self, path) + fs___FileSystem__DeleteFile(self, clean_path(path)) }, DeleteFiles = function(paths) { - fs___FileSystem__DeleteFiles(self, paths) + fs___FileSystem__DeleteFiles(self, clean_path(paths)) }, Move = function(src, dest) { - fs___FileSystem__Move(self, src, dest) + fs___FileSystem__Move(self, clean_path(src), clean_path(dest)) }, CopyFile = function(src, dest) { - fs___FileSystem__CopyFile(self, src, dest) + fs___FileSystem__CopyFile(self, clean_path(src), clean_path(dest)) }, OpenInputStream = function(path) { - shared_ptr(InputStream, fs___FileSystem__OpenInputStream(self, path)) + shared_ptr(InputStream, fs___FileSystem__OpenInputStream(self, clean_path(path))) }, OpenInputFile = function(path) { - shared_ptr(InputStream, fs___FileSystem__OpenInputFile(self, path)) + shared_ptr(InputStream, fs___FileSystem__OpenInputFile(self, clean_path(path))) }, OpenOutputStream = function(path) { - shared_ptr(OutputStream, fs___FileSystem__OpenOutputStream(self, path)) + shared_ptr(OutputStream, fs___FileSystem__OpenOutputStream(self, clean_path(path))) }, OpenAppendStream = function(path) { - shared_ptr(OutputStream, fs___FileSystem__OpenAppendStream(self, path)) + shared_ptr(OutputStream, fs___FileSystem__OpenAppendStream(self, clean_path(path))) } ) ) @@ -232,6 +243,11 @@ LocalFileSystem$create <- function() { #' @export SubTreeFileSystem <- R6Class("SubTreeFileSystem", inherit = FileSystem) SubTreeFileSystem$create <- function(base_path, base_fs) { - xp <- fs___SubTreeFileSystem__create(base_path, base_fs) + xp <- fs___SubTreeFileSystem__create(clean_path(base_path), base_fs) shared_ptr(SubTreeFileSystem, xp) } + +clean_path <- function(path) { + # Make sure we have a valid, forward-slashed path for passing to Arrow + normalizePath(path, winslash = "/", mustWork = FALSE) +} diff --git a/r/R/io.R b/r/R/io.R index f5390e32b257b..bafce7a3e0c36 100644 --- a/r/R/io.R +++ b/r/R/io.R @@ -74,8 +74,7 @@ OutputStream <- R6Class("OutputStream", inherit = Writable, #' @export FileOutputStream <- R6Class("FileOutputStream", inherit = OutputStream) FileOutputStream$create <- function(path) { - path <- normalizePath(path, mustWork = FALSE) - shared_ptr(FileOutputStream, io___FileOutputStream__Open(path)) + shared_ptr(FileOutputStream, io___FileOutputStream__Open(clean_path(path))) } #' @usage NULL @@ -148,7 +147,7 @@ Readable <- R6Class("Readable", inherit = Object, #' #' @section Methods: #' -#' - `$GetSize()`: +#' - `$GetSize()`: #' - `$supports_zero_copy()`: Logical #' - `$seek(position)`: go to that position in the stream #' - `$tell()`: return the position in the stream @@ -210,7 +209,7 @@ MemoryMappedFile <- R6Class("MemoryMappedFile", inherit = RandomAccessFile, #' @export ReadableFile <- R6Class("ReadableFile", inherit = RandomAccessFile) ReadableFile$create <- function(path) { - shared_ptr(ReadableFile, io___ReadableFile__Open(normalizePath(path))) + shared_ptr(ReadableFile, io___ReadableFile__Open(clean_path(path))) } #' @usage NULL @@ -232,7 +231,7 @@ BufferReader$create <- function(x) { #' #' @export mmap_create <- function(path, size) { - path <- normalizePath(path, mustWork = FALSE) + path <- clean_path(path) shared_ptr(MemoryMappedFile, io___MemoryMappedFile__Create(path, size)) } @@ -244,7 +243,7 @@ mmap_create <- function(path, size) { #' @export mmap_open <- function(path, mode = c("read", "write", "readwrite")) { mode <- match(match.arg(mode), c("read", "write", "readwrite")) - 1L - path <- normalizePath(path) + path <- clean_path(path) shared_ptr(MemoryMappedFile, io___MemoryMappedFile__Open(path, mode)) } diff --git a/r/tests/testthat/test-filesystem.R b/r/tests/testthat/test-filesystem.R index 1c19838306640..41327c077cf58 100644 --- a/r/tests/testthat/test-filesystem.R +++ b/r/tests/testthat/test-filesystem.R @@ -83,7 +83,6 @@ test_that("SubTreeFilesystem", { expect_is(st_fs, "FileSystem") st_fs$CreateDir("test") st_fs$CopyFile("DESCRIPTION", "DESC.txt") - skip_on_os("windows") # See ARROW-6622 stats <- st_fs$GetTargetStats(c("DESCRIPTION", "test", "nope", "DESC.txt")) expect_equal(stats[[1L]]$type, FileType$File) expect_equal(stats[[2L]]$type, FileType$Directory)