Changeset d219296


Ignore:
Timestamp:
2012-06-05T19:47:22Z (8 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
222b440
Parents:
00f1e93
Message:

Small cleanup of xml_save().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    r00f1e93 rd219296  
    174174        struct xt_node *node;
    175175        storage_status_t ret = STORAGE_OTHER_ERROR;
    176         char *nick;
    177176       
    178177        xd->irc = irc;
     
    246245
    247246
    248 static gboolean xml_save_nick( gpointer key, gpointer value, gpointer data );
     247static gboolean xml_generate_nick( gpointer key, gpointer value, gpointer data );
    249248
    250249struct xt_node *xml_generate( irc_t *irc )
     
    320319                   return TRUE on write errors. Which means, if we found
    321320                   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 );
    323322               
    324323                xt_add_child( root, cur );
     
    352351static storage_status_t xml_save( irc_t *irc, int overwrite )
    353352{
    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;
    356357        int fd;
    357358       
    358359        path2 = g_strdup( irc->user->nick );
    359360        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" );
    361362        g_free( path2 );
    362363       
     
    373374        tree = xml_generate( irc );
    374375        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;
    379381       
    380382        path2 = g_strndup( path, strlen( path ) - 7 );
    381383        if( rename( path, path2 ) != 0 )
    382384        {
    383                 irc_rootmsg( irc, "Error while renaming temporary configuration file." );
    384                
    385385                g_free( path2 );
    386                 unlink( path );
    387                
    388                 return STORAGE_OTHER_ERROR;
    389         }
    390        
     386                goto error;
     387        }
    391388        g_free( path2 );
    392389       
    393         return STORAGE_OK;
    394 
    395 write_error:
    396        
     390        goto finish;
     391
     392error:
    397393        irc_rootmsg( irc, "Write error. Disk full?" );
     394        ret = STORAGE_OTHER_ERROR;
     395
     396finish:
    398397        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
     405static gboolean xml_generate_nick( gpointer key, gpointer value, gpointer data )
    404406{
    405407        struct xt_node *node = xt_new_node( "buddy", NULL, NULL );
     
    410412        return FALSE;
    411413}
     414
    412415
    413416static storage_status_t xml_remove( const char *nick, const char *password )
Note: See TracChangeset for help on using the changeset viewer.