Skip to content

illegal file names, silent failure #119

@r2evans

Description

@r2evans

Windows doesn't generally like colons in the filenames. Using storr_rds, though, keys with embedded colons are accepted but silently fail.

Windows:

p <- tempfile()
st <- storr::storr_rds(p)
st$set("mt", mtcars[1:2,])
st$set("foo:bar", iris[1:3,])
list.files(file.path(p, "keys", "objects"))
# [1] "mt"
st$get("foo:bar")
# Error: key 'foo:bar' ('objects') not found

Linux:

p <- tempfile()
st <- storr::storr_rds(p)
st$set("mt", mtcars[1:2,])
st$set("foo:bar", iris[1:3,])
list.files(file.path(p, "keys", "objects"))
# [1] "foo:bar" "mt"     
st$get("foo:bar")
#   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1          5.1         3.5          1.4         0.2  setosa
# 2          4.9         3.0          1.4         0.2  setosa
# 3          4.7         3.2          1.3         0.2  setosa

I would expect one of two behaviors:

  1. The key is encoded so that windows will accommodate it as a file on its filesystem. This introduces the potential for key collisions, so this is not without risk.
    • Possible workaround: use the hash of the key as a filename. While this does not change the possibility of collision, it also allows arbitrarily-long key strings (I think 255 for many filesystems). (One of my use-cases involves keying on multiple UUIDs (36 char each), and while I do not foresee combining more than six for a single key, I don't think that that is impossible.)
  2. KeyError or KeyWarning.

Number 1 suggests you would have to store the actual key somehow as well, which would likely incur another file read/write in the loop, not something you're eager to do. Perhaps number 2 is best: after file creation is attempted, if !file.exists then send a warning or error.

At a minimum, I suggest that this externally-imposed limitation should be documented, instead of the current docs which say:

'key': The key name.  Can be any string.

(https://kb.acronis.com/content/39790 suggests that the colon is the only not-allowed character, though I don't know with certainty. Edit: apparently the Japanese yen symbol "¥" is also verboten; that same page suggests '\', '/', '.', '?', and '*' are also bad.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions