e888ac
From 3f6f906c7c7b28dc30edb98200b6e13e1a513bb4 Mon Sep 17 00:00:00 2001
e888ac
From: Ondrej Holy <oholy@redhat.com>
e888ac
Date: Wed, 9 May 2018 12:54:59 +0200
e888ac
Subject: [PATCH] smb: Use O_RDWR to fix fstat when writing
e888ac
e888ac
fstat fails with EINVAL on Windows servers if O_WRONLY is used to open
e888ac
(though it works properly on SAMBA servers). O_RDWR is needed to make
e888ac
it work. This causes issues when copying files over gvfsd-fuse among
e888ac
others.
e888ac
e888ac
https://bugzilla.gnome.org/show_bug.cgi?id=795805
e888ac
---
e888ac
 daemon/gvfsbackendsmb.c | 10 +++++-----
e888ac
 1 file changed, 5 insertions(+), 5 deletions(-)
e888ac
e888ac
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
e888ac
index d4944197..9571fa0d 100644
e888ac
--- a/daemon/gvfsbackendsmb.c
e888ac
+++ b/daemon/gvfsbackendsmb.c
e888ac
@@ -808,7 +808,7 @@ do_create (GVfsBackend *backend,
e888ac
   smbc_open = smbc_getFunctionOpen (op_backend->smb_context);
e888ac
   errno = 0;
e888ac
   file = smbc_open (op_backend->smb_context, uri,
e888ac
-		    O_CREAT|O_WRONLY|O_EXCL, 0666);
e888ac
+                    O_CREAT|O_RDWR|O_EXCL, 0666);
e888ac
   g_free (uri);
e888ac
 
e888ac
   if (file == NULL)
e888ac
@@ -850,7 +850,7 @@ do_append_to (GVfsBackend *backend,
e888ac
   smbc_open = smbc_getFunctionOpen (op_backend->smb_context);
e888ac
   errno = 0;
e888ac
   file = smbc_open (op_backend->smb_context, uri,
e888ac
-					O_CREAT|O_WRONLY|O_APPEND, 0666);
e888ac
+                    O_CREAT|O_RDWR|O_APPEND, 0666);
e888ac
   g_free (uri);
e888ac
 
e888ac
   if (file == NULL)
e888ac
@@ -916,7 +916,7 @@ open_tmpfile (GVfsBackendSmb *backend,
e888ac
     smbc_open = smbc_getFunctionOpen (backend->smb_context);
e888ac
     errno = 0;
e888ac
     file = smbc_open (backend->smb_context, tmp_uri,
e888ac
-		      O_CREAT|O_WRONLY|O_EXCL, 0666);
e888ac
+                      O_CREAT|O_RDWR|O_EXCL, 0666);
e888ac
   } while (file == NULL && errno == EEXIST);
e888ac
 
e888ac
   g_free (dir_uri);
e888ac
@@ -1040,7 +1040,7 @@ do_replace (GVfsBackend *backend,
e888ac
   
e888ac
   errno = 0;
e888ac
   file = smbc_open (op_backend->smb_context, uri,
e888ac
-		    O_CREAT|O_WRONLY|O_EXCL, 0);
e888ac
+                    O_CREAT|O_RDWR|O_EXCL, 0);
e888ac
   if (file == NULL && errno != EEXIST)
e888ac
     {
e888ac
       int errsv = fixup_open_errno (errno);
e888ac
@@ -1110,7 +1110,7 @@ do_replace (GVfsBackend *backend,
e888ac
 	  
e888ac
 	  errno = 0;
e888ac
 	  file = smbc_open (op_backend->smb_context, uri,
e888ac
-			    O_CREAT|O_WRONLY|O_TRUNC, 0);
e888ac
+                            O_CREAT|O_RDWR|O_TRUNC, 0);
e888ac
 	  if (file == NULL)
e888ac
 	    {
e888ac
               int errsv = fixup_open_errno (errno);
e888ac
-- 
e888ac
2.35.3
e888ac