improves variable names in cmd_move()

Wed, 30 May 2018 10:12:51 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 30 May 2018 10:12:51 +0200
changeset 383
bc215bdaf9bc
parent 382
1ce7211a1021
child 384
8bfde5687890

improves variable names in cmd_move()

dav/main.c file | annotate | diff | comparison | revisions
--- a/dav/main.c	Wed May 30 10:07:48 2018 +0200
+++ b/dav/main.c	Wed May 30 10:12:51 2018 +0200
@@ -1299,69 +1299,71 @@
 }
 
 int cmd_move(CmdArgs *a, int cp) {
+    const char* actionstr = cp ? "copy" : "move";
+    
     if(a->argc != 2) {
         // TODO: change, when creation of multiple dirs is supported
         fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many");
-        fprintf(stderr, "Usage: dav %s\n", find_usage_str(cp ? "copy" : "move"));
+        fprintf(stderr, "Usage: dav %s\n", find_usage_str(actionstr));
         return -1;
     }
     
-    char *url1 = a->argv[0];
-    char *path1 = NULL;
-    Repository *repo1 = url2repo(url1, &path1);
+    char *srcurl = a->argv[0];
+    char *srcpath = NULL;
+    Repository *srcrepo = url2repo(srcurl, &srcpath);
     
-    DavSession *sn = connect_to_repo(repo1, a);
-    if(set_session_config(sn, a)) {
+    DavSession *srcsn = connect_to_repo(srcrepo, a);
+    if(set_session_config(srcsn, a)) {
         return -1;
     }
-    set_session_lock(sn, a);
+    set_session_lock(srcsn, a);
     
     DavBool override = cmd_getoption(a, "override") ? true : false;
     
-    char *url2 = a->argv[1];
-    char *path2 = NULL;
-    Repository *repo2 = url2repo(url2, &path2);
+    char *desturl = a->argv[1];
+    char *destpath = NULL;
+    Repository *destrepo = url2repo(desturl, &destpath);
     
-    if(repo1 == repo2) {
-        DavResource *res = dav_resource_new(sn, path1);
-        int err = cp ? dav_copy_o(res, path2, override)
-                     : dav_move_o(res, path2, override);
+    if(srcrepo == destrepo) {
+        DavResource *res = dav_resource_new(srcsn, srcpath);
+        int err = cp ? dav_copy_o(res, destpath, override)
+                     : dav_move_o(res, destpath, override);
         if(err) {
-            print_resource_error(sn, res->path);
-            fprintf(stderr, "Cannot %s resource.\n", cp ? "copy" : "move");
+            print_resource_error(srcsn, res->path);
+            fprintf(stderr, "Cannot %s resource.\n", actionstr);
             return -1;
         }
     } else {
-        char *server1 = util_url_base(repo1->url);
-        char *server2 = util_url_base(repo2->url);     
-        if(!strcmp(server1, server2)) {
-            DavSession *sn2 = connect_to_repo(repo2, a);
-            if(set_session_config(sn2, a)) {
+        char *srchost = util_url_base(srcrepo->url);
+        char *desthost = util_url_base(destrepo->url);     
+        if(!strcmp(srchost, desthost)) {
+            DavSession *destsn = connect_to_repo(destrepo, a);
+            if(set_session_config(destsn, a)) {
                 return -1;
             }
-            DavResource *dest = dav_resource_new(sn2, path2);
+            DavResource *dest = dav_resource_new(destsn, destpath);
             char *desthref = dav_resource_get_href(dest);
-            char *desturl = util_get_url(sn2, desthref);
+            char *desturl = util_get_url(destsn, desthref);
             
-            DavResource *res = dav_resource_new(sn, path1);
+            DavResource *res = dav_resource_new(srcsn, srcpath);
             int err = cp ? dav_copyto(res, desturl, override)
                      : dav_moveto(res, desturl, override);
             
             free(desturl);
-            dav_session_destroy(sn2);
+            dav_session_destroy(destsn);
             
             if(err) {
-                print_resource_error(sn, res->path);
-                fprintf(stderr, "Cannot %s resource.\n", cp ? "copy" : "move");
+                print_resource_error(srcsn, res->path);
+                fprintf(stderr, "Cannot %s resource.\n", actionstr);
                 return -1;
             }
         } else {
-            fprintf(stderr, "Copy or Move not supported for different hosts.\n");
+            fprintf(stderr, "Cannot %s between different hosts.\n", actionstr);
             return -1;
         }
     }
     
-    dav_session_destroy(sn);
+    dav_session_destroy(srcsn);
     
     return 0;
 }

mercurial