Skip to content

Commit

Permalink
sync_server: plumb archive flag all the way down to reservefile
Browse files Browse the repository at this point in the history
Sync files are a part of the dlist parser, so we need to let sync_server
pass a flag all the way down to where they're set up. This is ugly, but
there's not realy another way.

This commit doesn't actually set the flag, just threads it through.

Signed-off-by: Rob N ★ <robn@despairlabs.com>
  • Loading branch information
robn authored and elliefm committed Aug 10, 2022
1 parent 546f0ab commit eda66e4
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions backup/backupd.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ static void cmdloop(void)
if (!backupd_userid) goto nologin;
if (!strcmp(cmd.s, "Apply")) {
struct dlist *dl = NULL;
c = dlist_parse(&dl, /*parsekeys*/ 1, /*isbackup*/ 1, backupd_in);
c = dlist_parse(&dl, /*parsekeys*/ 1, /*isarchive*/ 0, /*isbackup*/ 1, backupd_in);
if (c == EOF) goto missingargs;
if (c == '\r') c = prot_getc(backupd_in);
if (c != '\n') goto extraargs;
Expand Down Expand Up @@ -681,7 +681,7 @@ static void cmdloop(void)
if (!backupd_userid) goto nologin;
if (!strcmp(cmd.s, "Get")) {
struct dlist *dl = NULL;
c = dlist_parse(&dl, /*parsekeys*/ 1, /*isbackup*/ 1, backupd_in);
c = dlist_parse(&dl, /*parsekeys*/ 1, /*isarchive*/ 0, /*isbackup*/ 1, backupd_in);
if (c == EOF) goto missingargs;
if (c == '\r') c = prot_getc(backupd_in);
if (c != '\n') goto extraargs;
Expand Down
2 changes: 1 addition & 1 deletion backup/lcb_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ HIDDEN int parse_backup_line(struct protstream *in, time_t *ts,
if (c == EOF)
goto fail;

c = dlist_parse(&dl, /*parsekeys*/ 1, 1, in);
c = dlist_parse(&dl, /*parsekeys*/ 1, /*isarchive*/ 0, 1, in);

if (!dl) {
fprintf(stderr, "\ndidn't parse dlist, error %i\n", c);
Expand Down
2 changes: 1 addition & 1 deletion imap/append.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ static int callout_receive_reply(const char *callout,
prot_setisclient(p, 1);

/* read and parse the reply as a dlist */
c = dlist_parse(results, /*parsekeys*/0, /*isbackup*/0, p);
c = dlist_parse(results, /*parsekeys*/0, /*isarchive*/0, /*isbackup*/0, p);
r = (c == EOF ? IMAP_SYS_ERROR : 0);

out:
Expand Down
16 changes: 8 additions & 8 deletions imap/dlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ EXPORTED const char *dlist_reserve_path(const char *part, int isarchive, int isb

static int reservefile(struct protstream *in, const char *part,
struct message_guid *guid, unsigned long size,
int isbackup, const char **fname)
int isarchive, int isbackup, const char **fname)
{
static struct message_guid debug_writefail_guid = MESSAGE_GUID_INITIALIZER;
FILE *file;
Expand All @@ -197,7 +197,7 @@ static int reservefile(struct protstream *in, const char *part,
}

/* XXX - write to a temporary file then move in to place! */
*fname = dlist_reserve_path(part, /*isarchive*/0, isbackup, guid);
*fname = dlist_reserve_path(part, isarchive, isbackup, guid);

/* remove any duplicates if they're still here */
unlink(*fname);
Expand Down Expand Up @@ -1101,7 +1101,7 @@ static char next_nonspace(struct protstream *in, char c)
return c;
}

EXPORTED int dlist_parse(struct dlist **dlp, int parsekey, int isbackup,
EXPORTED int dlist_parse(struct dlist **dlp, int parsekey, int isarchive, int isbackup,
struct protstream *in)
{
struct dlist *dl = NULL;
Expand Down Expand Up @@ -1129,7 +1129,7 @@ EXPORTED int dlist_parse(struct dlist **dlp, int parsekey, int isbackup,
while (c != ')') {
struct dlist *di = NULL;
prot_ungetc(c, in);
c = dlist_parse(&di, 0, isbackup, in);
c = dlist_parse(&di, 0, isarchive, isbackup, in);
if (di) dlist_stitch(dl, di);
c = next_nonspace(in, c);
if (c == EOF) goto fail;
Expand All @@ -1145,7 +1145,7 @@ EXPORTED int dlist_parse(struct dlist **dlp, int parsekey, int isbackup,
while (c != ')') {
struct dlist *di = NULL;
prot_ungetc(c, in);
c = dlist_parse(&di, 1, isbackup, in);
c = dlist_parse(&di, 1, isarchive, isbackup, in);
if (di) dlist_stitch(dl, di);
c = next_nonspace(in, c);
if (c == EOF) goto fail;
Expand All @@ -1166,7 +1166,7 @@ EXPORTED int dlist_parse(struct dlist **dlp, int parsekey, int isbackup,
if (c == '\r') c = prot_getc(in);
if (c != '\n') goto fail;
if (!message_guid_decode(&tmp_guid, gbuf.s)) goto fail;
if (reservefile(in, pbuf.s, &tmp_guid, size, isbackup, &fname)) goto fail;
if (reservefile(in, pbuf.s, &tmp_guid, size, isarchive, isbackup, &fname)) goto fail;
dl = dlist_setfile(NULL, kbuf.s, pbuf.s, &tmp_guid, size, fname);
/* file literal */
}
Expand Down Expand Up @@ -1205,7 +1205,7 @@ EXPORTED int dlist_parse(struct dlist **dlp, int parsekey, int isbackup,
EXPORTED int dlist_parse_asatomlist(struct dlist **dlp, int parsekey,
struct protstream *in)
{
int c = dlist_parse(dlp, parsekey, 0, in);
int c = dlist_parse(dlp, parsekey, 0, 0, in);

/* make a list with one item */
if (*dlp && !dlist_isatomlist(*dlp)) {
Expand All @@ -1226,7 +1226,7 @@ EXPORTED int dlist_parsemap(struct dlist **dlp, int parsekey, int isbackup,

stream = prot_readmap(base, len);
prot_setisclient(stream, 1); /* don't sync literals */
c = dlist_parse(&dl, parsekey, isbackup, stream);
c = dlist_parse(&dl, parsekey, /*isarchive*/ 0, isbackup, stream);
prot_free(stream);

if (c != EOF) {
Expand Down
2 changes: 1 addition & 1 deletion imap/dlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void dlist_print(const struct dlist *dl, int printkeys,
struct protstream *out);
void dlist_printbuf(const struct dlist *dl, int printkeys,
struct buf *outbuf);
int dlist_parse(struct dlist **dlp, int parsekeys, int isbackup,
int dlist_parse(struct dlist **dlp, int parsekeys, int isarchive, int isbackup,
struct protstream *in);
int dlist_parse_asatomlist(struct dlist **dlp, int parsekey,
struct protstream *in);
Expand Down
6 changes: 3 additions & 3 deletions imap/imapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ static void cmdloop(void)
else if (!strcmp(cmd.s, "Syncapply")) {
if (!imapd_userisadmin) goto badcmd;

struct dlist *kl = sync_parseline(imapd_in);
struct dlist *kl = sync_parseline(imapd_in, /*isarchive*/ 0);

if (kl) {
cmd_syncapply(tag.s, kl, reserve_list);
Expand All @@ -2093,7 +2093,7 @@ static void cmdloop(void)
else if (!strcmp(cmd.s, "Syncget")) {
if (!imapd_userisadmin) goto badcmd;

struct dlist *kl = sync_parseline(imapd_in);
struct dlist *kl = sync_parseline(imapd_in, /*isarchive*/ 0);

if (kl) {
cmd_syncget(tag.s, kl);
Expand All @@ -2112,7 +2112,7 @@ static void cmdloop(void)
else if (!strcmp(cmd.s, "Syncrestore")) {
if (!imapd_userisadmin) goto badcmd;

struct dlist *kl = sync_parseline(imapd_in);
struct dlist *kl = sync_parseline(imapd_in, /*isarchive*/ 0);

if (kl) {
cmd_syncrestore(tag.s, kl, reserve_list);
Expand Down
2 changes: 1 addition & 1 deletion imap/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void notify_dlist(const char *sockpath, const char *method,
prot_printf(out, "\r\n");
prot_flush(out);

c = dlist_parse(&res, 1, 0, in);
c = dlist_parse(&res, 1, 0, 0, in);
if (c == '\r') c = prot_getc(in);
/* XXX - do something with the response? Like have NOTIFY answer */
if (c == '\n' && res && res->name) {
Expand Down
6 changes: 3 additions & 3 deletions imap/sync_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ static void cmdloop(void)
}
if (!sync_userid) goto nologin;
if (!strcmp(cmd.s, "Apply")) {
kl = sync_parseline(sync_in);
kl = sync_parseline(sync_in, /*isarchive*/ 0);
if (kl) {
cmd_apply(kl, reserve_list);
dlist_free(&kl);
Expand Down Expand Up @@ -585,7 +585,7 @@ static void cmdloop(void)
case 'G':
if (!sync_userid) goto nologin;
if (!strcmp(cmd.s, "Get")) {
kl = sync_parseline(sync_in);
kl = sync_parseline(sync_in, /*isarchive*/ 0);
if (kl) {
cmd_get(kl);
dlist_free(&kl);
Expand Down Expand Up @@ -629,7 +629,7 @@ static void cmdloop(void)
}
if (!sync_userid) goto nologin;
if (!strcmp(cmd.s, "Restore")) {
kl = sync_parseline(sync_in);
kl = sync_parseline(sync_in, /*isarchive*/ 0);
if (kl) {
cmd_restore(kl, reserve_list);
dlist_free(&kl);
Expand Down
6 changes: 3 additions & 3 deletions imap/sync_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1830,12 +1830,12 @@ void sync_eatline(struct protstream *pin, int c)
}
}

struct dlist *sync_parseline(struct protstream *in)
struct dlist *sync_parseline(struct protstream *in, int isarchive)
{
struct dlist *dl = NULL;
int c;

c = dlist_parse(&dl, 1, 0, in);
c = dlist_parse(&dl, 1, isarchive, 0, in);

/* end line - or fail */
if (c == '\r') c = prot_getc(in);
Expand Down Expand Up @@ -2051,7 +2051,7 @@ int sync_parse_response(const char *cmd, struct protstream *in,

kl = dlist_newlist(NULL, cmd);
while (!strcmp(response.s, "*")) {
struct dlist *item = sync_parseline(in);
struct dlist *item = sync_parseline(in, /*isarchive*/ 0);
if (!item) goto parse_err;
dlist_stitch(kl, item);
if ((c = getword(in, &response)) == EOF)
Expand Down
2 changes: 1 addition & 1 deletion imap/sync_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void sync_send_lookup(struct dlist *kl, struct protstream *out);
void sync_send_restart(struct protstream *out);
void sync_send_restore(struct dlist *kl, struct protstream *out);

struct dlist *sync_parseline(struct protstream *in);
struct dlist *sync_parseline(struct protstream *in, int isarchive);

/* ====================================================================== */

Expand Down

0 comments on commit eda66e4

Please sign in to comment.