Qubes wrote:
Qubes wrote:
I am just trying my luck here with an issue that i have been unable to resolve on my Qubes system for a long time now. I have been looking into this problem quite a bit but i cannot seem to find a solution anywhere. Perhaps someone on this list has experienced the same and has found a solution.

When i open a text file that is located on a network share with gedit, gedit is unable to save the file. When I click the save button, or `Ctrl + s`, i can see gedit creates a temporary file named ".goutputstream-AO9U51" on the network share and in gedit i get a message "Could not create a backup file while saving "/home/user/data/test/file-name.txt"". If i launch gedit from cli i see a message on cli when saving the file "Hit unhandled case 27 (Error renaming temporary file: Resource temporarily unavailable) in parse_error."

I definitely have permissions on the network share as i can copy files to it, delete, create directories, etc. I can also open a LibreOffice document and save it. The problem appears to be specific to gedit. Also, it happens with both a Fedora and Debian based VM.

In addition that i forgot to mention is, i can open edit and save the same txt files with vi and it works.

I have read reports [1][2][3][4][6] dating as far back as 12 years with the sshfs protocol (an abandoned project) being implicated as well.

On issue 438 [3] that was reported on Gitlab it is reported that "As far as I can tell, the problem is in the way glib saves a file by writing to a temporary file and renaming to the final name." and "I'll take a more serious look later but I'd start with gio/glocalfileoutputstream.c and particularly the function _g_local_file_output_stream_really_close which contains the error string "Error renaming temporary file".".

A duplicate issue 565 [5] to issue 438 [3] was opened and there a patch is provided that is said to fix this issue although i have not tried it because i don't know how to.

**Question:** Would anybody perhaps know how and where to do the patch, attached for reference, on Fedora/Debian. As far as I can tell the patch needs to be done on the client since the problem originates from the client.

[1]: https://askubuntu.com/questions/13843/gedit-sshfs-wont-save-vi-saves-fine [2]: https://unix.stackexchange.com/questions/52951/gedit-wont-save-a-file-on-a-virtualbox-share-text-file-busy
[3]: https://gitlab.gnome.org/GNOME/glib/-/issues/438
[4]: https://github.com/rclone/rclone/issues/2130
[5]: https://gitlab.gnome.org/GNOME/glib/-/issues/565
[6]: https://illumos.topicbox.com/groups/omnios-discuss/Tc4c6b72d6386f9fb/resource-temporarily-unavailable-when-saving-to-cifs-share-on-r151038

--
You received this message because you are subscribed to the Google Groups 
"qubes-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to qubes-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/qubes-users/41c6de8b-c200-0178-9cd9-c06809f94bfa%40ak47.co.za.
From 179812d0847af191e709539041a57d5779d847ed Mon Sep 17 00:00:00 2001
From: TW <tomasz@wisni3w...@gmail.com>
Date: Wed, 27 Jun 2012 19:35:33 +0200
Subject: [PATCH] gio: workaround for renaming files on filesystems not
 supporting it

This is a workaround for samba and "Virtual Box shared" filesystem which does not support renaming opened files and react on such attempt with ETXTBSY. It is also a solution proposal for:

Bug 678994 - Unable to overwrite files on vbox shared mounted filesystems
---
 gio/glocalfileoutputstream.c | 90 +++++++++++++++++++++++++++++++-------------
 1 file changed, 63 insertions(+), 27 deletions(-)

diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c
index a310fcd..60e5f43 100644
--- a/gio/glocalfileoutputstream.c
+++ b/gio/glocalfileoutputstream.c
@@ -223,6 +223,7 @@ _g_local_file_output_stream_really_close (GLocalFileOutputStream *file,
 {
   GLocalFileStat final_stat;
   int res;
+  int smb_cifs_rename_workaround = 0;
 
 #ifdef HAVE_FSYNC
   if (file->priv->sync_on_close &&
@@ -318,17 +319,44 @@ _g_local_file_output_stream_really_close (GLocalFileOutputStream *file,
       if (g_cancellable_set_error_if_cancelled (cancellable, error))
 	goto err_out;
 
-      /* tmp -> original */
-      if (g_rename (file->priv->tmp_filename, file->priv->original_filename) != 0)
-	{
-          int errsv = errno;
 
-	  g_set_error (error, G_IO_ERROR,
-		       g_io_error_from_errno (errsv),
-		       _("Error renaming temporary file: %s"),
-		       g_strerror (errsv));
-	  goto err_out;
-	}
+      res = g_rename (file->priv->tmp_filename, file->priv->original_filename);
+
+      /* tmp -> original */
+      if (res != 0 && errno == ETXTBSY)
+      {
+    	  // try to close the fd first and retry renaming
+    	  if (fstat (file->priv->fd, &final_stat) == 0)
+    		  file->priv->etag = _g_local_file_info_create_etag (&final_stat);
+
+    	  while (1)
+    	  {
+    		  res = close (file->priv->fd);
+    		  if (res == -1)
+    		  {
+    			  int errsv = errno;
+    			  g_set_error (error, G_IO_ERROR,
+    					  g_io_error_from_errno (errsv),
+    					  _("Error closing file: %s"),
+    					  g_strerror (errsv));
+    			  goto err_out;
+    		  }
+    		  break;
+    	  }
+
+    	  smb_cifs_rename_workaround = 1;
+    	  res = g_rename (file->priv->tmp_filename, file->priv->original_filename);
+      }
+
+      if (res != 0)
+      {
+    	  int errsv = errno;
+    	  g_set_error (error, G_IO_ERROR,
+    			  g_io_error_from_errno (errsv),
+    			  _("Error renaming temporary file: %s"),
+    			  g_strerror (errsv));
+    	  goto err_out;
+      }
     }
   
   if (g_cancellable_set_error_if_cancelled (cancellable, error))
@@ -336,25 +364,33 @@ _g_local_file_output_stream_really_close (GLocalFileOutputStream *file,
       
 #ifndef G_OS_WIN32		/* Already did the fstat() and close() above on Win32 */
 
-  if (fstat (file->priv->fd, &final_stat) == 0)
-    file->priv->etag = _g_local_file_info_create_etag (&final_stat);
 
-  while (1)
-    {
-      res = close (file->priv->fd);
-      if (res == -1)
-	{
-          int errsv = errno;
+  if (!smb_cifs_rename_workaround)
+  {
+	  if (fstat (file->priv->fd, &final_stat) == 0)
+		  file->priv->etag = _g_local_file_info_create_etag (&final_stat);
 
-	  g_set_error (error, G_IO_ERROR,
-		       g_io_error_from_errno (errsv),
-		       _("Error closing file: %s"),
-		       g_strerror (errsv));
-	}
-      break;
-    }
-  
-  return res != -1;
+	  while (1)
+	  {
+		  res = close (file->priv->fd);
+		  if (res == -1)
+		  {
+			  int errsv = errno;
+
+			  g_set_error (error, G_IO_ERROR,
+					  g_io_error_from_errno (errsv),
+					  _("Error closing file: %s"),
+					  g_strerror (errsv));
+		  }
+		  break;
+	  }
+
+	  return res != -1;
+  }
+  else
+  {
+	  return TRUE;
+  }
 
 #else
 
-- 
1.7.11.1

Reply via email to