detach on quick-save

Oswald Buddenhagen ossi at kde.org
Wed Feb 9 15:15:54 UTC 2005


On Wed, Feb 09, 2005 at 12:45:44PM +0200, Andrew V. Samoilov wrote:
> > in quick-save mode the editor just overwrites the existing file.
> > this is all fine ... except when you cloned a source tree with "cp
> > -al" and want to patch one copy.
> > this patch adds a check whether the file has multiple hard links and
> > asks whether the file should be "detached" before saving.
> > not sure the dialog looks 100% right, but you get the idea. :)
> 
> Safe save has to be the best choise for these cases.
> 
i'm not going to switch the mode all times. i made it interactive for a
reason.
but just deleting the old file seems dangerous, indeed, so let's do the
check earlier and just switch to safe save mode if necessary.
not sure whether one should check for file_is_local or whether remote
files always have st_nlink == 1?

> Also you cannot move mc_chown()/mc_chmod() calls because they must be
> called before mc_open(). Elsewhere mc editor will hang for FTPD
> timeout on ftpfs and forever on fishfs.
> 
hmm, TooMuchBlackMagicException.

i attached a new version of the patch and a small optimization patch
which short-cuts the file existance check if it is irrelevant.

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
-------------- next part --------------
Index: edit/edit-widget.h
===================================================================
RCS file: /cvsroot/mc/mc/edit/edit-widget.h,v
retrieving revision 1.24
diff -U2 -r1.24 edit-widget.h
--- edit/edit-widget.h	3 Dec 2004 17:09:27 -0000	1.24
+++ edit/edit-widget.h	9 Feb 2005 15:09:41 -0000
@@ -90,4 +90,5 @@
 
     struct stat stat1;		/* Result of mc_fstat() on the file */
+    int skip_ask_if_detach:1;	/* Already asked whether to detach file */
 
     /* syntax higlighting */
Index: edit/editcmd.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/editcmd.c,v
retrieving revision 1.128
diff -U2 -r1.128 editcmd.c
--- edit/editcmd.c	7 Feb 2005 07:31:19 -0000	1.128
+++ edit/editcmd.c	9 Feb 2005 15:09:42 -0000
@@ -238,4 +239,23 @@
     }
 
+    if (this_save_mode == EDIT_QUICK_SAVE &&
+	edit->stat1.st_nlink > 1 &&
+	!edit->skip_ask_if_detach)
+    {
+	switch (query_dialog (_(" File has hard-links "),
+			      _("Detach before saving?"), 0,
+			      3, _("&Yes"), _("&No"), _("&Cancel")))
+	{
+	case 0:
+	    this_save_mode = EDIT_SAFE_SAVE;
+	    /* fallthrough */
+	case 1:
+	    edit->skip_ask_if_detach = 1;
+	    break;
+	default:
+	    return 1;
+	}
+    }
+
     if (this_save_mode != EDIT_QUICK_SAVE) {
 	char *savedir, *saveprefix;
-------------- next part --------------
Index: edit/editcmd.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/editcmd.c,v
retrieving revision 1.128
diff -U2 -r1.128 editcmd.c
--- edit/editcmd.c	7 Feb 2005 07:31:19 -0000	1.128
+++ edit/editcmd.c	9 Feb 2005 15:09:42 -0000
@@ -226,5 +226,6 @@
     }
 
-    if (!vfs_file_is_local (filename) ||
+    if (option_save_mode == EDIT_QUICK_SAVE ||
+	!vfs_file_is_local (filename) ||
 	(fd = mc_open (filename, O_WRONLY | O_BINARY)) == -1) {
 	/*


More information about the mc-devel mailing list