From 800a132016acce7fb158b6d2b123780a6a145770 Mon Sep 17 00:00:00 2001
From: Eli Collins <eli@cloudera.com>
Date: Tue, 12 Jan 2010 21:09:02 -0800
Subject: [PATCH] HDFS-861: fuse-dfs does not support O_RDWR

---
 src/contrib/fuse-dfs/src/fuse_impls_open.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/contrib/fuse-dfs/src/fuse_impls_open.c b/src/contrib/fuse-dfs/src/fuse_impls_open.c
index 73a1e34..aa9a3a2 100644
--- a/src/contrib/fuse-dfs/src/fuse_impls_open.c
+++ b/src/contrib/fuse-dfs/src/fuse_impls_open.c
@@ -50,6 +50,21 @@ int dfs_open(const char *path, struct fuse_file_info *fi)
     return -EIO;
   }
 
+  if (flags & O_RDWR) {
+    hdfsFileInfo *info = hdfsGetPathInfo(dfs->fs,path);
+    if (info == NULL) {
+      // File does not exist (maybe?); interpret it as a O_WRONLY
+      // If the actual error was something else, we'll get it again when
+      // we try to open the file.
+      flags ^= O_RDWR;
+      flags |= O_WRONLY;
+    } else {
+      // File exists; open this as read only.
+      flags ^= O_RDWR;
+      flags |= O_RDONLY;
+    }
+  }
+
   if ((fh->hdfsFH = hdfsOpenFile(fh->fs, path, flags,  0, 0, 0)) == NULL) {
     syslog(LOG_ERR, "ERROR: could not connect open file %s:%d\n", __FILE__, __LINE__);
     syslog(LOG_ERR, "ERROR: errno %d\n", errno);
-- 
1.6.0.4

