svn commit: trunk/busybox/editors
vda at busybox.net
vda at busybox.net
Sat May 3 04:36:00 PDT 2008
Author: vda
Date: 2008-05-03 04:35:59 -0700 (Sat, 03 May 2008)
New Revision: 21928
Log:
vi: do not truncate file to zero length. closes bug 2944.
function old new delta
file_write 98 104 +6
Modified:
trunk/busybox/editors/vi.c
Changeset:
Modified: trunk/busybox/editors/vi.c
===================================================================
--- trunk/busybox/editors/vi.c 2008-05-03 07:21:27 UTC (rev 21927)
+++ trunk/busybox/editors/vi.c 2008-05-03 11:35:59 UTC (rev 21928)
@@ -2437,11 +2437,16 @@
return -2;
}
charcnt = 0;
- fd = open(fn, (O_WRONLY | O_CREAT | O_TRUNC), 0666);
+ /* By popular request we do not open file with O_TRUNC,
+ * but instead ftruncate() it _after_ successful write.
+ * Might reduce amount of data lost on power fail etc.
+ */
+ fd = open(fn, (O_WRONLY | O_CREAT), 0666);
if (fd < 0)
return -1;
cnt = last - first + 1;
charcnt = full_write(fd, first, cnt);
+ ftruncate(fd, charcnt);
if (charcnt == cnt) {
// good write
//file_modified = FALSE; // the file has not been modified
More information about the busybox-cvs
mailing list