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

Bugfix in waitForFile #276

Merged
merged 1 commit into from
Jul 28, 2021
Merged

Bugfix in waitForFile #276

merged 1 commit into from
Jul 28, 2021

Conversation

stuvet
Copy link
Contributor

@stuvet stuvet commented Jul 24, 2021

Background

  • Bug discovered on Slurm, where the worker is booting.

Reprex

library(rbenchmark)
library(data.table)

fn <- fs::file_create(tempfile())
fn_short <- basename(fn)
path <- fs::path_dir(fn)

fs::file_exists(fn)
#> /tmp/RtmpZqNq5M/file1f8ca1b4f66d4 
#>                              TRUE

Existing strategy

  • waitForFile currently receives fully-qualified filename
fn_short %chin% list.files(path, all.files = TRUE)
#> [1] TRUE
fn %chin% list.files(path, all.files = TRUE)
#> [1] FALSE

Proposed strategy

  • waitForFile handles both fully-qualified & short filenames
basename(fn_short) %chin% list.files(path, all.files = TRUE)
#> [1] TRUE
basename(fn) %chin% list.files(path, all.files = TRUE)
#> [1] TRUE

Benchmarks

benchmark(
  fs::file_exists(fn),
  basename(fn) %chin% list.files(path, all.files = TRUE), 
  fs::path_file(fn) %chin% list.files(path, all.files = TRUE), 
  fn %chin% list.files(path, all.files = TRUE, full.names = TRUE), # Fails if fn is already a basename
  replications = 10000
)
#>                                                              test replications elapsed relative user.self sys.self user.child sys.child
#> 2          basename(fn) %chin% list.files(path, all.files = TRUE)        10000  0.121    1.090     0.083    0.036          0         0
#> 4 fn %chin% list.files(path, all.files = TRUE, full.names = TRUE)        10000  0.111    1.000     0.060    0.049          0         0
#> 1                                             fs::file_exists(fn)        10000  8.339   75.126     6.419    1.425          0         0
#> 3     fs::path_file(fn) %chin% list.files(path, all.files = TRUE)        10000  0.319    2.874     0.266    0.050          0         0

Created on 2021-07-24 by the reprex package (v2.0.0)

@mllg
Copy link
Owner

mllg commented Jul 28, 2021

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants