-
Per Cederqvist authored
"struct dbfile". Add a database version field to that struct, and remove the global database format variables. This allows lyskomd to have files in different versions open at the same time, so that it can convert format X to format X+1 on the fly. (This is more preparation for bug 1616.) * src/server/ram-io.h (struct dbfile): New struct. (dbfile_delete): New function. (set_output_format): New function. (dbfile_open_write): New function. (dbfile_open_read): New function. (dump_dbfile_stats): New function. (dbfile_ftell): The argument is now a struct dbfile*, not FILE*. (dbfile_getc): Ditto. (dbfile_ungetc): Ditto. * src/server/ram-io.c (output_format): Moved from ram-output.c and made static variable. This defines the output format of all struct dbfile objects created after a change to the variable. (nr_dbfile_objects): New static statistics variable. (nr_dbfile_files): New static statistics variable. (dbfile_new): New static function. (dbfile_delete): New function. (set_output_format): Moved from ram-output.c. (get_version): Moved from simple-cache.c. Changed return type to int. The argument is an open dbfile, not a file name. Use dbfile_getc() instead of getc(). (dbfile_open_read): New function. (dbfile_open_write): New function. (dump_dbfile_stats): New function. (dbfile_ftell): The argument is now a struct dbfile*, not FILE*. (dbfile_getc): Ditto. (dbfile_ungetc): Ditto. * src/server/conference.c: Include ram-io.h, since local-to-global.h needs it. * src/server/memory.c: Ditto. * src/server/person.c: Ditto. * src/server/prot-a-output.c: Ditto. * src/server/text.c: Ditto. * src/server/membership.c: Include ram-io.h. (read_ranges_postcondition): Set up a dbfile wrapper around stderr for the report created if check_membership() fails. * src/server/local-to-global.h, src/server/local-to-global.c (l2g_read): The fp argument is now a struct dbfile*, not a FILE*. * src/server/dbck.c (oformat): Removed. The format is stored inside the dbfile struct instead. (main): Report an error message if an attempt to use an undefined output format is detected. * src/server/dbck-cache.c: Change all FILE* that refer to the status files to struct dbfile* in all functions, and made appropriate changes. Use fp->format instead of the global variable oformat or data_file_version. (get_version): Moved to ram-io.c. (sync_output_header): Removed the oformat argument. Use fp->format instead. All callers updated. (cache_sync_all): Use dbfile_open_write() instead of i_fopen(), and dbfile_delete() instead of i_fclose(). (init_cache): Removed the data_file_version variable, as the format is now stored inside the dbfile struct. Use dbfile_open_read() instead of i_fopen(), and dbfile_delete() instead of i_fclose(). * doc/lyskomd.texi (Modifying Stored Types): The default database format is now defined in ram-io.c, and nowhere else. It is preferrable if lyskomd is able to convert an old format to a new one after an upgrade. * src/server/testsuite/test-l2g.c (main): Added a dbfile wrapper around stdin in call to l2g_read(), and another around stderr in call to l2g_write(). * src/server/testsuite/Makefile.am (test_l2g_LDADD): Include libeintr.a. * src/server/simple-cache.c: Change all FILE* that refer to the status files to struct dbfile* in all functions, and made appropriate changes. (pre_sync): Use dbfile_delete() instead of i_fclose(), and dbfile_open_write() instead of i_fopen(). (post_sync): Use dbfile_delete() instead of i_fclose(), and dbfile_open_read() instead of i_fopen(). (save_one_text): Use dbfile_delete() instead of i_fclose(), and dbfile_open_read() instead of i_fopen(). (sync_part): Use dbfile_delete() instead of i_fclose(). (init_cache): Removed local variable datafile_version; use fp->format instead. Use dbfile_open_read() instead of i_fopen(). Removed call to set_input_format(), as dbfile_open_read() does the same thing. (free_all_cache): Use dbfile_delete() instead of i_fclose(). * src/server/ramkomd.c (dump_exit_statistics): Dump dbfile stats. * src/server/ram-parse.h, src/server/ram-parse.c: Change all FILE* that refer to the status files to struct dbfile* in all functions, and made appropriate changes. (set_input_format): Removed. * src/server/ram-parse.c (input_format): Removed. All users changed to use fp->format instead, so that lyskomd can read files with different versions at the same time. (fparse_text_stat_2): Code cleanup. (fparse_text_stat_0): Use dbfile_ungetc() instead of ungetc(). * src/server/ram-output.h, src/server/ram-output.c: Change all FILE* that refer to the status files to struct dbfile* in all functions, and made appropriate changes. (output_format): Moved to ram-io.c and made static. (set_output_format): Moved to ram-io.c.
554e4c59