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)
{
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;
}
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);
}
char *name;
gboolean (*init) (struct linestack_context *,
const char *name,
+ gboolean truncate,
struct ctrlproxy_config *,
const struct irc_network_state *
);
* @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);
}
static gboolean file_init(struct linestack_context *ctx, const char *name,
+ gboolean truncate,
struct ctrlproxy_config *config,
const struct irc_network_state *state)
{
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);
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);
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);
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);
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");
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);
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);
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");
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;