From: <ro...@us...> - 2006-06-18 22:46:38
|
Revision: 16278 Author: roast Date: 2006-06-18 15:46:32 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16278&view=rev Log Message: ----------- logging now truncates and writes logfiles; added code to eliminate collisions. Modified Paths: -------------- branches/soc-2006-file-loggers/src/log.c Modified: branches/soc-2006-file-loggers/src/log.c =================================================================== --- branches/soc-2006-file-loggers/src/log.c 2006-06-18 20:21:42 UTC (rev 16277) +++ branches/soc-2006-file-loggers/src/log.c 2006-06-18 22:46:32 UTC (rev 16278) @@ -687,13 +687,37 @@ date, tz, ext ? ext : ""); path = g_build_filename(dir, filename, NULL); - g_free(tz); - g_free(dir); g_free(filename); + /* since we're truncating now, test if file exists. if so, append ".[a-z]" to filename and stop */ + if (g_file_test(path, G_FILE_TEST_EXISTS)) { + char suffixchar = 'a'; + + do { + g_free(path); + filename = g_strdup_printf("%s_%s%s.%c%s", + gaim_escape_filename(gaim_normalize(log->account, log->name)), + date, tz, suffixchar, ext ? ext : ""); + path = g_build_filename(dir, filename, NULL); + g_free(filename); + + suffixchar++; + } while (g_file_test(path, G_FILE_TEST_EXISTS) && suffixchar <= 'z'); + + if (suffixchar == 'z' && g_file_test(path, G_FILE_TEST_EXISTS)) { + /* we have a collision problem. not logging, and complain. */ + gaim_conversation_write(log->conv, NULL, _("Logging of this conversation failed."), + GAIM_MESSAGE_ERROR, time(NULL)); + g_free(tz); + g_free(dir); + g_free(path); + return; + } + } + log->logger_data = data = g_slice_new0(GaimLogCommonLoggerData); - data->file = g_fopen(path, "a"); + data->file = g_fopen(path, "w+"); if (data->file == NULL) { gaim_debug(GAIM_DEBUG_ERROR, "log", @@ -702,6 +726,8 @@ if (log->conv != NULL) gaim_conversation_write(log->conv, NULL, _("Logging of this conversation failed."), GAIM_MESSAGE_ERROR, time(NULL)); + g_free(tz); + g_free(dir); g_free(path); return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |