103 } |
103 } |
104 } else if(!cfgret) { |
104 } else if(!cfgret) { |
105 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) { |
105 if(!strcasecmp(cmd, "list") || !strcasecmp(cmd, "ls")) { |
106 ret = cmd_list(args); |
106 ret = cmd_list(args); |
107 } else if(!strcasecmp(cmd, "get")) { |
107 } else if(!strcasecmp(cmd, "get")) { |
108 ret = cmd_get(args); |
108 ret = cmd_get(args, FALSE); |
109 } else if(!strcasecmp(cmd, "put")) { |
109 } else if(!strcasecmp(cmd, "put")) { |
110 ret = cmd_put(args); |
110 ret = cmd_put(args, FALSE); |
111 } else if( |
111 } else if( |
112 !strcasecmp(cmd, "remove") || |
112 !strcasecmp(cmd, "remove") || |
113 !strcasecmp(cmd, "rm") || |
113 !strcasecmp(cmd, "rm") || |
114 !strcasecmp(cmd, "delete")) |
114 !strcasecmp(cmd, "delete")) |
115 { |
115 { |
118 ret = cmd_mkdir(args); |
118 ret = cmd_mkdir(args); |
119 } else if(!strcasecmp(cmd, "copy") || !strcasecmp(cmd, "cp")) { |
119 } else if(!strcasecmp(cmd, "copy") || !strcasecmp(cmd, "cp")) { |
120 ret = cmd_move(args, true); |
120 ret = cmd_move(args, true); |
121 } else if(!strcasecmp(cmd, "move") || !strcasecmp(cmd, "mv")) { |
121 } else if(!strcasecmp(cmd, "move") || !strcasecmp(cmd, "mv")) { |
122 ret = cmd_move(args, false); |
122 ret = cmd_move(args, false); |
|
123 } else if(!strcasecmp(cmd, "export")) { |
|
124 ret = cmd_get(args, TRUE); |
|
125 } else if(!strcasecmp(cmd, "import")) { |
|
126 ret = cmd_put(args, TRUE); |
123 } else if(!strcasecmp(cmd, "date")) { |
127 } else if(!strcasecmp(cmd, "date")) { |
124 ret = cmd_date(args); |
128 ret = cmd_date(args); |
125 } else if(!strcasecmp(cmd, "set-property")) { |
129 } else if(!strcasecmp(cmd, "set-property")) { |
126 ret = cmd_set_property(args); |
130 ret = cmd_set_property(args); |
127 } else if(!strcasecmp(cmd, "get-property")) { |
131 } else if(!strcasecmp(cmd, "get-property")) { |
157 return ret; |
161 return ret; |
158 } |
162 } |
159 |
163 |
160 static char *cmdusageinfo[] = { |
164 static char *cmdusageinfo[] = { |
161 "list [-altdepcR] [-u <date>] <url>", |
165 "list [-altdepcR] [-u <date>] <url>", |
162 "get [-pcRKA] [-o <file>] [-u <date>] <url>", |
166 "get [-pcRK] [-o <file>] [-u <date>] <url>", |
163 "put [-pcRA] [-k <key>] [-L <lock>] <url> <file>", |
167 "put [-pcR] [-k <key>] [-L <lock>] <url> <file>", |
164 "mkdir [-pc] [-k <key>] [-L <lock>] <url>", |
168 "mkdir [-pc] [-k <key>] [-L <lock>] <url>", |
165 "remove [-pc] [-L <lock>] <url>", |
169 "remove [-pc] [-L <lock>] <url>", |
166 "copy [-pcO] [-L <lock>] <url> <url>", |
170 "copy [-pcO] [-L <lock>] <url> <url>", |
167 "move [-pcO] [-L <lock>] <url> <url>", |
171 "move [-pcO] [-L <lock>] <url> <url>", |
|
172 "export [-pc] [-o <file>] [-u <date>] <url>", |
|
173 "import [-pc] [-k <key>] [-L <lock>] <url> <file>", |
168 "get-property [-pcx] [-n <uri>] <url> <property>", |
174 "get-property [-pcx] [-n <uri>] <url> <property>", |
169 "set-property [-pcx] [-L <lock>] [-n <uri>] <url> <property> [value]", |
175 "set-property [-pcx] [-L <lock>] [-n <uri>] <url> <property> [value]", |
170 "remove-property [-pc] [-n <uri>] <url> <property>", |
176 "remove-property [-pc] [-n <uri>] <url> <property>", |
171 "lock [-pc] [-T timeout] <url>", |
177 "lock [-pc] [-T timeout] <url>", |
172 "unlock [-pc] [-L <lock>] <url>", |
178 "unlock [-pc] [-L <lock>] <url>", |
395 void download_progress(DavResource *res, int64_t total, int64_t now, void *data) { |
401 void download_progress(DavResource *res, int64_t total, int64_t now, void *data) { |
396 Progress *p = data; |
402 Progress *p = data; |
397 int newres = update_progress(res, total, now, p); |
403 int newres = update_progress(res, total, now, p); |
398 |
404 |
399 time_t newts = time(NULL); |
405 time_t newts = time(NULL); |
400 if(newres || (p->ts != newts)) { |
406 if((p->ts != newts)) { |
401 fprintf(p->out, "[%s]: %" PRId64 "k/%" PRId64 "k total: %" PRId64 "M/%" PRId64 "M\n", res->name, now/1024, total/1024, p->cur/(1024*1024), p->total/(1024*1024)); |
407 fprintf(p->out, "[%s]: %" PRId64 "k/%" PRId64 "k total: %" PRId64 "M/%" PRId64 "M\n", res->name, now/1024, total/1024, p->cur/(1024*1024), p->total/(1024*1024)); |
402 fflush(p->out); |
408 fflush(p->out); |
403 } |
409 } |
404 p->ts = newts; |
410 p->ts = newts; |
405 } |
411 } |
668 GetResource *getres = r; |
674 GetResource *getres = r; |
669 free(getres->path); |
675 free(getres->path); |
670 free(getres); |
676 free(getres); |
671 } |
677 } |
672 |
678 |
673 int cmd_get(CmdArgs *a) { |
679 int cmd_get(CmdArgs *a, DavBool export) { |
674 if(a->argc != 1) { |
680 if(a->argc != 1) { |
675 // TODO: change this, when get supports retrieval of multiple files |
681 // TODO: change this, when get supports retrieval of multiple files |
676 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
682 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few":"many"); |
677 fprintf(stderr, "Usage: dav %s\n", find_usage_str("get")); |
683 fprintf(stderr, "Usage: dav %s\n", find_usage_str("get")); |
678 return -1; |
684 return -1; |
|
685 } |
|
686 if(export) { |
|
687 ucx_map_cstr_put(a->options, "recursive", ""); |
679 } |
688 } |
680 |
689 |
681 char *url = a->argv[0]; |
690 char *url = a->argv[0]; |
682 char *path = NULL; |
691 char *path = NULL; |
683 Repository *repo = url2repo(url, &path); |
692 Repository *repo = url2repo(url, &path); |
739 * determine the output file |
748 * determine the output file |
740 * use stdout if the output file is - |
749 * use stdout if the output file is - |
741 */ |
750 */ |
742 char *outfile = cmd_getoption(a, "output"); |
751 char *outfile = cmd_getoption(a, "output"); |
743 char *basepath = outfile; |
752 char *basepath = outfile; |
744 char *tar = cmd_getoption(a, "tar"); |
|
745 if(!outfile) { |
753 if(!outfile) { |
746 if(res->iscollection) { |
754 if(res->iscollection) { |
747 basepath = ""; |
755 basepath = ""; |
748 } else { |
756 } else { |
749 basepath = res->name; |
757 basepath = res->name; |
750 } |
758 } |
751 if(tar) { |
759 if(export) { |
752 outfile = "-"; |
760 outfile = "-"; |
753 } |
761 } |
754 } else if(tar) { |
762 } else if(export) { |
755 basepath = ""; |
763 basepath = ""; |
756 } else if(res->iscollection && !strcmp(outfile, "-")) { |
764 } else if(res->iscollection && !strcmp(outfile, "-")) { |
757 fprintf( |
765 fprintf( |
758 stderr, |
766 stderr, |
759 "Cannot write output to stdout " |
767 "Cannot write output to stdout " |
813 pdata.total = totalsize; |
821 pdata.total = totalsize; |
814 |
822 |
815 int ret; |
823 int ret; |
816 getfunc get; |
824 getfunc get; |
817 TarOutputStream *tout = NULL; |
825 TarOutputStream *tout = NULL; |
818 if(tar) { |
826 if(export) { |
819 get = (getfunc)resource2tar; |
827 get = (getfunc)resource2tar; |
820 FILE *tarfile = strcmp(outfile, "-") ? fopen(outfile, "wb") : stdout; |
828 FILE *tarfile = strcmp(outfile, "-") ? fopen(outfile, "wb") : stdout; |
821 if(!tarfile) { |
829 if(!tarfile) { |
822 perror("Cannot open tar output file"); |
830 perror("Cannot open tar output file"); |
823 return -1; |
831 return -1; |
935 // download content |
943 // download content |
936 |
944 |
937 return tar_end_file(tar); |
945 return tar_end_file(tar); |
938 } |
946 } |
939 |
947 |
940 int cmd_put(CmdArgs *a) { |
948 int cmd_put(CmdArgs *a, DavBool import) { |
941 if(a->argc != 2) { |
949 if(a->argc != 2) { |
942 // TODO: change, when put supports multiple files (however it should do) |
950 // TODO: change, when put supports multiple files (however it should do) |
943 fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many"); |
951 fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many"); |
944 fprintf(stderr, "Usage: dav %s\n", find_usage_str("put")); |
952 fprintf(stderr, "Usage: dav %s\n", find_usage_str("put")); |
945 return -1; |
953 return -1; |
|
954 } |
|
955 if(import) { |
|
956 ucx_map_cstr_put(a->options, "resursive", ""); |
946 } |
957 } |
947 |
958 |
948 char *url = a->argv[0]; |
959 char *url = a->argv[0]; |
949 char *file = a->argv[1]; |
960 char *file = a->argv[1]; |
950 char *path = NULL; |
961 char *path = NULL; |
975 "but no default key is configured.\n" |
986 "but no default key is configured.\n" |
976 "You may specify a custom key with the '-k' option.\n"); |
987 "You may specify a custom key with the '-k' option.\n"); |
977 return -1; |
988 return -1; |
978 } |
989 } |
979 |
990 |
980 char *tar = cmd_getoption(a, "tar"); |
|
981 |
991 |
982 int ret; |
992 int ret; |
983 if(!tar) { |
993 if(!import) { |
984 if(!strcmp(file, "-")) { |
994 if(!strcmp(file, "-")) { |
985 FILE *in = stdin; |
995 FILE *in = stdin; |
986 ret = put_file(repo, a, sn, path, "stdin", in, 0); |
996 ret = put_file(repo, a, sn, path, "stdin", in, 0); |
987 } else { |
997 } else { |
988 ret = put_entry(repo, a, sn, path, file, TRUE); |
998 ret = put_entry(repo, a, sn, path, file, TRUE); |