Fix for another dala loss bug

Pavel Roskin proski at gnu.org
Wed Aug 1 21:56:51 UTC 2001


Hello!

"Safe save" and "Do backups" don't work on the remote VFS.  Fixing it
properly is quite hard, because it requires on implementation of rename()
on VFS.

Editing files on VFS with those options on can cause loss of data.  Such
bugs should have a very high priority for us.

I also replaced a tempnam() call with a call to mc_mkstemps(), so that the
last annoying linker warning on GNU/Linux is going away.

ChangeLog:
        * editcmd.c (edit_save_file): Temporarily disable safe save
        and backups on remote VFS because it doesn't work.  Use
        mc_mkstemps() instead of tempnam().

---------------------------------------------
--- editcmd.c
+++ editcmd.c
@@ -261,15 +261,27 @@ int edit_save_file (WEdit * edit, const

     savename = (char *) strdup ((char *) filename);

-    if ((fd = open (savename, O_WRONLY)) == -1) {
-	this_save_mode = 0;	/* the file does not exists yet, so no safe save or backup necessary */
+    if (vfs_file_is_local (filename)) {
+	if ((fd = open (savename, O_WRONLY)) == -1) {
+	    /*
+	     * The file does not exists yet, so no safe save or
+	     * backup are necessary.
+	     */
+	    this_save_mode = 0;
+	} else {
+	    close (fd);
+	    this_save_mode = option_save_mode;
+	}
     } else {
-	close (fd);
-	this_save_mode = option_save_mode;
+	/*
+	 * FIXME - rename is not impemented in VFS, so only
+	 * quick save is possible.
+	 */
+	this_save_mode = 0;
     }

     if (this_save_mode > 0) {
-	char *savedir, *slashpos;
+	char *savedir, *slashpos, *saveprefix;
 	savedir = (char *) strdup (".");
 	slashpos = strrchr (filename, '/');
 	if (slashpos) {
@@ -279,10 +291,17 @@ int edit_save_file (WEdit * edit, const
 	}
 	if (savename)
 	    free (savename);
-	savename = (char *) tempnam (savedir, "cooledit");
+	saveprefix = concat_dir_and_file (savedir, "cooledit");
+	fd = mc_mkstemps(&savename, saveprefix, NULL);
+	g_free (saveprefix);
 	free (savedir);
 	if (!savename)
 	    return 0;
+	/*
+	 * Close for now because it needs to be reopened by
+	 * VFS-aware mc_open() and MY_O_TEXT should be used.
+	 */
+	close (fd);
     }

     if ((fd = open (savename, O_CREAT | O_WRONLY | O_TRUNC | MY_O_TEXT,
---------------------------------------------

-- 
Regards,
Pavel Roskin





More information about the mc-devel mailing list