Changeset d219296
- Timestamp:
- 2012-06-05T19:47:22Z (12 years ago)
- Branches:
- master
- Children:
- 222b440
- Parents:
- 00f1e93
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
storage_xml.c
r00f1e93 rd219296 174 174 struct xt_node *node; 175 175 storage_status_t ret = STORAGE_OTHER_ERROR; 176 char *nick;177 176 178 177 xd->irc = irc; … … 246 245 247 246 248 static gboolean xml_ save_nick( gpointer key, gpointer value, gpointer data );247 static gboolean xml_generate_nick( gpointer key, gpointer value, gpointer data ); 249 248 250 249 struct xt_node *xml_generate( irc_t *irc ) … … 320 319 return TRUE on write errors. Which means, if we found 321 320 something, there was an error. :-) */ 322 g_hash_table_find( acc->nicks, xml_ save_nick, cur );321 g_hash_table_find( acc->nicks, xml_generate_nick, cur ); 323 322 324 323 xt_add_child( root, cur ); … … 352 351 static storage_status_t xml_save( irc_t *irc, int overwrite ) 353 352 { 354 char path[512], *path2, *xml; 355 struct xt_node *tree; 353 storage_status_t ret = STORAGE_OK; 354 char path[512], *path2 = NULL, *xml = NULL; 355 struct xt_node *tree = NULL; 356 size_t len; 356 357 int fd; 357 358 358 359 path2 = g_strdup( irc->user->nick ); 359 360 nick_lc( path2 ); 360 g_snprintf( path, sizeof( path ) - 2 , "%s%s%s", global.conf->configdir, path2, ".xml" );361 g_snprintf( path, sizeof( path ) - 20, "%s%s%s", global.conf->configdir, path2, ".xml" ); 361 362 g_free( path2 ); 362 363 … … 373 374 tree = xml_generate( irc ); 374 375 xml = xt_to_string( tree ); 375 write( fd, xml, strlen( xml ) ); 376 377 fsync( fd ); 378 close( fd ); 376 len = strlen( xml ); 377 if( write( fd, xml, len ) != len || 378 fsync( fd ) != 0 || /* #559 */ 379 close( fd ) != 0 ) 380 goto error; 379 381 380 382 path2 = g_strndup( path, strlen( path ) - 7 ); 381 383 if( rename( path, path2 ) != 0 ) 382 384 { 383 irc_rootmsg( irc, "Error while renaming temporary configuration file." );384 385 385 g_free( path2 ); 386 unlink( path ); 387 388 return STORAGE_OTHER_ERROR; 389 } 390 386 goto error; 387 } 391 388 g_free( path2 ); 392 389 393 return STORAGE_OK; 394 395 write_error: 396 390 goto finish; 391 392 error: 397 393 irc_rootmsg( irc, "Write error. Disk full?" ); 394 ret = STORAGE_OTHER_ERROR; 395 396 finish: 398 397 close( fd ); 399 400 return STORAGE_OTHER_ERROR; 401 } 402 403 static gboolean xml_save_nick( gpointer key, gpointer value, gpointer data ) 398 unlink( path ); 399 g_free( xml ); 400 xt_free_node( tree ); 401 402 return ret; 403 } 404 405 static gboolean xml_generate_nick( gpointer key, gpointer value, gpointer data ) 404 406 { 405 407 struct xt_node *node = xt_new_node( "buddy", NULL, NULL ); … … 410 412 return FALSE; 411 413 } 414 412 415 413 416 static storage_status_t xml_remove( const char *nick, const char *password )
Note: See TracChangeset
for help on using the changeset viewer.