1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
Write to temporary file and then rename.
Same approach like I did for bug 463072.
Fixes loss of data when disk is full.
Index: xchat-2.8.8/src/common/text.c
===================================================================
--- xchat-2.8.8.orig/src/common/text.c 2012-09-30 14:26:18.000000000 +0000
+++ xchat-2.8.8/src/common/text.c 2012-09-30 14:26:18.000000000 +0000
@@ -2332,23 +2332,43 @@
sound_save ()
{
int fd, i;
+ ssize_t nb;
char buf[512];
- fd = xchat_open_file ("sound.conf", O_CREAT | O_TRUNC | O_WRONLY, 0x180,
+ fd = xchat_open_file ("sound.conf.bug147832", O_CREAT | O_TRUNC | O_WRONLY, 0x180,
XOF_DOMODE);
if (fd == -1)
return;
+ nb = 1;
+
for (i = 0; i < NUM_XP; i++)
{
if (sound_files[i] && sound_files[i][0])
{
- write (fd, buf, snprintf (buf, sizeof (buf),
+ if( nb > 0 ) nb = write (fd, buf, snprintf (buf, sizeof (buf),
"event=%s\n", te[i].name));
- write (fd, buf, snprintf (buf, sizeof (buf),
+ if( nb > 0 ) nb = write (fd, buf, snprintf (buf, sizeof (buf),
"sound=%s\n\n", sound_files[i]));
}
}
- close (fd);
+ if( nb <= 0 )
+ {
+ fprintf( stderr, "sound_save: write() failed\n" );
+ close( fd );
+ return;
+ }
+
+ if( close (fd) != 0 )
+ {
+ perror( "sound_save: close() failed" );
+ return;
+ }
+
+ if( xchat_rename_file( "sound.conf.bug147832", "sound.conf", XOF_DOMODE ) != 0 )
+ {
+ perror( "sound_save: xchat_rename_file() failed" );
+ return;
+ }
}
|