git » libjio » commit d158773

We always need to read from files, even if jopen() is called with O_WRONLY, because we read the contents and save them to the transaction file before commiting it.

author Alberto Bertogli
2004-05-20 14:43:00 UTC
committer Alberto Bertogli
2007-07-15 12:49:16 UTC
parent 05b0e3965c8a6253717a1f18dcc2aba6509b215d

We always need to read from files, even if jopen() is called with O_WRONLY, because we read the contents and save them to the transaction file before commiting it.

We always need to read from files, even if jopen() is called with O_WRONLY,
because we read the contents and save them to the transaction file before
commiting it.

libjio.c +7 -0

diff --git a/libjio.c b/libjio.c
index cd51dae..bcef8e6 100644
--- a/libjio.c
+++ b/libjio.c
@@ -441,6 +441,13 @@ int jopen(struct jfs *fs, const char *name, int flags, int mode, int jflags)
 	unsigned int t;
 	char jdir[PATH_MAX], jlockfile[PATH_MAX];
 	struct stat sinfo;
+
+	/* we always need read access, because when we commit a transaction we
+	 * read the current contents before applying */
+	if (flags & O_WRONLY) {
+		flags = flags & ~O_WRONLY;
+		flags = flags | O_RDWR;
+	}
 	
 	fd = open(name, flags, mode);
 	if (fd < 0)