detach on quick-save

Oswald Buddenhagen ossi at kde.org
Mon Feb 7 17:39:02 UTC 2005


moin,

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. :)

-- 
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	7 Feb 2005 17:32:40 -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	7 Feb 2005 17:32:41 -0000
@@ -262,6 +262,23 @@
 	savename = g_strdup (filename);
 
-    mc_chown (savename, edit->stat1.st_uid, edit->stat1.st_gid);
-    mc_chmod (savename, edit->stat1.st_mode);
+    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:
+	    mc_unlink (savename);
+	    /* fallthrough */
+	case 1:
+	    edit->skip_ask_if_detach = 1;
+	    break;
+	default:
+	    g_free (savename);
+	    return 1;
+	}
+    }
 
     if ((fd =
@@ -270,4 +287,7 @@
 	goto error_save;
 
+    mc_chown (savename, edit->stat1.st_uid, edit->stat1.st_gid);
+    mc_chmod (savename, edit->stat1.st_mode);
+
 /* pipe save */
     if ((p = edit_get_write_filter (savename, filename))) {


More information about the mc-devel mailing list