Skip to content

Commit

Permalink
Added some cleanup of background files
Browse files Browse the repository at this point in the history
  • Loading branch information
stonehouse committed Mar 22, 2017
1 parent 44bce3e commit 433fa01
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion T-Minus/tminus.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,38 @@ Connection* Database_open(const char *filename)
return conn;
}


int Countdown_cleanUpBackgroundFile(Countdown ctdn)
{
char *bgPath = ctdn.background;
FILE *file = fopen(bgPath, "r");
if (file) {
fclose(file);
int rc = remove(bgPath);
if (rc != 0) {
printf("Error(%d) cleaning up background file at path '%s'", rc, bgPath);
return 0;
} else {
printf("Background file cleaned up successfully");
}
}

return 1;
}

Countdown* Countdown_getIndex(Connection *conn, int index)
{
Countdown ctdn = conn->db->rows[index];

long diff = difftime(ctdn.deadline, time(NULL));

if (ctdn.deadline == 0 || diff <= 0) {
if (ctdn.deadline == 0) {
// Empty DB row
return NULL;
} else if (diff <= 0) {
// Countdown exceeded, clean up and empty row
Countdown_cleanUpBackgroundFile(ctdn);
Database_createRow(conn, index);
return NULL;
} else {
Countdown *ptr = malloc(sizeof(Countdown));
Expand Down

0 comments on commit 433fa01

Please sign in to comment.