basho/bitcask

File Open behaves differently between NIF and Erlang modes [JIRA: RIAK-2895]

Closed this issue · 1 comments

https://github.com/basho/bitcask/blob/develop/src/bitcask_file.erl#L133-L134
https://github.com/basho/bitcask/blob/develop/c_src/bitcask_nifs.c#L2314

In Erlang mode, calling file_open with [] as the FileOpts will result in [read, write, raw, binary] being passed to Erlang's file:open/2. As per the Erlang docs,

write
The file is opened for writing. It is created if it does not exist.

In NIF mode, calling file_open with [] as the FileOps will result in O_RDWR | O_APPEND being passed into the open call. Without O_CREATE, O_RDWR will return enoent when attempting to open a file that does not exist.

The end result of this is that calling file_open/2 in Erlang mode will create a file if it doesn't exist, but calling it it in NIF mode it will not. This relates closely to #242.

Fixed by a1568ae