X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/e7eb3a2744aa45179daea235800753d3d1955338..85db49a59d75229b893047fceab4667c4fdef851:/server/server-queue.c diff --git a/server/server-queue.c b/server/server-queue.c index a1fa181..88e7723 100644 --- a/server/server-queue.c +++ b/server/server-queue.c @@ -18,11 +18,17 @@ #include "disorder-server.h" /* the head of the queue is played next, so normally we add to the tail */ -struct queue_entry qhead = { &qhead, &qhead, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +struct queue_entry qhead = { + .next = &qhead, + .prev = &qhead +}; /* the head of the recent list is the oldest thing, the tail the most recently * played */ -struct queue_entry phead = { &phead, &phead, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +struct queue_entry phead = { + .next = &phead, + .prev = &phead +}; long pcount; @@ -59,6 +65,7 @@ static void queue_do_read(struct queue_entry *head, const char *path) { char *buffer; FILE *fp; struct queue_entry *q; + int ver = 0; if(!(fp = fopen(path, "r"))) { if(errno == ENOENT) @@ -67,8 +74,31 @@ static void queue_do_read(struct queue_entry *head, const char *path) { } head->next = head->prev = head; while(!inputline(path, fp, &buffer, '\n')) { + if(buffer[0] == '#') { + /* Version indicator */ + ver = atoi(buffer + 1); + continue; + } q = xmalloc(sizeof *q); queue_unmarshall(q, buffer, queue_read_error, (void *)path); + if(ver < 1) { + /* Fix up origin field as best we can; will be wrong in some cases but + * hopefully not too horribly so. */ + q->origin = q->submitter ? origin_picked : origin_random; + /* Eliminated obsolete states, since they are assumed elsewhere not to be + * set. */ + switch(q->state) { + case playing_isscratch: + q->origin = origin_scratch; + q->state = playing_unplayed; + break; + case playing_random: + q->state = playing_unplayed; + break; + default: + break; + } + } if(head == &qhead && (!q->track || !q->when)) @@ -103,6 +133,9 @@ static void queue_do_write(const struct queue_entry *head, const char *path) { byte_xasprintf(&tmp, "%s.new", path); if(!(fp = fopen(tmp, "w"))) fatal(errno, "error opening %s", tmp); + /* Save version indicator */ + if(fprintf(fp, "#1\n") < 0) + fatal(errno, "error writing %s", tmp); for(q = head->next; q != head; q = q->next) if(fprintf(fp, "%s\n", queue_marshall(q)) < 0) fatal(errno, "error writing %s", tmp);