dav/sync.c

changeset 723
5ca174b3247a
parent 702
444aa8fe133f
child 724
9c2f0072abed
--- a/dav/sync.c	Sun Jul 05 11:55:54 2020 +0200
+++ b/dav/sync.c	Sat Jul 25 11:16:31 2020 +0200
@@ -205,15 +205,17 @@
     } else if(!cfgret) {
         if(!strcmp(cmd, "pull")) {
             tid = start_sighandler(&mutex);
-            ret = cmd_pull(args);
+            ret = cmd_pull(args, FALSE);
             stop_sighandler(&mutex, tid);
         } else if(!strcmp(cmd, "push")) {
             tid = start_sighandler(&mutex);
-            ret = cmd_push(args, FALSE);
+            ret = cmd_push(args, FALSE, FALSE);
             stop_sighandler(&mutex, tid);
+        } else if(!strcmp(cmd, "outgoing")) {
+            ret = cmd_push(args, TRUE, FALSE);
         } else if(!strcmp(cmd, "archive")) {
             tid = start_sighandler(&mutex);
-            ret = cmd_push(args, TRUE);
+            ret = cmd_push(args, FALSE, TRUE);
             stop_sighandler(&mutex, tid);
         } else if(!strcmp(cmd, "restore")) {
             tid = start_sighandler(&mutex);
@@ -546,7 +548,7 @@
     }
 }
 
-int cmd_pull(CmdArgs *a) {
+int cmd_pull(CmdArgs *a, DavBool incoming) {
     if(a->argc != 1) {
         fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
         return -1;
@@ -1880,7 +1882,7 @@
     return ucx_map_cstr_get(db->conflict, res->path) ? 1 : 0;
 }
 
-int cmd_push(CmdArgs *a, DavBool archive) {
+int cmd_push(CmdArgs *a, DavBool outgoing, DavBool archive) {
     if(a->argc != 1) {
         fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
         return -1;
@@ -1965,7 +1967,7 @@
     // lock repository
     DavBool locked = FALSE;
     char *locktokenfile = NULL;
-    if((dir->lockpush || cmd_getoption(a, "lock")) && !cmd_getoption(a, "nolock")) {
+    if((dir->lockpush || cmd_getoption(a, "lock")) && !cmd_getoption(a, "nolock") && !outgoing) {
         if(dav_lock_t(root, dir->lock_timeout)) {
             print_resource_error(sn, "/");
             dav_session_destroy(sn);
@@ -2000,7 +2002,7 @@
     UcxList *ls_move = NULL;
     UcxList *ls_copy = NULL;
     UcxList *ls_mkcol = NULL;
-    
+      
     // upload all changed files
     //UcxList *resources = cmd_getoption(a, "read") ?
     //        read_changes(dir, db) : local_scan(dir, db);
@@ -2156,6 +2158,19 @@
         ucx_map_cstr_remove(db->resources, local->path);
     }
     
+    if(outgoing) {
+        print_outgoing(
+                ls_new,
+                ls_modified,
+                ls_conflict,
+                ls_update,
+                ls_delete,
+                ls_move,
+                ls_copy,
+                ls_mkcol);
+        return 0;
+    }
+    
     //
     // BEGIN PUSH
     //
@@ -2698,6 +2713,103 @@
     return ret;
 }
 
+static void print_outgoging_file(LocalResource *res) {
+    char *lastmodified = util_date_str(res->last_modified);
+    char *size = util_size_str(FALSE, res->size);
+    printf(" %-49s  %12s  %10s\n", res->path+1, lastmodified, size);
+    free(lastmodified);
+    free(size);
+}
+
+void print_outgoing(
+        UcxList *ls_new,
+        UcxList *ls_modified,
+        UcxList *ls_conflict,
+        UcxList *ls_update,
+        UcxList *ls_delete,
+        UcxList *ls_move,
+        UcxList *ls_copy,
+        UcxList *ls_mkcol)
+{
+    printf("%s\n", "File                                                Last Modified    Size");
+    printf("%s\n", "==============================================================================");
+    
+    int num_files = 0;
+    int64_t total_size = 0;
+    
+    if(ls_mkcol) {
+        printf("Directories:\n");
+        UCX_FOREACH(elm, ls_mkcol) {
+            LocalResource *res = elm->data;
+            printf(" %-49s\n", res->path+1);
+            total_size += res->size;
+            num_files++;
+        }
+    }
+    if(ls_new) {
+        printf("New:\n");
+        UCX_FOREACH(elm, ls_new) {
+            LocalResource *res = elm->data;
+            print_outgoging_file(elm->data);
+            total_size += res->size;
+            num_files++;
+        }
+    }
+    if(ls_modified) {
+        printf("Modified:\n");
+        UCX_FOREACH(elm, ls_modified) {
+            LocalResource *res = elm->data;
+            print_outgoging_file(elm->data);
+            total_size += res->size;
+            num_files++;
+        }
+    }
+    if(ls_update) {
+        printf("Update:\n");
+        UCX_FOREACH(elm, ls_update) {
+            LocalResource *res = elm->data;
+            char *lastmodified = util_date_str(res->last_modified);
+            printf(" %-49s  %12s\n", res->path+1, lastmodified);
+            free(lastmodified);
+            num_files++;
+        }
+    }
+    if(ls_delete) {
+        printf("Delete:\n");
+        UCX_FOREACH(elm, ls_delete) {
+            LocalResource *res = elm->data;
+            printf(" %s\n", res->path+1);
+        }
+    }
+    if(ls_copy) {
+        printf("Copy:\n");
+        UCX_FOREACH(elm, ls_copy) {
+            LocalResource *res = elm->data;
+            printf("%s -> %s\n", res->origin->path+1, res->path);
+            num_files++;
+        }
+    }
+    if(ls_move) {
+        printf("Move:\n");
+        UCX_FOREACH(elm, ls_move) {
+            LocalResource *res = elm->data;
+            printf("%s -> %s\n", res->origin->path+1, res->path);
+            num_files++;
+        }
+    }
+    if(ls_conflict) {
+        printf("Conflict\n");
+        UCX_FOREACH(elm, ls_conflict) {
+            LocalResource *res = elm->data;
+            printf(" %s\n", res->path+1);
+        }
+    }
+    
+    char *total_size_str = util_size_str(FALSE, total_size);
+    printf("\n%d outgoing files, size: %s\n", num_files, total_size_str);
+    free(total_size_str);
+}
+
 UcxList* local_scan(SyncDirectory *dir, SyncDatabase *db) {
     UcxList *resources = NULL;
     

mercurial