Initial work not truncating existing linestack data.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 13 Apr 2009 16:53:00 +0000 (18:53 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 13 Apr 2009 16:53:00 +0000 (18:53 +0200)
src/linestack.c
src/linestack.h
src/linestack_file.c
testsuite/test-linestack.c

index f8038b9c0d089672168f33697a1e007950435b2d..874158c33a1ff5120690d87583664151081660c0 100644 (file)
@@ -34,6 +34,7 @@ void register_linestack(const struct linestack_ops *b)
 
 struct linestack_context *create_linestack(const struct linestack_ops *ops, 
                                                                                   const char *name, 
+                                                                                  gboolean truncate,
                                                                                   struct ctrlproxy_config *cfg,
                                                                                   const struct irc_network_state *state)
 {
@@ -45,7 +46,7 @@ struct linestack_context *create_linestack(const struct linestack_ops *ops,
 
        ctx = g_new0(struct linestack_context, 1);
        ctx->ops = ops;
-       ops->init(ctx, name, cfg, state);
+       ops->init(ctx, name, truncate, cfg, state);
 
        return ctx;
 }
@@ -385,7 +386,7 @@ struct linestack_context *new_linestack(struct irc_network *n, struct ctrlproxy_
                current_backend = &linestack_file;
        }
 
-       return create_linestack(current_backend, n->name, cfg, n->external_state);
+       return create_linestack(current_backend, n->name, TRUE, cfg, n->external_state);
 }
 
 
index 2edd905e9480b18e3be12955e5379d5a6647c3b6..fc271dd3044369feaa1d964a04fe0c748dea9fe8 100644 (file)
@@ -64,6 +64,7 @@ struct linestack_ops {
        char *name;
        gboolean (*init) (struct linestack_context *, 
                                          const char *name,
+                                         gboolean truncate,
                                          struct ctrlproxy_config *,
                                          const struct irc_network_state *
                                          );
@@ -167,7 +168,7 @@ G_MODULE_EXPORT struct linestack_marker *linestack_get_marker(struct linestack_c
  * @param cfg CtrlProxy configuration
  * @param state Current network state
  */
-G_MODULE_EXPORT struct linestack_context *create_linestack(const struct linestack_ops *, const char *name, struct ctrlproxy_config *, const struct irc_network_state *);
+G_MODULE_EXPORT struct linestack_context *create_linestack(const struct linestack_ops *, const char *name, gboolean truncate, struct ctrlproxy_config *, const struct irc_network_state *);
 G_MODULE_EXPORT void free_linestack_context(struct linestack_context *);
 G_MODULE_EXPORT struct linestack_ops *linestack_find_ops(const char *name);
 
index 7489060040c025f6d2fae22a59d1972801eca746..116a7812df326f65cc28a5c60d5ddcaa9d6569f2 100644 (file)
@@ -484,6 +484,7 @@ static char *global_init(struct ctrlproxy_config *config)
 }
 
 static gboolean file_init(struct linestack_context *ctx, const char *name, 
+                                                 gboolean truncate,
                                                  struct ctrlproxy_config *config, 
                                                  const struct irc_network_state *state)
 {
@@ -492,17 +493,26 @@ static gboolean file_init(struct linestack_context *ctx, const char *name,
        GError *error = NULL;
        const char *fname;
        GDir *dir;
+       const char *mode;
 
        parent_dir = global_init(config);
 
        data_dir = g_build_filename(parent_dir, name, NULL);
+       g_assert(data_dir != NULL);
+
        g_free(parent_dir);
        g_mkdir(data_dir, 0700);
        data_file = g_build_filename(data_dir, "lines", NULL);
+       g_assert(data_file != NULL);
 
        unlink(data_file);
 
-       data->line_file = g_io_channel_new_file(data_file, "w+", &error);
+       if (truncate)
+               mode = "w+";
+       else
+               mode = "a+";
+
+       data->line_file = g_io_channel_new_file(data_file, mode, &error);
        if (data->line_file == NULL) {
                log_global(LOG_WARNING, "Error opening `%s': %s", 
                                                  data_file, error->message);
index b03e458c992f379e02b631ec02190124bda4a67f..019a235afc073007c9142e2b1b272d114bfb53fb 100644 (file)
@@ -192,7 +192,7 @@ START_TEST(test_empty)
        struct linestack_context *ctx;
        
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");
-       ctx = create_linestack(&linestack_file, "test", my_config, ns1);
+       ctx = create_linestack(&linestack_file, "test", TRUE, my_config, ns1);
 
        ns2 = linestack_get_state(ctx, NULL);
 
@@ -210,7 +210,7 @@ START_TEST(test_msg)
        char *raw;
        
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");
-       ctx = create_linestack(&linestack_file, "test", my_config, ns1);
+       ctx = create_linestack(&linestack_file, "test", TRUE, my_config, ns1);
 
        lm = linestack_get_marker(ctx);
 
@@ -243,7 +243,7 @@ START_TEST(test_join_part)
        char *raw;
        
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");
-       ctx = create_linestack(&linestack_file, "test", my_config, ns1);
+       ctx = create_linestack(&linestack_file, "test", TRUE, my_config, ns1);
 
        lm = linestack_get_marker(ctx);
 
@@ -278,7 +278,7 @@ START_TEST(test_skip_msg)
        char *raw;
        
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");
-       ctx = create_linestack(&linestack_file, "test", my_config, ns1);
+       ctx = create_linestack(&linestack_file, "test", TRUE, my_config, ns1);
 
        stack_process(ctx, ns1, ":bloe!Gebruikersnaam@Computernaam PRIVMSG #bla :haha");
 
@@ -313,7 +313,7 @@ START_TEST(test_object_msg)
        char *raw;
        
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");
-       ctx = create_linestack(&linestack_file, "test", my_config, ns1);
+       ctx = create_linestack(&linestack_file, "test", TRUE, my_config, ns1);
 
        lm = linestack_get_marker(ctx);
 
@@ -353,7 +353,7 @@ START_TEST(test_object_open)
        int j;
        
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");
-       ctx = create_linestack(&linestack_file, "test", my_config, ns1);
+       ctx = create_linestack(&linestack_file, "test", TRUE, my_config, ns1);
 
        lm = linestack_get_marker(ctx);
 
@@ -387,7 +387,7 @@ START_TEST(test_join)
        struct linestack_context *ctx;
        
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");
-       ctx = create_linestack(&linestack_file, "test", my_config, ns1);
+       ctx = create_linestack(&linestack_file, "test", TRUE, my_config, ns1);
 
        stack_process(ctx, ns1, ":bla!Gebruikersnaam@Computernaam JOIN #bla");
 
@@ -413,7 +413,7 @@ START_TEST(bench_lots_of_lines)
        int i;
 
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");
-       ctx = create_linestack(&linestack_file, "test", my_config, ns1);
+       ctx = create_linestack(&linestack_file, "test", TRUE, my_config, ns1);
        marker = linestack_get_marker(ctx);
 
        seen = 0;