[PATCH] Re: Issues to fix before 4.6.1?

2005-03-30 Thread Jindrich Novy
Hello Oswald,

On Tue, 2005-03-29 at 22:37 +0200, Oswald Buddenhagen wrote:
 On Tue, Mar 29, 2005 at 05:46:33PM +0200, Jindrich Novy wrote:
  On Tue, 2005-03-29 at 11:07 +0300, Andrew V. Samoilov wrote:
   There is a data loss possible if file is edited with external editor over 
   VFS.
  
  I have similar experience even with mcedit without VFS - data loss when
  disk quota is exceeded, the edited file is truncated to zero size. I had
  these problems with mc-4.5.51 so I'm not sure if it's still a problem
  with recent mc.
  
 i've had this just yesterday ... good luck it was no important file.
 this happens with the quick save mode ... it must, given the way it
 works. not sure it can be fixed properly at all without just switching
 to another mode. oh, well, it could be fixed to not lose data, but the
 resulting file would be a bit inconsistent.
 

Seems like mc still tests presence of a file on local filesystem in
rather brutal way when quick-saving:

if (!vfs_file_is_local (filename) ||
(fd = mc_open (filename, O_WRONLY | O_BINARY)) == -1)

what actually truncates the filename to zero size. The proposed patch
modifies the opening mode to O_RDONLY so that we shouldn't lose any data
at this point.

Furthermore I noticed ctype.h is #included redundantly twice in
edit_cmd.c. This fixes the second patch.

Jindrich

-- 
Jindrich Novy [EMAIL PROTECTED], http://people.redhat.com/jnovy/
--- mc/edit/editcmd.c.dontrewrite	2005-03-17 22:18:23.0 +0100
+++ mc/edit/editcmd.c	2005-03-30 09:28:25.076282176 +0200
@@ -240,7 +240,7 @@ edit_save_file (WEdit *edit, const char 
 }
 
 if (!vfs_file_is_local (filename) ||
-	(fd = mc_open (filename, O_WRONLY | O_BINARY)) == -1) {
+	(fd = mc_open (filename, O_RDONLY | O_BINARY)) == -1) {
 	/*
 	 * The file does not exists yet, so no safe save or
 	 * backup are necessary.
--- mc/edit/editcmd.c.ctype	2005-03-17 22:18:23.0 +0100
+++ mc/edit/editcmd.c	2005-03-30 10:05:48.983156480 +0200
@@ -24,7 +24,6 @@
 /* #define PIPE_BLOCKS_SO_READ_BYTE_BY_BYTE */
 
 #include config.h
-#include ctype.h
 
 #include stdio.h
 #include stdarg.h
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel


Re: [PATCH] Re: Issues to fix before 4.6.1?

2005-03-30 Thread Oswald Buddenhagen
On Wed, Mar 30, 2005 at 10:11:19AM +0200, Jindrich Novy wrote:
 if (!vfs_file_is_local (filename) ||
 (fd = mc_open (filename, O_WRONLY | O_BINARY)) == -1)
 
 what actually truncates the filename to zero size.

it does not, unless mc_open has totally misleading semantics - there is
no O_TRUNCATE. the truncation comes during the actual write ... which
leaves us with a truncated/empty file, if we run out-of-space in the
middle.
the solution would be not to use O_TRUNCATE at all. instead, first
write the part that extends beyond the end of the old file. if that
fails to complete, truncate to the old length. if we crash now, the old
file will have garbage appended, but at least it's not clobbered
alltogether. note that we cannot just seek to the new end and write one
byte because of sparse files. after the extension was written,
overwrite the start of the file with the new content and possibly
truncate the file to the new length. this is all sooo ugly ...

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel