commit 926788f3ae17f93edd5136979cd7d61e239c8dcc
Author: Oswald Buddenhagen <[email protected]>
Date:   Tue Dec 30 15:16:38 2014 +0100

    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.

 src/main.c |   19 ++++++++++++-------
 src/sync.c |    7 +++++--
 src/sync.h |    6 +++++-
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/main.c b/src/main.c
index ee7a044..b93b8c5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -513,7 +513,7 @@ main( int argc, char **argv )
 
 static void store_opened( store_t *ctx, 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_2_dyn( 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;
                if (mvars->boxlist) {
                        while ((mbox = mvars->cboxes)) {
+                               int present[] = { BOX_PRESENT, BOX_PRESENT };
                                mvars->cboxes = mbox->next;
-                               if (sync_listed_boxes( mvars, mbox ))
+                               if (sync_listed_boxes( mvars, mbox, present ))
                                        goto syncw;
                        }
                        for (t = 0; t < 2; t++)
                                while ((mbox = mvars->boxes[t])) {
+                                       int present[2];
+                                       present[t] = BOX_PRESENT;
+                                       present[1-t] = BOX_ABSENT;
                                        mvars->boxes[t] = mbox->next;
                                        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;
                                        } else {
                                                free( mbox );
@@ -657,7 +661,8 @@ sync_chans( main_vars_t *mvars, int ent )
                                }
                } else {
                        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;
                          syncw:
                                mvars->cben = 1;
@@ -799,7 +804,7 @@ store_listed( int sts, void *aux )
 }
 
 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]) {
                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[S], "%s%s", spfx, 
mbox->string );
                        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;
                }
                printf( "%s%s <=> %s%s\n", mpfx, mbox->string, spfx, 
mbox->string );
        } else {
                if (!mvars->list) {
                        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;
                }
                puts( mbox->string );
diff --git a/src/sync.c b/src/sync.c
index 016a1f4..82d7f40 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -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 );
 
 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 )
 {
        sync_vars_t *svars;
@@ -987,7 +987,10 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
        sync_ref( svars );
        for (t = 0; ; 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 ))
                        break;
        }
diff --git a/src/sync.h b/src/sync.h
index 1b2db52..f3b8039 100644
--- a/src/sync.h
+++ b/src/sync.h
@@ -74,8 +74,12 @@ extern const char *str_ms[2], *str_hl[2];
 #define SYNC_NOGOOD   16 /* 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. */
-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 );
 
 #endif

------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to