I just noticed that the test uses O_CREAT but the impl does not even bother checking for this (ie treats O_WRONLY as create):
Yes, open on writes should i guess be O_WRONLY + one of the following:
1. O_CREAT | O_EXCL - create new file
2. O_CREATE|O_APPEND - create new file if it doesn't exist, else append
But, as you point out hdfsOpenFile has only ever checked for O_WRONLY|O_RDONLY. And #2 cannot be done without underlying FileSystem API.
But, as you point out, if someone does something like `echo hello >> foo` where foo does not exist, libhdfs will do the wrong thing probably.
FSDataOutputStream FileSystem.appendIfExistsElseCreate(Path p);
I can open a JIRA for it. I guess that means anyone using libhdfs (e.g. fuse) would have to do a hacky check if the file exists and decide whether to pass on the append flag, which of course is not transactional.
And of course, let's not even get into passing on O_TRUNCATE But, the libhdfs code should probably check for that flag and error out if it comes.