sort files in outgoing cmd

Sat, 25 Jul 2020 12:08:15 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 25 Jul 2020 12:08:15 +0200
changeset 724
9c2f0072abed
parent 723
5ca174b3247a
child 725
de3b2bb46492

sort files in outgoing cmd

dav/sync.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Sat Jul 25 11:16:31 2020 +0200
+++ b/dav/sync.c	Sat Jul 25 12:08:15 2020 +0200
@@ -2158,8 +2158,18 @@
         ucx_map_cstr_remove(db->resources, local->path);
     }
     
+    ls_new = ucx_list_sort(ls_new, (cmp_func)resource_pathlen_cmp, NULL);
+    ls_modified = ucx_list_sort(ls_modified, (cmp_func)resource_pathlen_cmp, NULL);
+    ls_conflict = ucx_list_sort(ls_conflict, (cmp_func)resource_pathlen_cmp, NULL);
+    ls_update = ucx_list_sort(ls_update, (cmp_func)resource_pathlen_cmp, NULL);
+    ls_delete = ucx_list_sort(ls_delete, (cmp_func)resource_pathlen_cmp, NULL);
+    ls_move = ucx_list_sort(ls_move, (cmp_func)resource_pathlen_cmp, NULL);
+    ls_copy = ucx_list_sort(ls_copy, (cmp_func)resource_pathlen_cmp, NULL);
+    ls_mkcol = ucx_list_sort(ls_mkcol, (cmp_func)resource_pathlen_cmp, NULL);
+    
     if(outgoing) {
         print_outgoing(
+                a,
                 ls_new,
                 ls_modified,
                 ls_conflict,
@@ -2722,6 +2732,7 @@
 }
 
 void print_outgoing(
+        CmdArgs *args,
         UcxList *ls_new,
         UcxList *ls_modified,
         UcxList *ls_conflict,
@@ -2731,19 +2742,32 @@
         UcxList *ls_copy,
         UcxList *ls_mkcol)
 {
+    int64_t total_size = 0;
+    
+    size_t len_new = ucx_list_size(ls_new);
+    size_t len_mod = ucx_list_size(ls_modified);
+    size_t len_cnf = ucx_list_size(ls_conflict);
+    size_t len_upd = ucx_list_size(ls_update);
+    size_t len_del = ucx_list_size(ls_delete);
+    size_t len_mov = ucx_list_size(ls_move);
+    size_t len_cpy = ucx_list_size(ls_copy);
+    size_t len_mkc = ucx_list_size(ls_mkcol);
+    
+    size_t total = len_new + len_mod + len_cnf + len_upd + len_del + len_mov + len_cpy + len_mkc;
+    if(total == 0) {
+        printf("no changes\n");
+        return;
+    }
+    
     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) {
@@ -2752,7 +2776,6 @@
             LocalResource *res = elm->data;
             print_outgoging_file(elm->data);
             total_size += res->size;
-            num_files++;
         }
     }
     if(ls_modified) {
@@ -2761,7 +2784,6 @@
             LocalResource *res = elm->data;
             print_outgoging_file(elm->data);
             total_size += res->size;
-            num_files++;
         }
     }
     if(ls_update) {
@@ -2771,7 +2793,6 @@
             char *lastmodified = util_date_str(res->last_modified);
             printf(" %-49s  %12s\n", res->path+1, lastmodified);
             free(lastmodified);
-            num_files++;
         }
     }
     if(ls_delete) {
@@ -2786,7 +2807,6 @@
         UCX_FOREACH(elm, ls_copy) {
             LocalResource *res = elm->data;
             printf("%s -> %s\n", res->origin->path+1, res->path);
-            num_files++;
         }
     }
     if(ls_move) {
@@ -2794,7 +2814,6 @@
         UCX_FOREACH(elm, ls_move) {
             LocalResource *res = elm->data;
             printf("%s -> %s\n", res->origin->path+1, res->path);
-            num_files++;
         }
     }
     if(ls_conflict) {
@@ -2806,7 +2825,17 @@
     }
     
     char *total_size_str = util_size_str(FALSE, total_size);
-    printf("\n%d outgoing files, size: %s\n", num_files, total_size_str);
+    
+    printf("\n");
+    if(len_new > 0) printf("new: %zu, ", len_new);
+    if(len_mod > 0) printf("modified: %zu, ", len_mod);
+    if(len_upd > 0) printf("updated: %zu, ", len_upd);
+    if(len_cpy > 0) printf("copied: %zu, ", len_cpy);
+    if(len_mov > 0) printf("moved: %zu, ", len_mov);
+    if(len_del > 0) printf("deleted: %zu, ", len_del);
+    if(len_cnf > 0) printf("conflicts: %zu, ", len_cnf);
+    printf("total size: %s\n", total_size_str);
+    
     free(total_size_str);
 }
 
--- a/dav/sync.h	Sat Jul 25 11:16:31 2020 +0200
+++ b/dav/sync.h	Sat Jul 25 12:08:15 2020 +0200
@@ -105,6 +105,7 @@
 int cmd_restore(CmdArgs *args);
 
 void print_outgoing(
+        CmdArgs *args,
         UcxList *ls_new,
         UcxList *ls_modified,
         UcxList *ls_conflict,

mercurial