rhdf5::h5dump requires write access
Entering edit mode
friedmab ▴ 10
Last seen 2.2 years ago
Genentech, Inc., South San Francisco, C…

I have a problem getting the h5dump function to work on a file for which I do not have write access. This example reproduces the error:

> library(rhdf5)
> filename <- "x.hdf5"
> stopifnot(!file.exists(filename))
> h5createFile(filename)
[1] TRUE
> h5write(LETTERS, file = filename, name = "/LETTERS")
> h5dump(filename)  ## works OK                                                                                                                                                    
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"

> Sys.chmod(filename, mode = "0444")
> h5dump(filename)  ## throws an error                                                                                                                                             
HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: H5F.c line 1522 in H5Fopen(): unable to open file                                                                                                                          
    major: File accessability
    minor: Unable to open file
  #001: H5F.c line 1211 in H5F_open(): unable to open file: time = Thu Oct 23 14:33:11 2014                                                                                        
, name = 'x.hdf5', tent_flags = 1
    major: File accessability
    minor: Unable to open file
  #002: H5FD.c line 1086 in H5FD_open(): open failed                                                                                                                               
    major: Virtual File Layer
    minor: Unable to initialize object

  #003: H5FDsec2.c line 348 in H5FD_sec2_open(): unable to open file: name = 'x.hdf5', errno = 13, error message = 'Permission denied', flags = 1, o_flags = 2                       
    major: File accessability
    minor: Unable to open file
HDF5: unable to open file
Error in h5checktypeOrOpenLoc(file) :
  Error in h5checktypeOrOpenLoc(). File 'x.hdf5' is not a valid HDF5 file.
> unlink(filename)
> sessionInfo()
R version 3.1.0 Patched (2014-05-17 r65643)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rhdf5_2.10.0

loaded via a namespace (and not attached):
[1] zlibbioc_1.11.1


I believe a simple fix would be to modify the first line of the h5dump function. Instead of 

loc = h5checktypeOrOpenLoc(file)

it should be

loc = h5checktypeOrOpenLoc(file, readonly = TRUE)

In fact that is how the h5ls() function starts.



In the meantime, this would be a workaround:

fid <- H5Fopen(filename, flags = "H5F_ACC_RDONLY")


rhdf5 • 2.8k views

Login before adding your answer.

Traffic: 284 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6