Skip to content

Commit

Permalink
Config: Detect errors writing to file
Browse files Browse the repository at this point in the history
Print an error message telling the user no configuration will be
persisted when unable to write the config file.
  • Loading branch information
Zirias committed Jul 26, 2024
1 parent 72ee094 commit 113e3c7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/bin/xmoji/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,18 @@ Config *Config_create(const char *path)
self->reading = 0;
EmojiHistory_deserialize(self->history,
ConfigFile_get(self->cfg, keys[CFG_HISTORY]));
ConfigFile_write(self->cfg);
PSC_Event_register(ConfigFile_changed(self->cfg), self, filechanged, 0);
PSC_Event_register(EmojiHistory_changed(self->history), self,
historychanged, 0);
if (ConfigFile_write(self->cfg) >= 0)
{
PSC_Event_register(ConfigFile_changed(self->cfg), self,
filechanged, 0);
PSC_Event_register(EmojiHistory_changed(self->history), self,
historychanged, 0);
}
else
{
PSC_Log_fmt(PSC_L_ERROR, "Cannot write to `%s', giving up. Runtime "
"configuration will NOT be persisted.", self->cfgfile);
}
return self;
}

Expand Down

0 comments on commit 113e3c7

Please sign in to comment.