supplement open_box() with box existence information from list_store()
there is no point in trying to open a non-existing box before trying to create it.
This commit is contained in:
parent
7b7304b625
commit
926788f3ae
19
src/main.c
19
src/main.c
|
@ -513,7 +513,7 @@ main( int argc, char **argv )
|
||||||
|
|
||||||
static void store_opened( store_t *ctx, void *aux );
|
static void store_opened( store_t *ctx, void *aux );
|
||||||
static void store_listed( int sts, void *aux );
|
static void store_listed( int sts, void *aux );
|
||||||
static int sync_listed_boxes( main_vars_t *mvars, string_list_t *mbox );
|
static int sync_listed_boxes( main_vars_t *mvars, string_list_t *mbox, int present[] );
|
||||||
static void done_sync_dyn( int sts, void *aux );
|
static void done_sync_dyn( int sts, void *aux );
|
||||||
static void done_sync_2_dyn( int sts, void *aux );
|
static void done_sync_2_dyn( int sts, void *aux );
|
||||||
static void done_sync( int sts, void *aux );
|
static void done_sync( int sts, void *aux );
|
||||||
|
@ -641,15 +641,19 @@ sync_chans( main_vars_t *mvars, int ent )
|
||||||
mvars->done = mvars->cben = 0;
|
mvars->done = mvars->cben = 0;
|
||||||
if (mvars->boxlist) {
|
if (mvars->boxlist) {
|
||||||
while ((mbox = mvars->cboxes)) {
|
while ((mbox = mvars->cboxes)) {
|
||||||
|
int present[] = { BOX_PRESENT, BOX_PRESENT };
|
||||||
mvars->cboxes = mbox->next;
|
mvars->cboxes = mbox->next;
|
||||||
if (sync_listed_boxes( mvars, mbox ))
|
if (sync_listed_boxes( mvars, mbox, present ))
|
||||||
goto syncw;
|
goto syncw;
|
||||||
}
|
}
|
||||||
for (t = 0; t < 2; t++)
|
for (t = 0; t < 2; t++)
|
||||||
while ((mbox = mvars->boxes[t])) {
|
while ((mbox = mvars->boxes[t])) {
|
||||||
|
int present[2];
|
||||||
|
present[t] = BOX_PRESENT;
|
||||||
|
present[1-t] = BOX_ABSENT;
|
||||||
mvars->boxes[t] = mbox->next;
|
mvars->boxes[t] = mbox->next;
|
||||||
if ((mvars->chan->ops[1-t] & OP_MASK_TYPE) && (mvars->chan->ops[1-t] & OP_CREATE)) {
|
if ((mvars->chan->ops[1-t] & OP_MASK_TYPE) && (mvars->chan->ops[1-t] & OP_CREATE)) {
|
||||||
if (sync_listed_boxes( mvars, mbox ))
|
if (sync_listed_boxes( mvars, mbox, present ))
|
||||||
goto syncw;
|
goto syncw;
|
||||||
} else {
|
} else {
|
||||||
free( mbox );
|
free( mbox );
|
||||||
|
@ -657,7 +661,8 @@ sync_chans( main_vars_t *mvars, int ent )
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!mvars->list) {
|
if (!mvars->list) {
|
||||||
sync_boxes( mvars->ctx, mvars->chan->boxes, mvars->chan, done_sync, mvars );
|
int present[] = { BOX_POSSIBLE, BOX_POSSIBLE };
|
||||||
|
sync_boxes( mvars->ctx, mvars->chan->boxes, present, mvars->chan, done_sync, mvars );
|
||||||
mvars->skip = 1;
|
mvars->skip = 1;
|
||||||
syncw:
|
syncw:
|
||||||
mvars->cben = 1;
|
mvars->cben = 1;
|
||||||
|
@ -799,7 +804,7 @@ store_listed( int sts, void *aux )
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sync_listed_boxes( main_vars_t *mvars, string_list_t *mbox )
|
sync_listed_boxes( main_vars_t *mvars, string_list_t *mbox, int present[] )
|
||||||
{
|
{
|
||||||
if (mvars->chan->boxes[M] || mvars->chan->boxes[S]) {
|
if (mvars->chan->boxes[M] || mvars->chan->boxes[S]) {
|
||||||
const char *mpfx = nz( mvars->chan->boxes[M], "" );
|
const char *mpfx = nz( mvars->chan->boxes[M], "" );
|
||||||
|
@ -808,14 +813,14 @@ sync_listed_boxes( main_vars_t *mvars, string_list_t *mbox )
|
||||||
nfasprintf( &mvars->names[M], "%s%s", mpfx, mbox->string );
|
nfasprintf( &mvars->names[M], "%s%s", mpfx, mbox->string );
|
||||||
nfasprintf( &mvars->names[S], "%s%s", spfx, mbox->string );
|
nfasprintf( &mvars->names[S], "%s%s", spfx, mbox->string );
|
||||||
free( mbox );
|
free( mbox );
|
||||||
sync_boxes( mvars->ctx, (const char **)mvars->names, mvars->chan, done_sync_2_dyn, mvars );
|
sync_boxes( mvars->ctx, (const char **)mvars->names, present, mvars->chan, done_sync_2_dyn, mvars );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf( "%s%s <=> %s%s\n", mpfx, mbox->string, spfx, mbox->string );
|
printf( "%s%s <=> %s%s\n", mpfx, mbox->string, spfx, mbox->string );
|
||||||
} else {
|
} else {
|
||||||
if (!mvars->list) {
|
if (!mvars->list) {
|
||||||
mvars->names[M] = mvars->names[S] = mbox->string;
|
mvars->names[M] = mvars->names[S] = mbox->string;
|
||||||
sync_boxes( mvars->ctx, (const char **)mvars->names, mvars->chan, done_sync_dyn, mvars );
|
sync_boxes( mvars->ctx, (const char **)mvars->names, present, mvars->chan, done_sync_dyn, mvars );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
puts( mbox->string );
|
puts( mbox->string );
|
||||||
|
|
|
@ -930,7 +930,7 @@ static void box_opened2( sync_vars_t *svars, int t );
|
||||||
static void load_box( sync_vars_t *svars, int t, int minwuid, int *mexcs, int nmexcs );
|
static void load_box( sync_vars_t *svars, int t, int minwuid, int *mexcs, int nmexcs );
|
||||||
|
|
||||||
void
|
void
|
||||||
sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan,
|
sync_boxes( store_t *ctx[], const char *names[], int present[], channel_conf_t *chan,
|
||||||
void (*cb)( int sts, void *aux ), void *aux )
|
void (*cb)( int sts, void *aux ), void *aux )
|
||||||
{
|
{
|
||||||
sync_vars_t *svars;
|
sync_vars_t *svars;
|
||||||
|
@ -987,7 +987,10 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan,
|
||||||
sync_ref( svars );
|
sync_ref( svars );
|
||||||
for (t = 0; ; t++) {
|
for (t = 0; ; t++) {
|
||||||
info( "Opening %s box %s...\n", str_ms[t], svars->orig_name[t] );
|
info( "Opening %s box %s...\n", str_ms[t], svars->orig_name[t] );
|
||||||
svars->drv[t]->open_box( ctx[t], box_confirmed, AUX );
|
if (present[t] == BOX_ABSENT)
|
||||||
|
box_confirmed( DRV_BOX_BAD, AUX );
|
||||||
|
else
|
||||||
|
svars->drv[t]->open_box( ctx[t], box_confirmed, AUX );
|
||||||
if (t || check_cancel( svars ))
|
if (t || check_cancel( svars ))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,12 @@ extern const char *str_ms[2], *str_hl[2];
|
||||||
#define SYNC_NOGOOD 16 /* internal */
|
#define SYNC_NOGOOD 16 /* internal */
|
||||||
#define SYNC_CANCELED 32 /* internal */
|
#define SYNC_CANCELED 32 /* internal */
|
||||||
|
|
||||||
|
#define BOX_POSSIBLE -1
|
||||||
|
#define BOX_ABSENT 0
|
||||||
|
#define BOX_PRESENT 1
|
||||||
|
|
||||||
/* All passed pointers must stay alive until cb is called. */
|
/* All passed pointers must stay alive until cb is called. */
|
||||||
void sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan,
|
void sync_boxes( store_t *ctx[], const char *names[], int present[], channel_conf_t *chan,
|
||||||
void (*cb)( int sts, void *aux ), void *aux );
|
void (*cb)( int sts, void *aux ), void *aux );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user