dav/sync.c

Sun, 21 Apr 2019 09:54:47 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 21 Apr 2019 09:54:47 +0200
changeset 580
caf23cf7f96d
parent 579
c80d5730c00b
child 581
3f9a9c80a2d2
permissions
-rw-r--r--

separate link changes from normal changes and create links after downloads

46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
542
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4 * Copyright 2019 Olaf Wintermann. All rights reserved.
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <errno.h>
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <unistd.h>
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
34 #include <signal.h>
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include <time.h>
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
36 #include <utime.h>
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include <libxml/xmlerror.h>
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include <sys/types.h>
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include <ucx/string.h>
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
40 #include <ucx/utils.h>
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
41 #include <ucx/properties.h>
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include <dirent.h>
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
44 #include <math.h>
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
45
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 #include <libidav/webdav.h>
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #include <libidav/utils.h>
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
48 #include <libidav/crypto.h>
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
399
a985a587787f fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 397
diff changeset
50 #include <libidav/session.h>
a985a587787f fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 397
diff changeset
51
a985a587787f fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 397
diff changeset
52 #include "sync.h"
a985a587787f fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 397
diff changeset
53
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 #include "config.h"
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 #include "sopt.h"
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 190
diff changeset
56 #include "error.h"
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
57 #include "assistant.h"
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
58 #include "libxattr.h"
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
59 #include "tags.h"
399
a985a587787f fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 397
diff changeset
60
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
61 #include "system.h"
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
63 #include <pthread.h>
394
4826f5fdd865 implements parser for basic tag filters without subfilters
Mike Becker <universe@uap-core.de>
parents: 392
diff changeset
64 #include <ctype.h>
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
65
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 static DavContext *ctx;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
68 static int sync_shutdown = 0;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
69
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 static void xmlerrorfnc(void * c, const char * msg, ... ) {
254
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
71 va_list ap;
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
72 va_start(ap, msg);
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
73 vfprintf(stderr, msg, ap);
d7c4ba50b7d8 implements xmlErrorFunc for dav sync + adds line numbers to error reporting in both config checkers
Mike Becker <universe@uap-core.de>
parents: 252
diff changeset
74 va_end(ap);
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
77 static DavPropName defprops[] = {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
78 { "DAV:", "getetag" },
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
79 { DAV_NS, "status" },
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
80 { DAV_NS, "finfo" },
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
81 { DAV_NS, "tags" },
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
82 { DAV_NS, "xattributes" },
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
83 { DAV_NS, "content-hash" },
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
84 { DAV_NS, "split" },
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
85 { DAV_NS, "link" }
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
86 };
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
87 static size_t numdefprops = 8 ;
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
88
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
89 /*
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
90 * strcmp version that works with NULL pointers
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
91 */
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
92 static int nullstrcmp(const char *s1, const char *s2) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
93 if(!s1 && s2) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
94 return -1;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
95 }
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
96 if(s1 && !s2) {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
97 return 1;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
98 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
99 if(!s1 && !s2) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
100 return 0;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
101 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
102 return strcmp(s1, s2);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
103 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
104
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
105 static char* nullstrdup(const char *s) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
106 return s ? strdup(s) : NULL;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
107 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
108
557
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
109 static void nullfree(void *p) {
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
110 if(p) {
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
111 free(p);
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
112 }
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
113 }
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
114
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 int main(int argc, char **argv) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 if(argc < 2) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 fprintf(stderr, "Missing command\n");
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 print_usage(argv[0]);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 return -1;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 char *cmd = argv[1];
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 if(!args) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 print_usage(argv[0]);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 return -1;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 }
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
128 int ret = EXIT_FAILURE;
54
fc34bd28a22a windows fix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
129
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
130 if(!strcasecmp(cmd, "version") || !strcasecmp(cmd, "-version")
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
131 || !strcasecmp(cmd, "--version")) {
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
132 fprintf(stderr, "dav-sync %s\n", DAV_VERSION);
235
0468df02e18f fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
133 cmd_args_free(args);
0468df02e18f fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 233
diff changeset
134 return -1;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
137 xmlGenericErrorFunc fnc = xmlerrorfnc;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
138 initGenericErrorDefaultFunc(&fnc);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
139 ctx = dav_context_new();
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
140 int cfgret = load_config(ctx) || load_sync_config();
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
141
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
142 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
143 pthread_mutex_lock(&mutex);
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
144 pthread_t tid;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
145
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
146 if(!strcmp(cmd, "check") || !strcmp(cmd, "check-config")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
147 if(!cfgret) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
148 fprintf(stdout, "Configuration OK.\n");
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
149 ret = EXIT_SUCCESS;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
150 } else {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
151 /* no output, the warnings are written by load_config */
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
152 ret = EXIT_FAILURE;
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
153 }
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
154 } else if(!cfgret) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
155 if(!strcmp(cmd, "pull")) {
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
156 tid = start_sighandler(&mutex);
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
157 ret = cmd_pull(args);
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
158 stop_sighandler(&mutex, tid);
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
159 } else if(!strcmp(cmd, "push")) {
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
160 tid = start_sighandler(&mutex);
299
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
161 ret = cmd_push(args, FALSE);
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
162 stop_sighandler(&mutex, tid);
299
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
163 } else if(!strcmp(cmd, "archive")) {
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
164 tid = start_sighandler(&mutex);
299
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
165 ret = cmd_push(args, TRUE);
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
166 stop_sighandler(&mutex, tid);
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
167 } else if(!strcmp(cmd, "restore")) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
168 tid = start_sighandler(&mutex);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
169 ret = cmd_restore(args);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
170 stop_sighandler(&mutex, tid);
563
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
171 } else if(!strcmp(cmd, "list-conflicts")) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
172 ret = cmd_list_conflicts(args);
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
173 } else if(!strcmp(cmd, "resolve-conflicts")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
174 ret = cmd_resolve_conflicts(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
175 } else if(!strcmp(cmd, "delete-conflicts")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
176 ret = cmd_delete_conflicts(args);
529
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
177 } else if(!strcmp(cmd, "list-versions")) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
178 ret = cmd_list_versions(args);
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
179 } else if(!strcmp(cmd, "trash-info")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
180 ret = cmd_trash_info(args);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
181 } else if(!strcmp(cmd, "empty-trash")) {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
182 ret = cmd_empty_trash(args);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
183 } else if(!strcmp(cmd, "add-tag")) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
184 ret = cmd_add_tag(args);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
185 } else if(!strcmp(cmd, "remove-tag")) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
186 ret = cmd_remove_tag(args);
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
187 } else if(!strcmp(cmd, "set-tags")) {
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
188 ret = cmd_set_tags(args);
377
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
189 } else if(!strcmp(cmd, "list-tags")) {
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
190 ret = cmd_list_tags(args);
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
191 } else if(!strcmp(cmd, "add-dir")
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
192 || !strcmp(cmd, "add-directory")) {
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
193 ret = cmd_add_directory(args);
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
194 } else if(!strcmp(cmd, "list-dirs")
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
195 || !strcmp(cmd, "list-directories")) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
196 ret = cmd_list_dirs();
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
197 } else if(!strcmp(cmd, "check-repos")
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
198 || !strcmp(cmd, "check-repositories")) {
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
199 ret = cmd_check_repositories();
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
200 } else {
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
201 print_usage(argv[0]);
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
202 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
205 // cleanup
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
206 cmd_args_free(args);
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
207 dav_context_destroy(ctx);
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
208
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
209 free_config();
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
210 free_sync_config();
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
211
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
212 curl_global_cleanup();
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
213 xmlCleanupParser();
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
214
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 return ret;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 void print_usage(char *cmd) {
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
219 fprintf(stderr, "Usage: %s command [options] arguments...\n\n", cmd);
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
221 fprintf(stderr, "Commands:\n");
405
6b85d745e402 fixes some char type mismatch warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 403
diff changeset
222 fprintf(stderr, " pull [-cldr] [-t <tags>] <directory>\n");
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
223 fprintf(stderr, " push [-cldrSRM] [-t <tags>] <directory>\n");
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
224 fprintf(stderr, " archive [-cldSRM] [-t <tags>] <directory>\n");
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
225 fprintf(stderr,
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
226 " restore [-ldRM] [-V <version>] [-s <directory>] [file...]\n");
563
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
227 fprintf(stderr, " list-conflicts <directory>\n");
219
9792cfe63b80 added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 218
diff changeset
228 fprintf(stderr, " resolve-conflicts <directory>\n");
9792cfe63b80 added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 218
diff changeset
229 fprintf(stderr, " delete-conflicts <directory>\n");
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
230 fprintf(stderr, " trash-info <directory>\n");
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
231 fprintf(stderr, " empty-trash <directory>\n");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
232 fprintf(stderr, " add-tag [-s <syncdir>] <file> <tag>\n");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
233 fprintf(stderr, " remove-tag [-s <syncdir>] <file> <tag>\n");
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
234 fprintf(stderr, " set-tags [-s <syncdir>] <file> [tags]\n");
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
235 fprintf(stderr, " list-tags [-s <syncdir>] <file>\n\n");
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
236
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
237 fprintf(stderr, "Options:\n");
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
238 fprintf(stderr, " -c Disable conflict detection\n");
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
239 fprintf(stderr, " -l Lock the repository before access\n");
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
240 fprintf(stderr, " -d Don't lock the repository\n");
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
241 fprintf(stderr, " -t <tags> "
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
242 "Only sync files which have the specified tags\n");
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
243 fprintf(stderr, " -r "
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
244 "Remove resources not matching the tag filter\n");
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
245 fprintf(stderr, " -V <vers> Restore specific version\n");
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
246 fprintf(stderr, " -S Save previous file version\n");
449
cdcaf532c030 small help text adjustment
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
247 fprintf(stderr, " -R Restore removed files\n");
cdcaf532c030 small help text adjustment
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
248 fprintf(stderr, " -M Restore modified files\n");
cdcaf532c030 small help text adjustment
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
249 fprintf(stderr, " -v Verbose output (all commands)\n\n");
198
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
250
44054c452de1 added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 192
diff changeset
251 fprintf(stderr, "Config commands:\n");
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
252 fprintf(stderr, " add-directory\n");
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
253 fprintf(stderr, " list-directories\n");
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
254 fprintf(stderr, " check-config\n");
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
255 fprintf(stderr, " check-repositories\n\n");
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
258 static void handlesig(int sig) {
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
259 if(sync_shutdown) {
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
260 exit(-1);
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
261 }
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
262 fprintf(stderr, "abort\n");
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
263 sync_shutdown = 1;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
264 }
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
265
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
266 static void* sighandler(void *data) {
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
267 signal(SIGTERM, handlesig);
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
268 signal(SIGINT, handlesig);
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
269
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
270 pthread_mutex_t *mutex = data;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
271 pthread_mutex_lock(mutex); // block thread
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
272 return NULL;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
273 }
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
274
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
275 pthread_t start_sighandler(pthread_mutex_t *mutex) {
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
276 pthread_t tid;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
277 if(pthread_create(&tid, NULL, sighandler, mutex)) {
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
278 perror("pthread_create");
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
279 exit(-1);
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
280 }
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
281 return tid;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
282 }
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
283
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
284 void stop_sighandler(pthread_mutex_t *mutex, pthread_t tid) {
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
285 pthread_mutex_unlock(mutex);
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
286 void *data;
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
287 pthread_join(tid, &data);
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
288 }
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
289
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
290 static char* create_local_path(SyncDirectory *dir, const char *path) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
291 char *local_path = util_concat_path(dir->path, path);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
292 size_t local_path_len = strlen(local_path);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
293 if(local_path[local_path_len-1] == '/') {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
294 local_path[local_path_len-1] = '\0';
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
295 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
296 return local_path;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
297 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
298
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
299 static int res_matches_filter(SyncDirectory *dir, char *res_path) {
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
300 // trash filter
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
301 if (dir->trash) {
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
302 sstr_t rpath = sstr(util_concat_path(dir->path, res_path));
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
303 if (util_path_isrelated(dir->trash, rpath.ptr)) {
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
304 free(rpath.ptr);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
305 return 1;
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
306 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
307 free(rpath.ptr);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
308 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
309
543
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
310 // versioning filter
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
311 if (dir->versioning) {
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
312 if(util_path_isrelated(dir->versioning->collection, res_path)) {
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
313 return 1;
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
314 }
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
315 }
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
316
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
317 // include/exclude filter
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
318 UCX_FOREACH(inc, dir->include) {
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
319 regex_t* pattern = (regex_t*) inc->data;
61
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
320 if (regexec(pattern, res_path, 0, NULL, 0) == 0) {
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
321 UCX_FOREACH(exc, dir->exclude) {
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
322 regex_t* pattern = (regex_t*) exc->data;
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
323 if (regexec(pattern, res_path, 0, NULL, 0) == 0) {
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
324 return 1;
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
325 }
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
326 }
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
327 return 0;
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
328 }
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
329 }
61
e9b102d5a6f6 fixed include/exclude filter for dav-sync
Mike Becker <universe@uap-core.de>
parents: 58
diff changeset
330 return 1;
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
331 }
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
332
389
fe855ce911f9 introduces SyncTagFilter type which for now implements the old tag list filter
Mike Becker <universe@uap-core.de>
parents: 386
diff changeset
333 static int res_matches_tags(DavResource *res, SyncTagFilter *tagfilter) {
415
6e1861e8262c check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
334 if(!tagfilter || tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) {
6e1861e8262c check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
335 return 1;
6e1861e8262c check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
336 }
417
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
337 // NOTE: currently not implementable
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
338 //int scope = res->iscollection ?
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
339 // DAV_SYNC_TAGFILTER_SCOPE_COLLECTION
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
340 // : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
341 //if((tagfilter->scope & scope) != scope) {
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
342 // return 1;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
343 //}
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
344 if(res->iscollection) {
414
ea50585ec9d9 adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
345 return 1;
ea50585ec9d9 adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
346 }
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
347
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
348 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags");
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
349 UcxList *res_tags = parse_dav_xml_taglist(tagsprop);
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
350
397
ddda42712f39 fixes tag filter evaluation not respecting mode for subfilter combination
Mike Becker <universe@uap-core.de>
parents: 396
diff changeset
351 int ret = matches_tagfilter(res_tags, tagfilter);
390
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 389
diff changeset
352
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 389
diff changeset
353 ucx_list_free_content(res_tags, (ucx_destructor) free_dav_tag);
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
354 ucx_list_free(res_tags);
390
26998dc980f9 adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents: 389
diff changeset
355
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
356 return ret;
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
357 }
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
358
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
359 static int localres_matches_tags(
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
360 SyncDirectory *dir,
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
361 LocalResource *res,
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
362 SyncTagFilter *tagfilter)
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
363 {
415
6e1861e8262c check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
364 if(!tagfilter || tagfilter->mode == DAV_SYNC_TAGFILTER_OFF) {
6e1861e8262c check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
365 return 1;
6e1861e8262c check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 414
diff changeset
366 }
417
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
367 //int scope = res->isdirectory ?
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
368 // DAV_SYNC_TAGFILTER_SCOPE_COLLECTION
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
369 // : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
370 //if((tagfilter->scope & scope) != scope) {
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
371 // return 1;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
372 //}
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
373 if(res->isdirectory) {
414
ea50585ec9d9 adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
374 return 1;
ea50585ec9d9 adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
375 }
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
376
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
377 DavBool changed = 0;
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
378 UcxList *res_tags = sync_get_file_tags(dir, res, &changed, NULL);
389
fe855ce911f9 introduces SyncTagFilter type which for now implements the old tag list filter
Mike Becker <universe@uap-core.de>
parents: 386
diff changeset
379
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
380 int ret = matches_tagfilter(res_tags, tagfilter);
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
381 UCX_FOREACH(elm, res_tags) {
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
382 DavTag *t = elm->data;
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
383 free_dav_tag(t);
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
384 }
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
385 ucx_list_free(res_tags);
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
386 return ret;
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
387 }
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
388
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
389 static DavSession* create_session(DavContext *ctx, Repository *repo, char *collection) {
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
390 int flags = get_repository_flags(repo);
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
391 char *url = repo->url;
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
392 DavBool find_collection = TRUE;
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
393 if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) {
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
394 url = util_concat_path(repo->url, collection);
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
395 find_collection = FALSE;
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
396 }
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
397 if(!collection || (collection[0] == '/' && strlen(collection) == 1)) {
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
398 // collection is NULL or "/"
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
399 // we don't need to find any collection because the repo url is
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
400 // the base url
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
401 find_collection = FALSE;
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
402 }
73
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
403 DavSession *sn = dav_session_new_auth(
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
404 ctx,
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
405 url,
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
406 repo->user,
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
407 repo->password);
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
408 if(url != repo->url) {
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
409 free(url);
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
410 }
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
411 sn->flags = flags;
73
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
412 sn->key = dav_context_get_key(ctx, repo->default_key);
199
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
413 curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
414 curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
415 if(repo->cert) {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
416 curl_easy_setopt(sn->handle, CURLOPT_CAPATH, repo->cert);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
417 }
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
418 if(!repo->verification) {
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
419 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
420 curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0);
f448fc8c9191 enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 198
diff changeset
421 }
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
422
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
423 if(find_collection) {
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
424 DavResource *col = dav_resource_new(sn, collection);
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
425 dav_exists(col); // exec this to get the href
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
426 // we actually don't care what the result is
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
427 // if it doesn't exists, an error will occur later
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
428 // and we can't handle it here
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
429 char *newurl = util_concat_path(repo->url, util_resource_name(col->href));
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
430 dav_session_set_baseurl(sn, newurl);
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
431 free(newurl);
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
432 }
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
433
73
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
434 return sn;
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
435 }
41e88442ad4e ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
436
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
437 static void print_allowed_cmds(SyncDirectory *dir) {
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
438 fprintf(stderr, "Allowed commands: ");
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
439 char *sep = "";
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
440 if((dir->allow_cmd & SYNC_CMD_PULL) == SYNC_CMD_PULL) {
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
441 fprintf(stderr, "pull");
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
442 sep = ", ";
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
443 }
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
444 if((dir->allow_cmd & SYNC_CMD_PUSH) == SYNC_CMD_PUSH) {
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
445 fprintf(stderr, "%spush", sep);
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
446 sep = ", ";
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
447 }
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
448 if((dir->allow_cmd & SYNC_CMD_ARCHIVE) == SYNC_CMD_ARCHIVE) {
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
449 fprintf(stderr, "%sarchive", sep);
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
450 }
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
451 fprintf(stderr, "\n");
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
452 }
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
453
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
454 static void localres_keep(SyncDatabase *db, const char *path) {
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
455 LocalResource *local = ucx_map_cstr_remove(db->resources, path);
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
456 if(local) {
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
457 local->keep = TRUE;
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
458 }
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
459
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
460 }
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
461
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
462 void res2map(DavResource *root, UcxMap *map) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
463 UcxList *stack = ucx_list_prepend(NULL, root->children);
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
464 while(stack) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
465 DavResource *res = stack->data;
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
466 stack = ucx_list_remove(stack, stack);
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
467
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
468 while(res) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
469 ucx_map_cstr_put(map, res->path, res);
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
470
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
471 if(res->children) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
472 stack = ucx_list_prepend(stack, res->children);
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
473 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
474 res = res->next;
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
475 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
476 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
477 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
478
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 int cmd_pull(CmdArgs *a) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480 if(a->argc != 1) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
481 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 return -1;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
483 }
392
4853fbad5014 adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents: 391
diff changeset
484 // if there are syntax errors in the command line, fail asap.
414
ea50585ec9d9 adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
485 SyncTagFilter* tagfilter = parse_tagfilter_string(
ea50585ec9d9 adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
486 cmd_getoption(a, "tags"), DAV_SYNC_TAGFILTER_SCOPE_RESOURCE);
392
4853fbad5014 adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents: 391
diff changeset
487 if (!tagfilter) {
4853fbad5014 adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents: 391
diff changeset
488 fprintf(stderr, "Malformed tag filter\n");
4853fbad5014 adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents: 391
diff changeset
489 return -1;
4853fbad5014 adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents: 391
diff changeset
490 }
395
b491d207ee16 fixes whitespace handling and error detection for basic tag filters
Mike Becker <universe@uap-core.de>
parents: 394
diff changeset
491 // TODO: tons of memory leaks...
b491d207ee16 fixes whitespace handling and error detection for basic tag filters
Mike Becker <universe@uap-core.de>
parents: 394
diff changeset
492 // call free_tagfilter() before each return
392
4853fbad5014 adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents: 391
diff changeset
493
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494 SyncDirectory *dir = scfg_get_dir(a->argv[0]);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495 if(!dir) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497 return -1;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498 }
233
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
499 if(scfg_check_dir(dir)) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
500 return -1;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
501 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
503 if((dir->allow_cmd & SYNC_CMD_PULL) != SYNC_CMD_PULL) {
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
504 fprintf(stderr, "Command 'pull' is not allowed for this sync dir\n");
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
505 print_allowed_cmds(dir);
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
506 return -1;
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
507 }
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
508
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
509 Repository *repo = get_repository(sstr(dir->repository));
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
510 if(!repo) {
495
52cbd310b881 fixes 'Unkown repository' error message in dav-sync
Mike Becker <universe@uap-core.de>
parents: 493
diff changeset
511 fprintf(stderr, "Unknown repository %s\n", dir->repository);
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512 return -1;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514
49
c5759ac76c1b dav-sync detects locally removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
515 SyncDatabase *db = load_db(dir->database);
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
516 if(!db) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
517 fprintf(stderr, "Cannot load database file: %s\n", dir->database);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
518 return -1;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
519 }
218
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
520 remove_deleted_conflicts(dir, db);
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
521
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
522 UcxMap *hashes = NULL;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
523 if(dir->hashing) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
524 hashes = create_hash_index(db);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
525 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
526
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
527 DavSession *sn = create_session(ctx, repo, dir->collection);
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
528 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db);
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 66
diff changeset
529 if (cmd_getoption(a, "verbose")) {
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 66
diff changeset
530 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 66
diff changeset
531 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 66
diff changeset
532 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
533
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
534 // lock repository
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
535 char *locktokenfile = NULL;
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
536 DavBool locked = FALSE;
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
537 DavResource *root = dav_resource_new(sn, "/");
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
538 root->iscollection = TRUE;
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
539 if((dir->lockpush || cmd_getoption(a, "lock")) && !cmd_getoption(a, "nolock")) {
316
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 313
diff changeset
540 if(dav_lock_t(root, dir->lock_timeout)) {
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
541 print_resource_error(sn, "/");
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
542 dav_session_destroy(sn);
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
543 fprintf(stderr, "Abort\n");
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
544 return -1;
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
545 }
233
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
546 DavLock *lock = dav_get_lock(sn, "/");
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
547 if(lock) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
548 printf("Lock-Token: %s\n", lock->token);
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
549 }
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
550 locked = TRUE;
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
551 locktokenfile = create_locktoken_file(dir->name, lock->token);
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
552 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
553
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
554 int ret = 0;
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
555 DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:tags,idav:finfo,idav:xattributes,idav:split,idav:link,`idav:content-hash` from / with depth = infinity");
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556 if(!ls) {
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 190
diff changeset
557 print_resource_error(sn, "/");
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
558 if(locked) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
559 if(dav_unlock(root)) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
560 print_resource_error(sn, "/");
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
561 } else {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
562 locked = FALSE;
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
563 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
564 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
565
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
566 fprintf(stderr, "Abort\n");
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
567
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
568 dav_session_destroy(sn);
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
569 // TODO: free
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
570 return -1;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
571 }
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
572 if(!ls->iscollection) {
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
573 fprintf(stderr, "%s is not a collection.\nAbort.\n", ls->path);
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
574 if(locked) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
575 if(dav_unlock(root)) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
576 print_resource_error(sn, "/");
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
577 } else {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
578 locked = FALSE;
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
579 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
580 }
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
581 // TODO: free
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
582 dav_session_destroy(sn);
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
583
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
584 if(!locked && locktokenfile) {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
585 remove(locktokenfile);
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
586 }
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
587
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
588 return -1;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
589 }
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
590
402
babdf40dd22c dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 400
diff changeset
591 DavBool remove_file = cmd_getoption(a, "remove") ? 1 : 0;
babdf40dd22c dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 400
diff changeset
592
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
593 int sync_success = 0;
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
594 int sync_delete = 0;
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
595 int sync_error = 0;
561
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
596 int sync_conflict = 0;
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
597
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
598 UcxList *res_modified = NULL;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
599 UcxList *res_new = NULL;
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
600 UcxList *res_moved = NULL; // type: MovedFile
579
c80d5730c00b add check to detect changed link properties in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
601 UcxList *res_link;
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
602 UcxList *res_conflict = NULL;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
603 UcxList *res_mkdir = NULL;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
604 UcxList *res_metadata = NULL;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
605 UcxList *res_broken = NULL;
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
606 UcxMap *lres_removed = ucx_map_new(16); // type: LocalResource*
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
607
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
608 //UcxMap *svrres = ucx_map_new(db->resources->count);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
609 UcxMap *dbres = ucx_map_clone(db->resources, NULL, NULL);
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
610
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
611 UcxList *stack = ucx_list_prepend(NULL, ls->children);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
612 while(stack) {
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
613 DavResource *res = stack->data;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
614 stack = ucx_list_remove(stack, stack);
49
c5759ac76c1b dav-sync detects locally removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
615
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
616 while(res) {
417
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
617 DavBool res_filtered = FALSE;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
618 if (res_matches_filter(dir, res->path)) {
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
619 res_filtered = TRUE;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
620 } else {
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
621 UCX_FOREACH(elm, dir->tagfilter) {
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
622 SyncTagFilter *tf = elm->data;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
623 if(!res_matches_tags(res, tf)) {
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
624 res_filtered = TRUE;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
625 break;
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
626 }
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
627 }
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
628 }
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
629 if(res_filtered) {
402
babdf40dd22c dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 400
diff changeset
630 // don't delete files filtered by config
babdf40dd22c dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 400
diff changeset
631 localres_keep(db, res->path);
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
632 res = res->next;
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
633 continue;
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
634 }
402
babdf40dd22c dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 400
diff changeset
635
392
4853fbad5014 adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents: 391
diff changeset
636 if (!res_matches_tags(res, tagfilter)) {
402
babdf40dd22c dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 400
diff changeset
637 if(!remove_file) {
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
638 localres_keep(db, res->path);
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
639 }
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
640 res = res->next;
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
641 continue;
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
642 }
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
643
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
644 char *status = dav_get_string_property(res, "idav:status");
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
645 if(status && !strcmp(status, "broken")) {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
646 res = res->next;
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
647 localres_keep(db, res->path);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
648 res_broken = ucx_list_append(res_broken, res);
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
649 continue;
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
650 }
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
651
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
652 // check if a resource has changed on the server
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
653 int change = resource_get_remote_change(a, res, dir, db);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
654 switch(change) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
655 case REMOTE_NO_CHANGE: break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
656 case REMOTE_CHANGE_MODIFIED: {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
657 res_modified = ucx_list_append(res_modified, res);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
658 break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
659 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
660 case REMOTE_CHANGE_NEW: {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
661 res_new = ucx_list_append(res_new, res);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
662 break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
663 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
664 case REMOTE_CHANGE_DELETED: break; // never happens
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
665 case REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED: {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
666 res_conflict = ucx_list_append(res_conflict, res);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
667 break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
668 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
669 case REMOTE_CHANGE_METADATA: {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
670 res_metadata = ucx_list_append(res_metadata, res);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
671 break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
672 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
673 case REMOTE_CHANGE_MKDIR: {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
674 res_mkdir = ucx_list_append(res_mkdir, res);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
675 break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
676 }
580
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
677 case REMOTE_CHANGE_LINK: {
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
678 res_link = ucx_list_append(res_link, res);
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
679 break;
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
680 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
681 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
682
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
683 // remove every server resource from dbres
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
684 // all remaining elements are the resources that are removed
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
685 // on the server
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
686 ucx_map_cstr_remove(dbres, res->path);
272
b321a3be0a38 fixes unnecessary mkcol in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 257
diff changeset
687
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
688 if(!dav_get_property_ns(res, DAV_NS, "split") && res->children) {
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
689 stack = ucx_list_prepend(stack, res->children);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
690 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
691 res = res->next;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
692 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
693 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
694
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
695 // find deleted resources
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
696 // svrres currently contains all resources from the server
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
697 // and will replace the current db->resources map later
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
698 UcxMapIterator i = ucx_map_iterator(dbres);
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
699 LocalResource *local;
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
700 UCX_MAP_FOREACH(key, local, i) {
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
701 if (res_matches_filter(dir, local->path)) {
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
702 continue;
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
703 }
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
704 if(!local->keep) {
564
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
705 ucx_map_cstr_put(lres_removed, local->path, local);
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
706 if(lres_removed->count > lres_removed->size * 2) {
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
707 ucx_map_rehash(lres_removed);
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
708 }
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
709 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
710 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
711
566
9a88920b15d8 increase snyc_conflict counter only after conflict renaming, to make sure the counter is correct when pull is aborted
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 565
diff changeset
712 //
9a88920b15d8 increase snyc_conflict counter only after conflict renaming, to make sure the counter is correct when pull is aborted
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 565
diff changeset
713 // BEGIN PULL
9a88920b15d8 increase snyc_conflict counter only after conflict renaming, to make sure the counter is correct when pull is aborted
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 565
diff changeset
714 //
9a88920b15d8 increase snyc_conflict counter only after conflict renaming, to make sure the counter is correct when pull is aborted
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 565
diff changeset
715
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
716 // the first thing we need are all directories to put the files in
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
717 UCX_FOREACH(elm, res_mkdir) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
718 DavResource *res = elm->data;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
719 char *local_path = create_local_path(dir, res->path);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
720 if(sys_mkdir(local_path) && errno != EEXIST) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
721 fprintf(stderr,
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
722 "Cannot create directory %s: %s",
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
723 local_path, strerror(errno));
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
724 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
725 free(local_path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
726 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
727
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
728 // we need a map for all conflicts for fast lookups
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
729 UcxMap *conflicts = ucx_map_new(ucx_list_size(res_conflict)+16);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
730 UCX_FOREACH(elm, res_conflict) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
731 DavResource *res = elm->data;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
732 ucx_map_cstr_put(conflicts, res->path, res);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
733 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
734
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
735 if(dir->hashing) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
736 // check for moved/copied files
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
737 UcxList *elm = res_new;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
738 UcxList *prev = NULL;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
739 UcxList *next = NULL;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
740 struct stat s;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
741 for(;elm;elm=next) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
742 DavResource *res = elm->data;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
743 prev = elm->prev;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
744 next = elm->next;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
745
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
746 if(dav_get_property_ns(res, DAV_NS, "link")) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
747 continue;
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
748 }
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
749
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
750 char *hash = sync_get_content_hash(res);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
751 if(!hash) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
752 continue;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
753 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
754
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
755 LocalResource *local = ucx_map_cstr_get(hashes, hash);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
756 if(!local) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
757 continue;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
758 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
759
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
760 char *local_path = util_concat_path(dir->path, local->path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
761 int staterr = stat(local_path, &s);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
762 free(local_path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
763 if(staterr) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
764 // origin doesn't exist or is inaccessible
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
765 continue;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
766 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
767
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
768 MovedFile *mf = malloc(sizeof(MovedFile));
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
769 mf->content = local;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
770 mf->resource = res;
569
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
771 if(ucx_map_cstr_remove(lres_removed, local->path)) {
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
772 mf->copy = FALSE;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
773 } else {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
774 mf->copy = TRUE;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
775 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
776
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
777 res_moved = ucx_list_append(res_moved, mf);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
778
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
779 // remove item from res_new
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
780 if(prev) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
781 prev->next = next;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
782 } else {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
783 res_new = next;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
784 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
785 if(next) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
786 next->prev = prev;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
787 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
788 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
789 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
790
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
791 // do copy/move operations
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
792 UCX_FOREACH(elm, res_moved) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
793 MovedFile *mf = elm->data;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
794 if(sync_shutdown) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
795 break;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
796 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
797
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
798 DavBool issplit = dav_get_property_ns(mf->resource, DAV_NS, "split") ? 1 : 0;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
799 if(ucx_map_cstr_get(conflicts, mf->resource->path)) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
800 rename_conflict_file(dir, db, mf->resource->path, issplit);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
801 sync_conflict++;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
802 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
803
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
804 // move file
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
805 if(sync_move_resource(a, dir, mf->resource, mf->content, mf->copy, db, &sync_success)) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
806 fprintf(stderr, "%s failed: %s\n", mf->copy?"copy":"move", mf->resource->path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
807 sync_error++;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
808 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
809 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
810
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
811 // download all new, modified and conflict files
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
812 UcxList *download = ucx_list_concat(res_modified, res_conflict);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
813 download = ucx_list_concat(res_new, download);
580
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
814 download = ucx_list_concat(download, res_link);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
815 UCX_FOREACH(elm, download) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
816 DavResource *res = elm->data;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
817 if(sync_shutdown) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
818 break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
819 }
302
395763c0ee69 adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 299
diff changeset
820
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
821 DavBool issplit = dav_get_property_ns(res, DAV_NS, "split") ? 1 : 0;
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
822 if(ucx_map_cstr_get(conflicts, res->path)) {
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
823 rename_conflict_file(dir, db, res->path, issplit);
566
9a88920b15d8 increase snyc_conflict counter only after conflict renaming, to make sure the counter is correct when pull is aborted
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 565
diff changeset
824 sync_conflict++;
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
825 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
826
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
827 // download the resource
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
828 if(sync_get_resource(a, dir, res->path, res, db, &sync_success)) {
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
829 fprintf(stderr, "resource download failed: %s\n", res->path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
830 sync_error++;
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
831 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
832 }
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
833
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
834 UCX_FOREACH(elm, res_metadata) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
835 DavResource *res = elm->data;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
836 if(sync_shutdown) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
837 break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
838 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
839
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
840 LocalResource *local = ucx_map_cstr_get(db->resources, res->path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
841 if(local) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
842 printf("update: %s\n", res->path);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
843 char *local_path = create_local_path(dir, res->path);
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
844 if(sync_store_metadata(dir, local_path, local, res)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
845 fprintf(stderr, "Metadata update failed: %s\n", res->path);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
846 sync_error++;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
847 } else {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
848 struct stat s;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
849 if(stat(local_path, &s)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
850 fprintf(stderr, "Cannot stat file after update: %s\n", strerror(errno));
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
851 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
852 sync_set_metadata_from_stat(local, &s);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
853 sync_success++;
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
854 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
855 free(local_path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
856 } else {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
857 // this should never happen but who knows
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
858 fprintf(stderr,
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
859 "Cannot update metadata of file %s: not in database\n",
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
860 res->path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
861 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
862 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
863
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
864 UcxList *rmdirs = NULL;
564
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
865 UcxMapIterator mi = ucx_map_iterator(lres_removed);
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
866 LocalResource *removed_res;
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
867 UcxKey key;
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
868 UCX_MAP_FOREACH(key, removed_res, mi) {
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
869 if(sync_shutdown) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
870 break;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
871 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
872
564
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
873 int ret = sync_remove_local_resource(dir, removed_res);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
874 if(ret == -1) {
564
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
875 rmdirs = ucx_list_append(rmdirs, removed_res);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
876 } else if(ret == 0) {
564
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
877 LocalResource *local = ucx_map_cstr_remove(db->resources, removed_res->path);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
878 if(local) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
879 local_resource_free(local);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
880 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
881 sync_delete++;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
882 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
883 }
564
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
884 ucx_map_free(lres_removed);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
885
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
886 UCX_FOREACH(elm, rmdirs) {
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
887 LocalResource *local_dir = elm->data;
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
888 if(!sync_remove_local_directory(dir, local_dir)) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
889 LocalResource *local = ucx_map_cstr_remove(db->resources, local_dir->path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
890 if(local) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
891 local_resource_free(local);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
892 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
893 sync_delete++;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
894 }
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
895 }
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
896
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
897 // unlock repository
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
898 if(locked) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
899 if(dav_unlock(root)) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
900 print_resource_error(sn, "/");
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
901 ret = -1;
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
902 } else {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
903 locked = FALSE;
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
904 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
905 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
906
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
907 // store db
521
c5bbae4b3cca extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 516
diff changeset
908 if(store_db(db, dir->database, dir->db_settings)) {
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
909 fprintf(stderr, "Cannot store sync db\n");
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
910 ret = -2;
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
911 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
912
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
913 // cleanup
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
914 dav_session_destroy(sn);
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
915
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
916 if(!locked && locktokenfile) {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
917 remove(locktokenfile);
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
918 }
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
919
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
920 // Report
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
921 if(ret != -2) {
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
922 char *str_success = sync_success == 1 ? "file" : "files";
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
923 char *str_delete = sync_delete == 1 ? "file" : "files";
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
924 char *str_error = sync_error == 1 ? "error" : "errors";
561
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
925 char *str_conflict = sync_conflict == 1 ? "conflict" : "conflicts";
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
926 printf("Result: %d %s pulled, %d %s deleted, %d %s, %d %s\n",
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
927 sync_success, str_success,
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
928 sync_delete,str_delete,
561
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
929 sync_conflict, str_conflict,
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
930 sync_error, str_error);
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
931 }
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
932
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
933 return ret;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
934 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
935
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
936
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
937 RemoteChangeType resource_get_remote_change(
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
938 CmdArgs *a,
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
939 DavResource *res,
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
940 SyncDirectory *dir,
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
941 SyncDatabase *db)
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
942 {
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
943 char *etag = dav_get_string_property(res, "D:getetag");
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
944 if(!etag) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
945 fprintf(stderr, "Error: resource %s has no etag\n", res->path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
946 return REMOTE_NO_CHANGE;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
947 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
948
543
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
949 DavBool issplit = dav_get_property(res, "idav:split") ? TRUE : FALSE;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
950 if(issplit) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
951 util_remove_trailing_pathseparator(res->path);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
952 }
543
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
953
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
954 RemoteChangeType type = cmd_getoption(a, "conflict") ?
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
955 REMOTE_CHANGE_MODIFIED : REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED;
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
956
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
957 LocalResource *local = ucx_map_cstr_get(db->resources, res->path);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
958 char *local_path = create_local_path(dir, res->path);
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
959
580
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
960 char *link = SYNC_SYMLINK(dir) ?
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
961 dav_get_string_property_ns(res, DAV_NS, "link") : NULL;
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
962
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
963 SYS_STAT s;
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
964 DavBool exists = 1;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
965 if(sys_stat(local_path, &s)) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
966 if(errno != ENOENT) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
967 fprintf(stderr, "Cannot stat file: %s\n", local_path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
968 free(local_path);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
969 return REMOTE_NO_CHANGE;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
970 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
971 exists = 0;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
972 }
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
973
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
974 RemoteChangeType ret = REMOTE_NO_CHANGE;
543
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
975 if(res->iscollection && !issplit) {
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
976 if(!exists) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
977 ret = REMOTE_CHANGE_MKDIR;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
978 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
979 } else if(local) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
980 DavBool nochange = FALSE;
543
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
981 char *content_hash = sync_get_content_hash(res);
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
982
580
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
983 if(SYNC_SYMLINK(dir) && nullstrcmp(link, local->link_target)) {
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
984 ret = REMOTE_CHANGE_LINK;
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
985 nochange = TRUE;
579
c80d5730c00b add check to detect changed link properties in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 578
diff changeset
986 } else if(content_hash && local->hash) {
560
a816e805e5db store origin of file conflicts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 559
diff changeset
987 if(!strcmp(content_hash, local->hash)) {
543
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
988 nochange = TRUE;
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
989 }
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
990 } else if(local->etag) {
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
991 sstr_t e = sstr(etag);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
992 if(sstrprefix(e, S("W/"))) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
993 e = sstrsubs(e, 2);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
994 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
995 if(!strcmp(e.ptr, local->etag)) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
996 // resource is already up-to-date on the client
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
997 nochange = TRUE;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
998 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
999 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1000
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1001 if(!nochange) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1002 if(!(exists && s.st_mtime != local->last_modified)) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1003 type = REMOTE_CHANGE_MODIFIED;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1004 }
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1005 ret = type;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1006 }
580
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
1007 } else if(link) {
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
1008 if(type == REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED) {
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
1009 ret = REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED;
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
1010 } else {
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
1011 ret = REMOTE_CHANGE_LINK;
caf23cf7f96d separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 579
diff changeset
1012 }
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1013 } else if(exists) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1014 ret = type;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1015 } else {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1016 ret = REMOTE_CHANGE_NEW;
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1017 }
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
1018
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1019 while(ret == REMOTE_NO_CHANGE && local) {
524
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
1020 // check if tags have changed
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
1021 if(dir->tagconfig) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1022 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags");
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1023 UcxList *remote_tags = NULL;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1024 if(tagsprop) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1025 remote_tags = parse_dav_xml_taglist(tagsprop);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1026 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1027 char *remote_hash = create_tags_hash(remote_tags);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1028 if(nullstrcmp(remote_hash, local->remote_tags_hash)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1029 ret = REMOTE_CHANGE_METADATA;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1030 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1031 if(remote_hash) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1032 free(remote_hash);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1033 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1034 free_taglist(remote_tags);
524
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
1035
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1036 if(ret == REMOTE_CHANGE_METADATA) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1037 break;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1038 }
524
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
1039 }
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
1040
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1041 // check if extended attributes have changed
539
8deb52292c99 fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 536
diff changeset
1042 if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1043 DavXmlNode *xattr = dav_get_property_ns(res, DAV_NS, "xattributes");
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1044 char *xattr_hash = get_xattr_hash(xattr);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1045 if(nullstrcmp(xattr_hash, local->xattr_hash)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1046 ret = REMOTE_CHANGE_METADATA;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1047 break;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1048 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1049 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1050
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1051 // check if finfo has changed
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1052 DavXmlNode *finfo = dav_get_property_ns(res, DAV_NS, "finfo");
539
8deb52292c99 fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 536
diff changeset
1053 if((dir->metadata & FINFO_MODE) == FINFO_MODE) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1054 FileInfo f;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1055 finfo_get_values(finfo, &f);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1056 if(f.mode_set && f.mode != local->mode) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1057 ret = REMOTE_CHANGE_METADATA;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1058 break;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1059 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1060 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1061
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1062 break;
524
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
1063 }
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
1064
502
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
1065 free(local_path);
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
1066 return ret;
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
1067 }
a23fedac340c fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 501
diff changeset
1068
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1069 void sync_set_metadata_from_stat(LocalResource *local, struct stat *s) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1070 local->last_modified = s->st_mtime;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1071 local->mode = s->st_mode & 07777;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1072 local->uid = s->st_uid;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1073 local->gid = s->st_gid;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1074 local->size = s->st_size;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1075 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1076
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1077 static UcxList* sync_download_changed_parts(
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1078 DavResource *res,
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1079 LocalResource *local,
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1080 FILE *out,
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1081 size_t blocksize,
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1082 uint64_t *blockcount,
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1083 int64_t *truncate_file,
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1084 int *err)
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1085 {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1086 UcxList *updates = NULL;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1087
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1088 size_t local_numparts = local ? local->numparts : 0;
546
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1089 fseeko(out, 0, SEEK_END);
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1090 off_t end = ftello(out);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1091
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1092 int error = 0;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1093
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1094 UcxBuffer *buf = ucx_buffer_new(NULL, blocksize, 0);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1095
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1096 int64_t maxsize = -1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1097
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1098 DavResource *part = res->children;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1099 uint64_t i = 0;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1100 while(part) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1101 char *res_name = part->name;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1102 while(res_name[0] == '0' && res_name[1] != '\0') {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1103 res_name++;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1104 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1105 uint64_t partnum = 0;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1106 if(util_strtouint(res_name, &partnum)) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1107 DavBool download_part = FALSE;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1108 char *etag = dav_get_string_property_ns(part, "DAV:", "getetag");
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1109 if(partnum >= local_numparts) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1110 // new part
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1111 download_part = TRUE;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1112 } else {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1113 FilePart p = local->parts[partnum]; // local is always non-null here
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1114 if(etag) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1115 if(nullstrcmp(etag, p.etag)) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1116 download_part = TRUE;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1117 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1118 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1119 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1120
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1121 uint64_t offset;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1122 int mul_err = util_uint_mul(partnum, blocksize, &offset);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1123 if(mul_err || offset >= INT64_MAX) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1124 error = 1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1125 fprintf(stderr, "Error: part number too high\n");
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1126 break;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1127 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1128
546
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1129 int64_t block_end = 0;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1130 if(download_part) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1131 if(fseeko(out, offset, SEEK_SET)) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1132 error = 1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1133 fprintf(stderr, "Error: fseek failed: %s\n", strerror(errno));
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1134 break;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1135 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1136 buf->pos = 0;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1137 buf->size = 0;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1138 if(dav_get_content(part, buf,(dav_write_func)ucx_buffer_write)) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1139 fprintf(stderr, "Error: cannot download part: %s\n", part->name);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1140 error = 1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1141 break;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1142 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1143 if(fwrite(buf->space, 1, buf->size, out) == 0) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1144 perror("write");
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1145 error = 1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1146 break;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1147 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1148
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1149 FilePart *update = calloc(1, sizeof(FilePart));
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1150 update->block = partnum;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1151 update->etag = etag ? strdup(etag) : NULL;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1152 update->hash = dav_create_hash(buf->space, buf->size);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1153 updates = ucx_list_append(updates, update);
546
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1154
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1155 block_end = offset+buf->size;
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1156 } else {
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1157 if(offset+blocksize > end) {
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1158 // if we don't download the block, we don't know the size
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1159 // but it can't be bigger than the file
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1160 block_end = end;
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1161 } else {
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1162 block_end = offset+blocksize;
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1163 }
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1164 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1165
546
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1166 if(block_end > maxsize) {
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1167 maxsize = block_end;
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1168 }
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1169
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1170 i++;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1171 } // else: res is not a regular file part
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1172 part = part->next;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1173 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1174
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1175 ucx_buffer_free(buf);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1176
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1177 if(error) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1178 *err = 1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1179 ucx_list_free_content(updates, (ucx_destructor)filepart_free);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1180 return NULL;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1181 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1182
546
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1183 if(maxsize < end) {
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1184 *truncate_file = maxsize;
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1185 } else {
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1186 *truncate_file = -1;
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1187 }
33e312dd851d truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 545
diff changeset
1188
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1189 *err = 0;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1190 *blockcount = i;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1191 return updates;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1192 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1193
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1194 int copy_file(const char *from, const char *to) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1195 FILE *in = sys_fopen(from, "rb");
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1196 if(!in) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1197 return 1;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1198 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1199 FILE *out = sys_fopen(to, "wb");
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1200 if(!out) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1201 fclose(in);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1202 return 1;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1203 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1204
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1205 ucx_stream_copy(in, out, (read_func)fread, (write_func)fwrite);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1206 fclose(in);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1207 fclose(out);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1208
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1209 return 0;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1210 }
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1211
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1212 typedef int (*renamefunc)(const char*,const char*);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1213
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1214 int sync_move_resource(
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1215 CmdArgs *a,
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1216 SyncDirectory *dir,
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1217 DavResource *res,
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1218 LocalResource *content,
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1219 DavBool copy,
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1220 SyncDatabase *db,
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1221 int *counter)
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1222 {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1223 renamefunc fn = copy ? copy_file : sys_rename;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1224
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1225 char *new_path = util_concat_path(dir->path, res->path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1226 char *old_path = util_concat_path(dir->path, content->path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1227
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1228 printf("%s: %s -> %s\n", copy?"copy":"move", content->path, res->path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1229 if(fn(old_path, new_path)) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1230 free(new_path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1231 free(old_path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1232 return 1;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1233 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1234 (*counter)++;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1235
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1236 char *etag = dav_get_string_property(res, "D:getetag");
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1237 char *content_hash = sync_get_content_hash(res);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1238
569
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1239 LocalResource *local = NULL;
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1240 if(copy) {
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1241 local = local_resource_copy(content, res->path);
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1242 } else {
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1243 // reuse previous LocalResource (content)
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1244 // remove it from db->resources, change path and put it back
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1245 local = ucx_map_cstr_remove(db->resources, content->path);
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1246 if(!local) {
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1247 // can't happen, but handle it nevertheless
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1248 local = content;
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1249 }
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1250 free(content->path);
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1251 local->path = strdup(res->path);
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1252 }
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1253 ucx_map_cstr_put(db->resources, local->path, local);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1254
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1255 if(sync_store_metadata(dir, new_path, local, res)) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1256 fprintf(stderr, "Cannot store metadata: %s\n", res->path);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1257 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1258
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1259 if(local->etag) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1260 free(local->etag);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1261 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1262 if(local->hash) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1263 free(local->hash);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1264 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1265
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1266 SYS_STAT s;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1267 if(sys_stat(new_path, &s)) {
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1268 fprintf(stderr,
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1269 "Cannot stat file %s: %s\n", new_path, strerror(errno));
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1270 }
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1271
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1272 // set metadata from stat
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1273 local->etag = nullstrdup(etag);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1274 local->hash = nullstrdup(content_hash);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1275
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1276 sync_set_metadata_from_stat(local, &s);
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1277 local->skipped = FALSE;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1278
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1279 return 0;
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
1280 }
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1281
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1282 int sync_get_resource(
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1283 CmdArgs *a,
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1284 SyncDirectory *dir,
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
1285 const char *path,
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1286 DavResource *res,
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1287 SyncDatabase *db,
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1288 int *counter)
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1289 {
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
1290 LocalResource *local = ucx_map_cstr_get(db->resources, path);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1291 char *local_path = create_local_path(dir, path);
49
c5759ac76c1b dav-sync detects locally removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
1292
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1293 char *link = dav_get_string_property_ns(res, DAV_NS, "link");
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1294
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
1295 char *etag = dav_get_string_property(res, "D:getetag");
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1296 SYS_STAT s;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1297 memset(&s, 0, sizeof(SYS_STAT));
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1298
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1299 char *blocksize_str = dav_get_string_property_ns(res, DAV_NS, "split");
558
1a9e6a5c1e79 fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents: 557
diff changeset
1300 uint64_t blocksize = 0;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1301 DavBool issplit = FALSE;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1302 if(blocksize_str) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1303 if(!util_strtouint(blocksize_str, &blocksize)) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1304 fprintf(stderr, "Error: split property does not contain an integer.\n");
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1305 return 1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1306 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1307 issplit = TRUE;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1308 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1309 UcxList *part_updates = NULL;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1310 uint64_t blockcount = 0;
545
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1311 char *content_hash = NULL;
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1312
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1313 if(res->iscollection && !issplit) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1314 // why are we here?
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1315 return 0;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1316 }
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1317
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1318 int ret = 0;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1319
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1320 char *tmp_path = NULL;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1321 FILE *out = NULL;
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1322 if(!link) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1323 if(!issplit) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1324 tmp_path = create_tmp_download_path(local_path);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1325 if(!tmp_path) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1326 fprintf(stderr, "Cannot create tmp path for %s\n", local_path);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1327 free(local_path);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1328 return -1;
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1329 }
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1330 out = sys_fopen(tmp_path , "wb");
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1331 } else {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1332 out = sys_fopen(local_path, "r+b");
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1333 if(!out && errno == ENOENT) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1334 out = sys_fopen(local_path, "wb");
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1335 }
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1336 }
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1337 if(!out) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1338 fprintf(stderr, "Cannot open output file: %s\n", local_path);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1339 free(local_path);
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1340 if(tmp_path) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1341 free(tmp_path);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1342 }
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1343 return -1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1344 }
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1345 }
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1346
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1347 int64_t truncate_file = -1;
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1348 if(!link) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1349 printf("get: %s\n", path);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1350 if(issplit) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1351 part_updates = sync_download_changed_parts(res, local, out, blocksize, &blockcount, &truncate_file, &ret);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1352 } else {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1353 ret = dav_get_content(res, out, (dav_write_func)fwrite);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1354 }
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1355 fclose(out);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1356 } else {
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1357 printf("link: %s -> %s\n", path, link);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1358 if(sys_symlink(link, local_path)) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1359 perror("symlink");
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1360 ret = 1;
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1361 }
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1362 }
545
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1363
560
a816e805e5db store origin of file conflicts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 559
diff changeset
1364 if(issplit || dir->hashing) {
545
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1365 if(truncate_file >= 0) {
560
a816e805e5db store origin of file conflicts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 559
diff changeset
1366 // only true if issplit is true
548
ab46acda1066 fixes truncate path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
1367 if(truncate(local_path, truncate_file)) {
ab46acda1066 fixes truncate path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
1368 perror("truncate");
ab46acda1066 fixes truncate path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 547
diff changeset
1369 }
545
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1370 }
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1371
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1372 char *res_hash = sync_get_content_hash(res);
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1373 if(res_hash) {
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1374 content_hash = res_hash;
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1375 } else {
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1376 content_hash = util_file_hash(local_path);
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1377 }
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1378 }
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1379
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1380 if(ret == 0) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1381 (*counter)++;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1382
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1383 if(tmp_path) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1384 if(dir->trash && dir->backuppull) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1385 move_to_trash(dir, local_path);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1386 }
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1387 if(sys_rename(tmp_path, local_path)) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1388 fprintf(
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1389 stderr,
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1390 "Cannot rename file %s to %s\n",
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1391 tmp_path,
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1392 local_path);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1393 perror("");
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1394 free(tmp_path);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1395 free(local_path);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1396 return -1;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1397 }
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1398 }
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1399
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1400 if(!local) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1401 // new local resource
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1402 local = calloc(1, sizeof(LocalResource));
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
1403 local->path = strdup(path);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1404 ucx_map_cstr_put(db->resources, local->path, local);
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1405 }
543
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
1406
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
1407 if(sync_store_metadata(dir, local_path, local, res)) {
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
1408 fprintf(stderr, "Cannot store metadata: %s\n", path);
2f85df8cd35e fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 542
diff changeset
1409 }
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1410
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1411 if(local->etag) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1412 free(local->etag);
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1413 }
545
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1414 if(local->hash) {
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1415 free(local->hash);
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1416 }
578
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1417 if(local->link_target) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1418 free(local->link_target);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1419 }
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1420
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1421 if(link) {
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1422 local->link_target = strdup(link);
bb1e60fada74 create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 577
diff changeset
1423 }
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1424
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1425 update_parts(local, part_updates, blockcount);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1426
547
4a249c645ae4 fixes that metadata is updated after stat in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 546
diff changeset
1427 if(sys_stat(local_path, &s)) {
4a249c645ae4 fixes that metadata is updated after stat in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 546
diff changeset
1428 fprintf(stderr,
4a249c645ae4 fixes that metadata is updated after stat in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 546
diff changeset
1429 "Cannot stat file %s: %s\n", local_path, strerror(errno));
4a249c645ae4 fixes that metadata is updated after stat in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 546
diff changeset
1430 }
4a249c645ae4 fixes that metadata is updated after stat in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 546
diff changeset
1431
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1432 // set metadata from stat
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1433 local->etag = strdup(etag);
545
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1434 if(content_hash) {
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1435 local->hash = content_hash;
268157722a0e store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 544
diff changeset
1436 }
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
1437 sync_set_metadata_from_stat(local, &s);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1438 local->skipped = FALSE;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1439 } else if(tmp_path) {
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1440 if(sys_unlink(tmp_path)) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1441 fprintf(stderr, "Cannot remove tmp file: %s\n", tmp_path);
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1442 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1443 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1444
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1445 if(tmp_path) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1446 free(tmp_path);
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1447 }
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1448 free(local_path);
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1449 return ret;
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1450 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1451
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1452 int sync_remove_local_resource(SyncDirectory *dir, LocalResource *res) {
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1453 char *local_path = create_local_path(dir, res->path);
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1454 SYS_STAT s;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1455 if(sys_stat(local_path, &s)) {
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1456 free(local_path);
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1457 return -2;
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1458 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1459
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1460 if(S_ISDIR(s.st_mode)) {
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1461 free(local_path);
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1462 return -1;
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1463 }
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1464
54
fc34bd28a22a windows fix
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 53
diff changeset
1465 if(s.st_mtime != res->last_modified) {
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1466 free(local_path);
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1467 return -2;
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1468 }
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1469
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1470 printf("delete: %s\n", res->path);
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1471 int ret = 0;
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1472 if(dir->trash) {
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1473 move_to_trash(dir, local_path);
412
dc74f736aea1 adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
1474 } else if(sys_unlink(local_path)) {
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1475 fprintf(stderr, "Cannot remove file %s\n", local_path);
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1476 ret = -2;
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1477 }
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1478 free(local_path);
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1479
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1480 return ret;
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1481 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1482
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1483 int sync_remove_local_directory(SyncDirectory *dir, LocalResource *res) {
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1484 int ret = 0;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1485 char *local_path = create_local_path(dir, res->path);
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1486
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1487 printf("delete: %s\n", res->path);
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1488 if(rmdir(local_path)) {
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1489 fprintf(stderr, "rmdir: %s : %s", local_path, strerror(errno));
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1490 ret = 1;
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1491 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1492
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
1493 free(local_path);
503
f84e64afee61 dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 502
diff changeset
1494 return ret;
50
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1495 }
9c486ea25161 dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 49
diff changeset
1496
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1497 void rename_conflict_file(SyncDirectory *dir, SyncDatabase *db, char *path, DavBool copy) {
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1498 char *local_path = create_local_path(dir, path);
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1499 char *parent = util_parent_path(local_path);
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1500
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1501 renamefunc fn = copy ? copy_file : sys_rename;
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1502
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1503 int rev = 0;
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1504 SYS_STAT s;
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1505 int loop = 1;
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1506 do {
216
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1507 char *res_parent = util_parent_path(path);
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1508 char *res_name = util_resource_name(path);
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1509
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1510 sstr_t new_path = ucx_sprintf(
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1511 "%sorig.%d.%s",
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1512 parent,
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1513 rev,
216
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1514 res_name);
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1515 sstr_t new_res_path = ucx_sprintf(
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1516 "%sorig.%d.%s",
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1517 res_parent,
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1518 rev,
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1519 res_name);
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1520
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1521
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1522 if(sys_stat(new_path.ptr, &s)) {
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1523 if(errno == ENOENT) {
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1524 loop = 0;
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1525 printf("conflict: %s\n", local_path);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
1526 if(fn(local_path, new_path.ptr)) {
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1527 //printf("errno: %d\n", errno);
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1528 fprintf(
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1529 stderr,
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1530 "Cannot rename file %s to %s\n",
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1531 local_path,
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1532 new_path.ptr);
216
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1533 } else {
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1534 LocalResource *conflict = calloc(1, sizeof(LocalResource));
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1535 conflict->path = strdup(new_res_path.ptr);
560
a816e805e5db store origin of file conflicts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 559
diff changeset
1536 conflict->conflict_source = strdup(path);
216
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1537 ucx_map_cstr_put(db->conflict, new_res_path.ptr, conflict);
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1538 }
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1539 }
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1540 }
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1541 rev++;
216
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1542 free(res_parent);
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1543 free(new_path.ptr);
216
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1544 free(new_res_path.ptr);
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1545
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1546 } while(loop);
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1547 free(parent);
216
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1548 free(local_path);
52
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1549 }
91517b874a86 added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 51
diff changeset
1550
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1551 char* create_tmp_download_path(char *path) {
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1552 char *new_path = NULL;
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1553 char *parent = util_parent_path(path);
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1554 for (int i=0;;i++) {
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1555 sstr_t np = ucx_asprintf(
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1556 ucx_default_allocator(),
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1557 "%sdownload%d-%s",
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1558 parent,
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1559 i,
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1560 util_resource_name(path));
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1561
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1562 SYS_STAT s;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1563 if(sys_stat(np.ptr, &s)) {
145
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1564 if(errno == ENOENT) {
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1565 new_path = np.ptr;
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1566 }
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1567 break;
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1568 }
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1569 free(np.ptr);
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1570 };
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1571
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1572 free(parent);
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1573 return new_path;
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1574 }
82475dc12dd4 improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 144
diff changeset
1575
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1576 void move_to_trash(SyncDirectory *dir, char *path) {
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1577 char *new_path = NULL;
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1578 for (int i=0;;i++) {
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1579 sstr_t np = ucx_asprintf(
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1580 ucx_default_allocator(),
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1581 "%s%d-%s",
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1582 dir->trash,
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1583 i,
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1584 util_resource_name(path));
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1585
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1586 SYS_STAT s;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1587 if(sys_stat(np.ptr, &s)) {
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1588 if(errno == ENOENT) {
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1589 new_path = np.ptr;
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1590 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1591 break;
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1592 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1593 free(np.ptr);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1594 };
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1595
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1596 if(!new_path) {
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1597 fprintf(stderr, "Cannot move file %s to trash.\n", path);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1598 return;
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1599 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1600
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
1601 if(sys_rename(path, new_path)) {
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1602 //printf("errno: %d\n", errno);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1603 fprintf(
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1604 stderr,
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1605 "Cannot rename file %s to %s\n",
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1606 path,
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1607 new_path);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1608 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1609
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1610 free(new_path);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1611 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
1612
216
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1613 static int res_isconflict(SyncDatabase *db, LocalResource *res) {
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1614 return ucx_map_cstr_get(db->conflict, res->path) ? 1 : 0;
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1615 }
16d6b97fbf33 dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 215
diff changeset
1616
299
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
1617 int cmd_push(CmdArgs *a, DavBool archive) {
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1618 if(a->argc != 1) {
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1619 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1620 return -1;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1621 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1622
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1623 // if there are syntax errors in the command line, fail asap.
414
ea50585ec9d9 adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
1624 SyncTagFilter* tagfilter = parse_tagfilter_string(
ea50585ec9d9 adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 412
diff changeset
1625 cmd_getoption(a, "tags"), DAV_SYNC_TAGFILTER_SCOPE_RESOURCE);
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1626 if (!tagfilter) {
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1627 fprintf(stderr, "Malformed tag filter\n");
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1628 return -1;
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1629 }
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1630
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1631 SyncDirectory *dir = scfg_get_dir(a->argv[0]);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1632 if(!dir) {
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1633 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1634 return -1;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1635 }
233
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
1636 if(scfg_check_dir(dir)) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
1637 return -1;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
1638 }
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
1639 if(cmd_getoption(a, "snapshot")) {
492
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
1640 if(dir->versioning) {
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
1641 dir->versioning->always = TRUE;
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
1642 } else {
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
1643 fprintf(stderr, "Error: versioning not configured for the sync directory\nAbort.\n");
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
1644 return -1;
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
1645 }
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
1646 }
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1647
347
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1648 int cmd = archive ? SYNC_CMD_ARCHIVE : SYNC_CMD_PUSH;
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1649 if((dir->allow_cmd & cmd) != cmd) {
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1650 fprintf(stderr, "Command '%s' is not allowed for this sync dir\n", archive ? "archive" : "push");
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1651 print_allowed_cmds(dir);
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1652 return -1;
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1653 }
b6ff6be7aa91 adds config option to disable certain commands for specific syncdirs and fixes authmethod config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 331
diff changeset
1654
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1655 Repository *repo = get_repository(sstr(dir->repository));
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1656 if(!repo) {
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1657 fprintf(stderr, "Unkown repository %s\n", dir->name);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1658 return -1;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1659 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1660
49
c5759ac76c1b dav-sync detects locally removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
1661 SyncDatabase *db = load_db(dir->database);
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1662 if(!db) {
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1663 fprintf(stderr, "Cannot load database file: %s\n", dir->database);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1664 return -1;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1665 }
218
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
1666 remove_deleted_conflicts(dir, db);
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1667
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
1668 DavSession *sn = create_session(ctx, repo, dir->collection);
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
1669 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db);
68
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 66
diff changeset
1670 if (cmd_getoption(a, "verbose")) {
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 66
diff changeset
1671 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 66
diff changeset
1672 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
f6d3db6113d3 added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents: 66
diff changeset
1673 }
556
1a58014260e0 set content-hash property after uploads when syncdir hashing is enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 554
diff changeset
1674 if(dir->hashing) {
1a58014260e0 set content-hash property after uploads when syncdir hashing is enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 554
diff changeset
1675 sn->flags |= DAV_SESSION_STORE_HASH;
1a58014260e0 set content-hash property after uploads when syncdir hashing is enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 554
diff changeset
1676 }
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1677
445
c525f049c8b7 renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 444
diff changeset
1678 DavBool restore_removed = cmd_getoption(a, "restore-removed") ? 1 : 0;
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1679 DavBool restore_modified = cmd_getoption(a, "restore-modified") ? 1 : 0;
445
c525f049c8b7 renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 444
diff changeset
1680 DavBool restore = restore_removed || restore_modified;
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1681 int depth = restore ? -1 : 0;
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1682
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1683 DavResource *root = dav_query(sn, "select D:getetag,idav:status from / with depth = %d", depth);
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1684 if(!root) {
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1685 print_resource_error(sn, "/");
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1686 dav_session_destroy(sn);
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1687 fprintf(stderr, "Abort\n");
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1688 return -1;
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1689 }
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1690
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1691 UcxMap *svrres = NULL;
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1692 if(restore) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1693 svrres = ucx_map_new(1024);
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1694 res2map(root, svrres);
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1695 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1696
220
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
1697 int cdt = cmd_getoption(a, "conflict") ? 0 : 1; // conflict detection
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
1698
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1699 // lock repository
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1700 DavBool locked = FALSE;
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
1701 char *locktokenfile = NULL;
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1702 if((dir->lockpush || cmd_getoption(a, "lock")) && !cmd_getoption(a, "nolock")) {
316
9d0505d80044 adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 313
diff changeset
1703 if(dav_lock_t(root, dir->lock_timeout)) {
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1704 print_resource_error(sn, "/");
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1705 dav_session_destroy(sn);
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1706 fprintf(stderr, "Abort\n");
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1707 return -1;
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1708 }
233
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
1709 DavLock *lock = dav_get_lock(sn, "/");
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
1710 if(lock) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
1711 printf("Lock-Token: %s\n", lock->token);
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
1712 }
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1713 locked = TRUE;
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
1714 locktokenfile = create_locktoken_file(dir->name, lock->token);
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1715 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
1716
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1717 DavBool remove_file = cmd_getoption(a, "remove") ? 1 : 0;
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1718
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1719 UcxMap *db_hashes = NULL;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1720 if(dir->hashing) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1721 db_hashes = create_hash_index(db);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1722 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1723
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1724 int sync_success = 0;
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1725 int sync_delete = 0;
561
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
1726 int sync_conflict = 0;
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1727 int sync_error = 0;
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
1728
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1729 UcxList *ls_new = NULL;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1730 UcxList *ls_modified = NULL;
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1731 UcxList *ls_conflict = NULL;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1732 UcxList *ls_update = NULL;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1733 UcxList *ls_delete = NULL;
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1734 UcxList *ls_move = NULL;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1735 UcxList *ls_copy = NULL;
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1736
51
e94bf8530d56 dav-sync deletes removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
1737 // upload all changed files
219
9792cfe63b80 added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 218
diff changeset
1738 //UcxList *resources = cmd_getoption(a, "read") ?
9792cfe63b80 added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 218
diff changeset
1739 // read_changes(dir, db) : local_scan(dir, db);
9792cfe63b80 added resolve-conflicts and delete-conflicts to help text and fixed crash with unknown cmd options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 218
diff changeset
1740 UcxList *resources = local_scan(dir, db);
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1741 UcxMap *resources_map = ucx_map_new(ucx_list_size(resources)+16);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1742
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1743 UCX_FOREACH(elm, resources) {
57
3c1ce5f203d7 refactored push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
1744 LocalResource *local_res = elm->data;
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1745 // ignore all files, that are excluded by a static filter (sync.xml)
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1746
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1747 // static include/exclude filter
417
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
1748 if(res_matches_filter(dir, local_res->path+1)) {
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1749 continue;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1750 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1751 // static tag filter
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1752 UCX_FOREACH(elm, dir->tagfilter) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1753 SyncTagFilter *tf = elm->data;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1754 if(!localres_matches_tags(dir, local_res, tf)) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1755 continue;
417
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
1756 }
f340460a8b5d disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
1757 }
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1758
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1759 // we need a fast file lookup map later to detect deleted files
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1760 ucx_map_cstr_put(resources_map, local_res->path, local_res);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1761
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1762 // dynamic tag filter
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1763 if(!localres_matches_tags(dir, local_res, tagfilter)) {
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1764 if(!remove_file) {
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1765 LocalResource *dbres = ucx_map_cstr_get(
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1766 db->resources,
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1767 local_res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1768 if(dbres) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1769 // this makes sure the file will not be deleted later
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1770 dbres->keep = TRUE;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1771 }
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1772 }
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1773 continue;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1774 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1775
561
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
1776 // skip conflict backups silently
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1777 if(res_isconflict(db, local_res)) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1778 ls_conflict = ucx_list_append(ls_conflict, local_res);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1779 continue;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1780 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1781
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1782 int is_changed = local_resource_is_changed(
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1783 dir,
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1784 db,
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1785 local_res,
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1786 svrres,
445
c525f049c8b7 renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 444
diff changeset
1787 restore_removed,
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
1788 restore_modified);
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1789 if(is_changed) {
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1790 if(local_res->isnew) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1791 ls_new = ucx_list_append(ls_new, local_res);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1792 } else {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1793 ls_modified = ucx_list_append(ls_modified, local_res);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1794 }
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
1795 } else if(local_res->metadata_updated) {
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1796 ls_update = ucx_list_append(ls_update, local_res);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1797 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1798 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1799
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1800 if(dir->hashing) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1801 // calculate hashes of all new files and check if a file
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1802 // was moved or is a copy
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1803 UcxList *elm = ls_new;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1804 while(elm) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1805 LocalResource *local = elm->data;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1806 UcxList *prev = elm->prev;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1807 UcxList *next = elm->next;
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
1808 if(local->isdirectory || local->link_target) {
551
99ef8202cd82 add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
1809 elm = elm->next;
99ef8202cd82 add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
1810 continue;
99ef8202cd82 add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
1811 }
99ef8202cd82 add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
1812
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1813 char *local_path = util_concat_path(dir->path, local->path);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1814 char *hash = util_file_hash(local_path);
551
99ef8202cd82 add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 550
diff changeset
1815 local->hash = hash;
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1816 // check if a file with this hash already exists
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1817 LocalResource *origin = ucx_map_cstr_get(db_hashes, hash);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1818 if(origin) {
552
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
1819 local->origin = local_resource_copy(origin, origin->path);
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1820 // the file is a copied/moved file
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1821 // check if the file is in the resources_map, because then
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1822 // it still exists
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1823 if(ucx_map_cstr_get(resources_map, origin->path)) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1824 ls_copy = ucx_list_append(ls_copy, local);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1825 } else {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1826 ls_move = ucx_list_append(ls_move, local);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1827 // put file in resources_map to prevent deletion
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1828 ucx_map_cstr_put(resources_map, origin->path, local);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1829 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1830 // remove list elemend from ls_new
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1831 if(prev) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1832 prev->next = next;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1833 } else {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1834 ls_new = next;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1835 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1836 if(next) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1837 next->prev = prev;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1838 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1839 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1840
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1841 free(local_path);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1842
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1843 elm = next;
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1844 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1845 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1846
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1847 // find all deleted files and cleanup the database
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1848 UcxMapIterator i = ucx_map_iterator(db->resources);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1849 LocalResource *local;
506
ceed7714846a fixes crash in dav-sync archive command when trying to remove resources from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
1850 UcxList *removed_res = NULL;
ceed7714846a fixes crash in dav-sync archive command when trying to remove resources from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
1851 UCX_MAP_FOREACH(key, local, i) {
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1852 // all filtered files should be removed from the database
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1853 if(res_matches_filter(dir, local->path+1)) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1854 ucx_map_cstr_remove(db->resources, local->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1855 continue;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1856 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1857 UCX_FOREACH(elm, dir->tagfilter) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1858 SyncTagFilter *tf = elm->data;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1859 if(!localres_matches_tags(dir, local, tf)) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1860 ucx_map_cstr_remove(db->resources, local->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1861 continue;
58
1708cba82ca3 added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents: 57
diff changeset
1862 }
403
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1863 }
8e1948eebef5 adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 402
diff changeset
1864
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1865 if(!ucx_map_get(resources_map, key)) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1866 // The current LocalResource is in the database but doesn't exist
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1867 // in the filesystem anymore. This means the file was deleted
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1868 // and should be deleted on the server
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1869 if(!archive) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1870 ls_delete = ucx_list_append(ls_delete, local);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1871 } else {
506
ceed7714846a fixes crash in dav-sync archive command when trying to remove resources from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
1872 removed_res = ucx_list_prepend(removed_res, local);
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1873 }
57
3c1ce5f203d7 refactored push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
1874 }
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1875 }
506
ceed7714846a fixes crash in dav-sync archive command when trying to remove resources from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
1876 UCX_FOREACH(elm, removed_res) {
ceed7714846a fixes crash in dav-sync archive command when trying to remove resources from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
1877 LocalResource *local = elm->data;
ceed7714846a fixes crash in dav-sync archive command when trying to remove resources from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
1878 ucx_map_cstr_remove(db->resources, local->path);
ceed7714846a fixes crash in dav-sync archive command when trying to remove resources from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 505
diff changeset
1879 }
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
1880
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1881 //
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1882 // BEGIN PUSH
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1883 //
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1884
568
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1885 int ret = 0;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1886 int error = 0;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1887
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1888 // copy/move files
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1889 DavBool copy = TRUE;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1890 if(!ls_copy) {
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1891 copy = FALSE;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1892 ls_copy = ls_move;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1893 }
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1894 for(UcxList *elm=ls_copy;elm && !sync_shutdown;elm=elm->next) {
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1895 LocalResource *local = elm->data;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1896
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1897 int err = 0;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1898 DavResource *res = dav_resource_new(sn, local->path);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1899 if(dav_exists(res)) {
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1900 printf("conflict: %s\n", local->path);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1901 local->last_modified = 0;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1902 nullfree(local->etag);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1903 local->etag = NULL;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1904 nullfree(local->hash);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1905 local->hash = NULL;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1906 local->skipped = TRUE;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1907 sync_conflict++;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1908 } else {
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1909 DavResource *origin_res = dav_resource_new(sn, local->origin->path);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1910 int origin_changed = remote_resource_is_changed(
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1911 sn,
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1912 dir,
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1913 db,
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1914 origin_res,
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1915 local->origin);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1916 if(origin_changed) {
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1917 // upload with put
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1918 ls_modified = ucx_list_prepend(ls_modified, local);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1919 } else {
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1920 printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1921 err = sync_move_remote_resource(
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1922 dir,
569
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
1923 db,
568
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1924 origin_res,
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1925 local,
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1926 copy,
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1927 &sync_success);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1928 }
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1929 }
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1930
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1931 if(err) {
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1932 sync_error++;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1933 print_resource_error(sn, res->path);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1934 ret = -1;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1935 error = 1;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1936 }
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1937
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1938 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local->path);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1939 ucx_map_cstr_put(db->resources, local->path, local);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1940
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1941 if(copy && !elm->next) {
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1942 // finished copy, begin move
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1943 elm->next = ls_move;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1944 copy = FALSE;
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1945 }
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1946 }
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
1947
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1948 // upload changed files
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1949 ls_modified = ucx_list_concat(ls_new, ls_modified);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1950
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
1951 for(UcxList *elm=ls_modified;elm && !sync_shutdown;elm=elm->next) {
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1952 LocalResource *local_res = elm->data;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1953
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1954 DavResource *res = dav_resource_new(sn, local_res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1955 if(!res) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1956 print_resource_error(sn, local_res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1957 ret = -1;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1958 sync_error++;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1959 }
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
1960
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1961 if(local_res->isdirectory) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1962 dav_exists(res);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1963 if(sn->error == DAV_NOT_FOUND) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1964 int abort = 0;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1965 // make sure to store tags for newly created cols
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1966 local_res->tags_updated = 1;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1967 // create collection
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1968 // TODO: show 405
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1969 printf("mkcol: %s\n", local_res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1970 if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1971 print_resource_error(sn, res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1972 ret = -1;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1973 sync_error++;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1974 error = 1;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1975 abort = 1;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1976 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1977
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
1978 if(local_res->metadata_updated && !abort) {
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
1979 sync_update_metadata(dir, sn, res, local_res);
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1980 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1981 } else if(sn->error != DAV_OK) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1982 // dav_exists() failed
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1983 print_resource_error(sn, local_res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1984 ret = -1;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1985 sync_error++;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1986 error = 1;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1987 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1988 } else {
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
1989 int changed = remote_resource_is_changed(sn, dir, db, res, local_res);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
1990 if(cdt && changed) {
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1991 printf("conflict: %s\n", local_res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1992 local_res->last_modified = 0;
557
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
1993 nullfree(local_res->etag);
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
1994 local_res->etag = NULL;
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
1995 nullfree(local_res->hash);
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
1996 local_res->hash = NULL;
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1997 local_res->skipped = TRUE;
564
fb482734e429 replace list of removed resources with a map (cmd_pull)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 563
diff changeset
1998 sync_conflict++;
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
1999 } else {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2000 printf("put: %s\n", local_res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2001 if(sync_put_resource(dir, res, local_res, &sync_success)) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2002 sync_error++;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2003 print_resource_error(sn, res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2004 ret = -1;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2005 error = 1;
191
0e45b04236a7 more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 190
diff changeset
2006 }
66
f8c1f685e08e some bug fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 65
diff changeset
2007 }
51
e94bf8530d56 dav-sync deletes removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
2008 }
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2009 dav_resource_free(res);
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2010
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2011 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2012 ucx_map_cstr_put(db->resources, local_res->path, local_res);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2013 //if(dbres) local_resource_free(dbres);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2014 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2015
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2016 // metadata updates
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2017 for(UcxList *elm=ls_update;elm && !sync_shutdown;elm=elm->next) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2018 LocalResource *local_res = elm->data;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2019
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2020 DavResource *res = dav_resource_new(sn, local_res->path);
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2021 if(local_res->metadata_updated) {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2022 if(!sync_update_metadata(dir, sn, res, local_res)) {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2023 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local_res->path);
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2024 ucx_map_cstr_put(db->resources, local_res->path, local_res);
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2025 }
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2026 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2027 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2028
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2029 // delete all removed files
568
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
2030 ls_delete = ucx_list_sort(ls_delete, (cmp_func)resource_pathlen_cmp, NULL);
a81cad6bb377 fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 567
diff changeset
2031
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2032 UcxList *cols = NULL;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2033 UcxList **col_list = &cols;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2034 UcxList *deletelist = ls_delete;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2035 for(int i=0;i<2;i++) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2036 // the first iteration deletes everything from ls_delete except
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2037 // all collections, which are stored in cols
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2038 // in the second run all collections will be deleted
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2039 for(UcxList *elm=deletelist;elm && !sync_shutdown;elm=elm->next) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2040 LocalResource *local = elm->data;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2041 if(local->keep) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2042 continue;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2043 }
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2044 if(sync_delete_remote_resource(dir, sn, local, &sync_delete, col_list)) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2045 if(sn->error != DAV_NOT_FOUND) {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2046 print_resource_error(sn, local->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2047 sync_error++;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2048 break;
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2049 }
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2050 } else {
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2051 LocalResource *dbres = ucx_map_cstr_remove(db->resources, local->path);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2052 //local_resource_free(dbres);
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2053 }
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2054 }
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2055 deletelist = cols;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2056 col_list = NULL;
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2057 }
51
e94bf8530d56 dav-sync deletes removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 50
diff changeset
2058
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2059 // unlock repository
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2060 if(locked) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2061 if(dav_unlock(root)) {
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2062 print_resource_error(sn, "/");
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2063 ret = -1;
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
2064 } else {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
2065 locked = FALSE;
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2066 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2067 }
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2068
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2069 // store db
521
c5bbae4b3cca extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 516
diff changeset
2070 if(store_db(db, dir->database, dir->db_settings)) {
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2071 fprintf(stderr, "Cannot store sync db\n");
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
2072 ret = -2;
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2073 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2074
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2075 // cleanup
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
2076 if(!locked && locktokenfile) {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
2077 remove(locktokenfile);
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
2078 }
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
2079
501
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2080 //ucx_map_free_content(db->resources, (ucx_destructor)local_resource_free);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2081 //ucx_map_free(db->resources);
868da3f76267 dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 497
diff changeset
2082
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2083 dav_session_destroy(sn);
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
2084
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
2085 // Report
223
cbbdf207e67e fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 222
diff changeset
2086 if(ret != -2) {
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2087 char *str_success = sync_success == 1 ? "file" : "files";
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2088 char *str_delete = sync_delete == 1 ? "file" : "files";
561
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
2089 char *str_conflict = sync_conflict == 1 ? "conflict" : "conflicts";
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2090 char *str_error = sync_error == 1 ? "error" : "errors";
299
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
2091
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
2092 printf("Result: %d %s pushed, ", sync_success, str_success);
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
2093 if(!archive) {
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
2094 printf("%d %s deleted, ", sync_delete, str_delete);
c517502d3e38 adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 296
diff changeset
2095 }
561
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
2096 printf("%d %s, %d %s\n",
5e6df4f502d3 harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents: 560
diff changeset
2097 sync_conflict, str_conflict, sync_error, str_error);
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2098 }
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
2099
221
e22c29b7ee2f using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
2100 return ret;
46
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2101 }
0542668d0f26 added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2102
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2103 static int localres_cmp_path(LocalResource *a, LocalResource *b, void *n) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2104 return strcmp(a->path, b->path);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2105 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2106
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2107 int cmd_restore(CmdArgs *a) {
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2108 char *syncdir = cmd_getoption(a, "syncdir");
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2109
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2110 if(!syncdir && a->argc == 0) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2111 fprintf(stderr, "No syncdir or files specified\n");
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2112 return -1;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2113 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2114
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2115 char *version = cmd_getoption(a, "version");
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2116 if(version) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2117 if(a->argc != 1) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2118 fprintf(stderr, "If the -V option is enabled, only one file can be specified\n");
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2119 return -1;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2120 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2121 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2122
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2123 SyncDirectory *dir = NULL;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2124 UcxMap *files = NULL;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2125 if(syncdir) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2126 dir = scfg_get_dir(syncdir);
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2127 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2128
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2129 LocalResource nres;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2130 if(a->argc > 0) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2131 files = ucx_map_new(a->argc+8);
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2132 // get all specified files and check the syncdir
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2133 SyncDirectory *sd = NULL;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2134 for(int i=0;i<a->argc;i++) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2135 SyncFile f;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2136 int err = sync_get_file(a, a->argv[i], &f, FALSE);
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2137 if(err) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2138 sync_print_get_file_err(a->argv[i], err);
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2139 return 1;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2140 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2141 if(!sd) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2142 sd = f.dir;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2143 } else {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2144 if(f.dir != sd) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2145 fprintf(stderr, "Not all files are in the same syncdir\n");
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2146 return 1;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2147 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2148 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2149
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2150 ucx_map_cstr_put(files, f.path, &nres);
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2151 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2152 dir = sd;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2153 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2154
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2155 if(!dir) {
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2156 fprintf(stderr, "Unknown sync dir: %s\n", syncdir);
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2157 return -1;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2158 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2159 if(scfg_check_dir(dir)) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2160 return -1;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2161 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2162
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2163 if((dir->allow_cmd & SYNC_CMD_RESTORE) != SYNC_CMD_RESTORE) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2164 fprintf(stderr, "Command ''restore'' is not allowed for this sync dir\n");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2165 print_allowed_cmds(dir);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2166 return -1;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2167 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2168
528
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2169 DavBool restore_modified = cmd_getoption(a, "restore-modified") ? 1 : 0;
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2170 DavBool restore_removed = cmd_getoption(a, "restore-removed") ? 1 : 0;
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2171 if(!restore_modified && !restore_removed) {
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2172 restore_modified = 1;
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2173 restore_removed = 1;
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2174 }
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2175
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2176 SyncDatabase *db = load_db(dir->database);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2177 if(!db) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2178 fprintf(stderr, "Cannot load database file: %s\n", dir->database);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2179 return -1;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2180 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2181 remove_deleted_conflicts(dir, db);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2182
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2183 UcxList *modified = NULL;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2184 UcxList *deleted = NULL;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2185
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2186 // iterate over all db resources and check if any resource is
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2187 // modified or deleted
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2188 UcxMapIterator i = ucx_map_iterator(files ? files : db->resources);
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2189 LocalResource *resource;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2190 UCX_MAP_FOREACH(key, resource, i) {
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2191 if(resource == &nres) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2192 resource = ucx_map_get(db->resources, key);
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2193 if(!resource) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2194 continue;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2195 }
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2196 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2197
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
2198 char *file_path = create_local_path(dir, resource->path);
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2199 SYS_STAT s;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2200 if(sys_stat(file_path, &s)) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2201 if(errno == ENOENT) {
528
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2202 if(restore_removed) {
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2203 deleted = ucx_list_prepend(deleted, resource);
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2204 }
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2205 } else {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2206 fprintf(stderr, "Cannot stat file: %s\n", file_path);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2207 perror("");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2208 }
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2209 } else {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2210 if(files) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2211 modified = ucx_list_prepend(modified, resource);
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2212 } else if(!resource->isdirectory && !S_ISDIR(s.st_mode)) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2213 if(resource->last_modified != s.st_mtime || resource->size != s.st_size) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2214 if(restore_modified) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2215 modified = ucx_list_prepend(modified, resource);
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2216 }
528
4c9c8c017d52 adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 527
diff changeset
2217 }
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2218 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2219 }
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2220
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2221 free(file_path);
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2222 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2223
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2224 if(files) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2225 ucx_map_free(files);
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2226 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2227
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2228 int ret = 0;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2229
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2230 // create DavSession
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2231 Repository *repo = get_repository(sstr(dir->repository));
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2232 if(!repo) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2233 fprintf(stderr, "Unkown repository %s\n", dir->name);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2234 return -1;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2235 }
497
411bd1098175 fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 495
diff changeset
2236 DavSession *sn = create_session(ctx, repo, dir->collection);
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2237 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2238 if (cmd_getoption(a, "verbose")) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2239 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2240 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2241 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2242
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2243 // lock repository
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2244 char *locktokenfile = NULL;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2245 DavBool locked = FALSE;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2246 DavResource *root = dav_resource_new(sn, "/");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2247 root->iscollection = TRUE;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2248 if((dir->lockpush || cmd_getoption(a, "lock")) && !cmd_getoption(a, "nolock")) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2249 if(dav_lock_t(root, dir->lock_timeout)) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2250 print_resource_error(sn, "/");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2251 dav_session_destroy(sn);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2252 fprintf(stderr, "Abort\n");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2253 return -1;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2254 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2255 DavLock *lock = dav_get_lock(sn, "/");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2256 if(lock) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2257 printf("Lock-Token: %s\n", lock->token);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2258 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2259 locked = TRUE;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2260 locktokenfile = create_locktoken_file(dir->name, lock->token);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2261 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2262
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2263 int sync_success = 0;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2264 int sync_error = 0;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2265
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2266 UcxList *resources = ucx_list_concat(modified, deleted);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2267 resources = ucx_list_sort(resources, (cmp_func)localres_cmp_path, NULL);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2268
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2269 UCX_FOREACH(elm, resources) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2270 LocalResource *resource = elm->data;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2271
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2272 DavResource *res = dav_get(sn, resource->path, "D:getetag,idav:status,idav:version-collection,idav:finfo,idav:xattributes");
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2273 if(!res) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2274 printf("skip: %s\n", resource->path);
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2275 continue;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2276 }
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2277 char *status = dav_get_string_property(res, "idav:status");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2278 if(status && !strcmp(status, "broken")) {
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2279 fprintf(stderr, "Resource %s broken\n", res->path);
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2280 continue;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2281 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2282
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2283 DavResource *vres = NULL;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2284 if(version) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2285 if(dir->versioning->type == VERSIONING_SIMPLE) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2286 vres = versioning_simple_find(res, version);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2287 } else if(dir->versioning->type == VERSIONING_DELTAV) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2288 vres = versioning_deltav_find(res, version);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2289 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2290 if(!vres) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2291 fprintf(stderr, "Cannot find specified version for resource %s\n", res->path);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2292 ret = 1;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2293 break;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2294 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2295 } else {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2296 vres = res;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2297 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2298
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2299 // download the resource
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2300 if(!sync_shutdown) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2301 if(resource->isdirectory) {
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
2302 char *local_path = create_local_path(dir, res->path);
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2303 if(sys_mkdir(local_path) && errno != EEXIST) {
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2304 fprintf(stderr,
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2305 "Cannot create directory %s: %s",
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2306 local_path, strerror(errno));
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2307 }
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2308 free(local_path);
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2309 } else {
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2310 if(sync_get_resource(a, dir, res->path, vres, db, &sync_success)) {
532
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2311 fprintf(stderr, "sync_get_resource failed for resource: %s\n", res->path);
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2312 sync_error++;
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2313 }
aeda47714978 fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
2314 }
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2315 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2316 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2317
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2318 // unlock repository
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2319 if(locked) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2320 if(dav_unlock(root)) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2321 print_resource_error(sn, "/");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2322 ret = -1;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2323 } else {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2324 locked = FALSE;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2325 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2326 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2327
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2328 // store db
521
c5bbae4b3cca extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 516
diff changeset
2329 if(store_db(db, dir->database, dir->db_settings)) {
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2330 fprintf(stderr, "Cannot store sync db\n");
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2331 ret = -2;
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2332 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2333
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2334 // cleanup
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2335 dav_session_destroy(sn);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2336
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2337 if(!locked && locktokenfile) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2338 remove(locktokenfile);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2339 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2340
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2341 // Report
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2342 if(ret != -2) {
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2343 char *str_success = sync_success == 1 ? "file" : "files";
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2344 char *str_error = sync_error == 1 ? "error" : "errors";
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2345 printf("Result: %d %s pulled, %d %s\n",
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2346 sync_success, str_success,
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2347 sync_error, str_error);
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2348 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2349
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2350 return ret;
490
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2351 }
d94c4fd35c21 adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 479
diff changeset
2352
49
c5759ac76c1b dav-sync detects locally removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 48
diff changeset
2353 UcxList* local_scan(SyncDirectory *dir, SyncDatabase *db) {
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2354 UcxList *resources = NULL;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2355
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2356 char *path = strdup("/");
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2357 UcxList *stack = ucx_list_prepend(NULL, path);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2358 while(stack) {
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2359 // get a directory path from the stack and read all entries
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2360 // if an entry is a directory, put it on the stack
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2361
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2362 char *p = stack->data;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2363 stack = ucx_list_remove(stack, stack);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
2364 char *local_path = create_local_path(dir, p);
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
2365 SYS_DIR local_dir = sys_opendir(local_path);
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2366
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2367 if(!local_dir) {
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2368 fprintf(stderr, "Cannot open directory %s\n", local_path);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2369 } else {
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
2370 SysDirEnt *ent;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
2371 while((ent = sys_readdir(local_dir)) != NULL) {
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
2372 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) {
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2373 continue;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2374 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2375
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
2376 char *new_path = util_concat_path(p, ent->name);
573
b8f798d240ab change local_resource_new signature
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 570
diff changeset
2377 LocalResource *res = local_resource_new(dir, db, new_path);
b8f798d240ab change local_resource_new signature
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 570
diff changeset
2378 if(res->isdirectory) {
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
2379 resources = ucx_list_append(resources, res);
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2380 stack = ucx_list_prepend(stack, new_path);
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2381 } else if(res) {
57
3c1ce5f203d7 refactored push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
2382 resources = ucx_list_append(resources, res);
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2383 free(new_path);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2384 } else {
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2385 free(new_path);
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2386 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2387 }
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
2388 sys_closedir(local_dir);
55
4cb389452a44 replaced readdir_r with readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
2389
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2390 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2391 free(local_path);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2392 free(p);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2393 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2394
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2395 return resources;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2396 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
2397
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2398 UcxList* read_changes(SyncDirectory *dir, SyncDatabase *db) {
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2399 UcxProperties *parser = ucx_properties_new();
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2400 parser->delimiter = ':';
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2401
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2402 UcxList *resources = NULL;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2403 sstr_t name;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2404 sstr_t value;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2405
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2406 char buf[STDIN_BUF_SIZE];
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2407 size_t r;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2408 while(!feof(stdin)) {
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2409 r = fread(buf, 1, STDIN_BUF_SIZE, stdin);
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2410 ucx_properties_fill(parser, buf, r);
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2411 while(ucx_properties_next(parser, &name, &value)) {
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2412 if(value.length == 0) {
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2413 fprintf(stderr, "Wrong input\n");
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2414 continue;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2415 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2416 if(value.ptr[0] == '"'
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2417 && value.length > 2
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2418 && value.ptr[value.length - 1] == '"')
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2419 {
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2420 value.ptr[value.length - 1] = '\0';
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2421 value.ptr++;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2422 value.length -= 2;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2423 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2424 value = sstrdup(value);
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2425
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2426 if(!sstrcmp(name, S("put"))) {
573
b8f798d240ab change local_resource_new signature
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 570
diff changeset
2427 LocalResource *res = local_resource_new(dir, db, value.ptr);
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2428 if(res) {
57
3c1ce5f203d7 refactored push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
2429 resources = ucx_list_append(resources, res);
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2430 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2431 } else if(!sstrcmp(name, S("remove"))) {
288
cd3846cc8b25 fixes memory leaks detected by cppcheck (or annotates them at least)
Mike Becker <universe@uap-core.de>
parents: 274
diff changeset
2432 ucx_map_sstr_remove(db->resources, value);
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2433 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2434
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2435 free(value.ptr);
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2436 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2437 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2438 ucx_properties_free(parser);
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2439
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2440 return resources;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2441 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2442
573
b8f798d240ab change local_resource_new signature
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 570
diff changeset
2443 LocalResource* local_resource_new(SyncDirectory *dir, SyncDatabase *db, char *path) {
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
2444 char *file_path = create_local_path(dir, path);
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
2445 SYS_STAT s;
574
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2446 if(sys_lstat(file_path, &s)) {
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2447 fprintf(stderr, "Cannot stat file %s\n", file_path);
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2448 free(file_path);
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2449 return NULL;
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2450 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2451
574
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2452 LocalResource *res = calloc(1, sizeof(LocalResource));
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2453 res->mode = s.st_mode & 07777;
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2454 res->uid = s.st_uid;
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2455 res->gid = s.st_gid;
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2456 res->last_modified = s.st_mtime;
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2457 if(!S_ISDIR(s.st_mode)) {
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2458 res->path = strdup(path);
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2459 res->size = s.st_size;
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2460 } else {
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
2461 res->path = util_concat_path(path, "/");
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
2462 res->isdirectory = 1;
574
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2463 }
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2464
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2465 if(S_ISLNK(s.st_mode)) {
576
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2466 off_t l_sz = s.st_size + 16;
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2467 size_t lnksize = l_sz > 256 ? l_sz : 256;
574
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2468 char *lnkbuf = malloc(lnksize);
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2469
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2470 ssize_t len = 0;
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2471 for(int i=0;i<4;i++) {
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2472 // we try to read the link at most 4 times
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2473 // only repeat if the buffer is too small
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2474 len = sys_readlink(file_path, lnkbuf, lnksize);
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2475 if(len != lnksize) {
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2476 break;
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2477 }
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2478 lnksize *= 2;
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2479 lnkbuf = realloc(lnkbuf, lnksize);
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2480 }
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2481
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2482 if(len > 0) {
576
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2483 // readlink successful
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2484 lnkbuf[len] = 0;
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2485
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2486 char *normalized = NULL;
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2487 if(lnkbuf[0] != '/') {
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2488 char *link_parent = util_parent_path(res->path);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2489 char *abs_link_parent = util_concat_path(dir->path, link_parent);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2490 char *link = util_concat_path(abs_link_parent, lnkbuf);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2491 normalized = util_path_normalize(link);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2492 free(abs_link_parent);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2493 free(link_parent);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2494 free(link);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2495 } else {
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2496 normalized = util_path_normalize(lnkbuf);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2497 }
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2498
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2499 if(util_path_isrelated(dir->path, normalized)) {
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2500 // the link points to a file inside the syncdir
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2501 char *rel = util_create_relative_path(normalized, file_path);
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2502 res->link_target = rel;
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2503 }
62cc92445234 store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 574
diff changeset
2504 free(normalized);
574
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2505 }
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2506
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2507 free(lnkbuf);
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2508 }
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2509
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2510 free(file_path);
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2511
c36eddf167a8 read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 573
diff changeset
2512 return res;
53
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2513 }
ddc4efc9b0f8 added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
2514
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2515 int local_resource_is_changed(
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2516 SyncDirectory *dir,
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2517 SyncDatabase *db,
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2518 LocalResource *res,
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2519 UcxMap *svrres,
445
c525f049c8b7 renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 444
diff changeset
2520 DavBool restore_removed,
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2521 DavBool restore_modified)
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2522 {
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2523 LocalResource *db_res = ucx_map_cstr_get(db->resources, res->path);
366
5228b912c925 adds technical foundation to just push tag updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 363
diff changeset
2524 res->tags_updated = 0;
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2525 if(db_res) {
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2526 if(svrres) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2527 DavResource *remote = ucx_map_cstr_get(svrres, res->path);
445
c525f049c8b7 renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 444
diff changeset
2528 if(restore_removed && !remote) {
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2529 return 1;
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2530 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2531 if(!res->isdirectory && restore_modified && remote) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2532 char *etag = dav_get_string_property(remote, "D:getetag");
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2533 if(!etag || (db_res->etag && strcmp(etag, db_res->etag))) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2534 res->restore = TRUE;
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2535 return 1;
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2536 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2537 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2538 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2539
366
5228b912c925 adds technical foundation to just push tag updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 363
diff changeset
2540 res->tags_updated = db_res->tags_updated;
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2541 if(db_res->etag) {
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2542 res->etag = strdup(db_res->etag);
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2543 }
370
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
2544 if(db_res->tags_hash) {
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
2545 res->tags_hash = strdup(db_res->tags_hash);
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
2546 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2547 if(db_res->remote_tags_hash) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2548 res->remote_tags_hash = strdup(db_res->remote_tags_hash);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2549 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2550 if(db_res->xattr_hash) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2551 res->xattr_hash = strdup(db_res->xattr_hash);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2552 }
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2553
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2554 if(dir->tagconfig && dir->tagconfig->detect_changes && !res->tags_updated) {
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2555 UcxBuffer *tags = sync_get_file_tag_data(dir, res);
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2556 if(tags) {
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2557 if(db_res->tags_hash) {
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2558 char *hash = dav_create_hash(tags->space, tags->size);
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2559 if(strcmp(hash, db_res->tags_hash)) {
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2560 res->tags_updated = 1;
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2561 }
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2562 free(hash);
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2563 } else {
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2564 res->tags_updated = 1;
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2565 }
370
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
2566 } else if(db_res->tags_hash) {
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
2567 res->tags_updated = 1; // tags removed
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2568 }
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2569 res->metadata_updated = res->tags_updated;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2570 }
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2571
539
8deb52292c99 fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 536
diff changeset
2572 if((dir->metadata & FINFO_MODE) == FINFO_MODE) {
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2573 if(db_res->mode != res->mode) {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2574 res->finfo_updated = 1;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2575 res->metadata_updated = 1;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2576 }
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2577 }
539
8deb52292c99 fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 536
diff changeset
2578 if((dir->metadata & FINFO_OWNER) == FINFO_OWNER) {
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2579 if(db_res->uid != res->uid || db_res->gid != res->gid) {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2580 res->finfo_updated = 1;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2581 res->metadata_updated = 1;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2582 }
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2583 }
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2584
539
8deb52292c99 fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 536
diff changeset
2585 if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) {
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
2586 char *path = create_local_path(dir, db_res->path);
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2587 XAttributes *xattr = file_get_attributes(path);
524
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
2588 // test if xattr are added, removed or changed
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2589 if((db_res->xattr_hash && !xattr) ||
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2590 (!db_res->xattr_hash && xattr) ||
524
d53fd1006485 store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 523
diff changeset
2591 (xattr && db_res->xattr_hash && strcmp(xattr->hash, db_res->xattr_hash)))
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2592 {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2593 res->metadata_updated = 1;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2594 res->xattr_updated = 1;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2595 res->xattr = xattr;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2596 } else if(xattr) {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2597 xattributes_free(xattr);
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
2598 }
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2599 }
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
2600
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
2601 if(nullstrcmp(db_res->link_target, res->link_target)) {
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
2602 res->link_updated = 1;
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
2603 } else if(db_res->last_modified == res->last_modified && db_res->size == res->size) {
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2604 return 0;
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
2605 }
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2606
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2607 if(db_res->parts) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2608 // if the resource is splitted, move the part infos to the new
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2609 // LocalResource obj, because we need it later
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2610 res->parts = db_res->parts;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2611 res->numparts = db_res->numparts;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2612 db_res->parts = NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2613 db_res->numparts = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2614 }
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2615 } else {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2616 res->tags_updated = 1;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2617 res->finfo_updated = 1;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2618 res->xattr_updated = 1;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2619 res->metadata_updated = 1;
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
2620 res->isnew = 1;
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2621 }
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2622 return 1;
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2623 }
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2624
220
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2625 int remote_resource_is_changed(
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2626 DavSession *sn,
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2627 SyncDirectory *dir,
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2628 SyncDatabase *db,
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2629 DavResource *remote,
220
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2630 LocalResource *res)
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2631 {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2632 DavPropName properties[] = {
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2633 {"DAV:", "getetag"},
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2634 {DAV_NS, "tags"},
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2635 {DAV_NS, "version-collection"},
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
2636 {DAV_NS, "content-hash"},
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
2637 {DAV_NS, "split" },
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
2638 {DAV_NS, "link" }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2639 };
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
2640 int err = dav_load_prop(remote, properties, 6);
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2641
444
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2642 if(res->restore) {
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2643 return 0;
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2644 }
761dc4867208 adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 417
diff changeset
2645
220
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2646 int ret = 0;
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2647 if(err == 0) {
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
2648 char *etag = dav_get_string_property(remote, "D:getetag");
542
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
2649 char *hash = sync_get_content_hash(remote);
557
90ad7324bbbc fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 556
diff changeset
2650 if(hash && res->hash) {
567
b0ce8b27978b implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 566
diff changeset
2651 if(strcmp(hash, res->hash)) {
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
2652 ret = 1;
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
2653 }
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
2654 } else if(!res->etag) {
318
7e0694423838 dav-sync bugfix: files that are not in the db but on the server should not be pushed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
2655 // the resource is on the server and the client has no etag
7e0694423838 dav-sync bugfix: files that are not in the db but on the server should not be pushed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
2656 ret = 1;
7e0694423838 dav-sync bugfix: files that are not in the db but on the server should not be pushed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
2657 } else if(etag) {
220
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2658 sstr_t e = sstr(etag);
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2659 if(sstrprefix(e, S("W/"))) {
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2660 e = sstrsubs(e, 2);
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2661 }
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2662 if(strcmp(e.ptr, res->etag)) {
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2663 ret = 1;
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2664 }
318
7e0694423838 dav-sync bugfix: files that are not in the db but on the server should not be pushed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
2665 } else {
7e0694423838 dav-sync bugfix: files that are not in the db but on the server should not be pushed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
2666 // something weird is happening, the server must support etags
7e0694423838 dav-sync bugfix: files that are not in the db but on the server should not be pushed
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 316
diff changeset
2667 fprintf(stderr, "Warning: resource %s has no etag\n", remote->href);
220
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2668 }
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2669 }
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2670 return ret;
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2671 }
f1b3873a6525 added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
2672
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2673 size_t resource_get_blocksize(SyncDirectory *dir, LocalResource *local, DavResource *res, off_t filesize) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2674 size_t local_blocksize = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2675 if(local->blocksize < 0) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2676 // file splitting disabled
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2677 return 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2678 } else if(local->blocksize > 0) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2679 local_blocksize = (size_t)local->blocksize;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2680 } else {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2681 UCX_FOREACH(elm, dir->splitconfig) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2682 SplitConfig *sc = elm->data;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2683 if(sc->pattern) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2684 if(regexec(sc->pattern, local->path, 0, NULL, 0) != 0) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2685 continue;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2686 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2687 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2688
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2689 if(sc->minsize > 0) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2690 if(filesize < sc->minsize) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2691 continue;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2692 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2693 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2694
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2695 local_blocksize = sc->blocksize;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2696 break;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2697 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2698 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2699
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2700 size_t svr_blocksize = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2701 char *svr_blocksize_str = dav_get_string_property_ns(res, DAV_NS, "split");
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2702 if(svr_blocksize_str) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2703 uint64_t i = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2704 if(util_strtouint(svr_blocksize_str, &i)) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2705 svr_blocksize = (size_t)i;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2706 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2707 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2708
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2709 if(local_blocksize > 0 && svr_blocksize > 0) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2710 fprintf(stderr, "Warning: Blocksize mismatch: %s: local: %zu server: %zu\n", local->path, local_blocksize, svr_blocksize);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2711 return svr_blocksize;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2712 } else if(local_blocksize > 0) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2713 return local_blocksize;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2714 } else if(svr_blocksize > 0) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2715 return svr_blocksize;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2716 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2717
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2718 return 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2719
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2720 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
2721
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2722 int resource_pathlen_cmp(LocalResource *res1, LocalResource *res2, void *n) {
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2723 size_t s1 = strlen(res1->path);
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2724 size_t s2 = strlen(res2->path);
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2725 if(s1 < s2) {
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2726 return 1;
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2727 } else if(s1 > s2) {
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2728 return -1;
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2729 } else {
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2730 return 0;
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2731 }
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2732 }
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
2733
533
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2734 DavResource *versioning_simple_find(DavResource *res, const char *version) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2735 char *vcol_href = dav_get_string_property_ns(res, DAV_NS, VERSION_PATH_PROPERTY);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2736 if(!vcol_href) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2737 return NULL;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2738 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2739 DavResource *vcol = dav_resource_new_href(res->session, vcol_href);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2740 if(!vcol) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2741 return NULL;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2742 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2743
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2744
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2745 if(dav_load_prop(vcol, defprops, numdefprops)) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2746 print_resource_error(res->session, vcol->path);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2747 dav_resource_free(vcol);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2748 return NULL;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2749 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2750
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2751 DavResource *ret = NULL;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2752 DavResource *child = vcol->children;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2753 while(child) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2754 DavResource *next = child->next;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2755 if(!strcmp(child->name, version)) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2756 ret = child;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2757 } else {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2758 dav_resource_free(child);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2759 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2760 child = next;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2761 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2762 dav_resource_free(vcol);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2763
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2764 return ret;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2765 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2766
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2767 // TODO: remove code dup (main.c: find_version)
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2768 DavResource* versioning_deltav_find(DavResource *res, const char *version) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2769 DavResource *list = dav_versiontree(res, "D:getetag,idav:status,idav:finfo,idav:xattributes,idav:tags");
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2770 DavResource *ret = NULL;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2771 while(list) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2772 DavResource *next = list->next;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2773 if(!ret) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2774 char *vname = dav_get_string_property(list, "D:version-name");
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2775 if(vname && !strcmp(vname, version)) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2776 ret = list;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2777 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2778 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2779 if(list != ret) {
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2780 dav_resource_free(list);
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2781 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2782 list = next;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2783 }
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2784 return ret;
5b9f20aa88c2 adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 532
diff changeset
2785 }
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
2786
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2787 int sync_set_status(DavResource *res, char *status) {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2788 DavResource *resource = dav_resource_new(res->session, res->path);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2789 dav_set_string_property(resource, "idav:status", status);
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2790 int ret = dav_store(resource);
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2791 dav_resource_free(resource);
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2792 return ret;
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2793 }
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2794
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2795 int sync_remove_status(DavResource *res) {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2796 DavResource *resource = dav_resource_new(res->session, res->path);
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2797 dav_remove_property(resource, "idav:status");
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2798 int ret = dav_store(resource);
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2799 dav_resource_free(resource);
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2800 return ret;
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2801 }
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
2802
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2803 int sync_tags_equal(UcxList *tags1, UcxList *tags2) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2804 if(!tags1) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2805 return tags2 ? 0 : 1;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2806 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2807 if(!tags2) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2808 return tags1 ? 0 : 1;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2809 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2810
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2811 UcxMap *map1 = ucx_map_new(32);
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2812 UCX_FOREACH(elm, tags1) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2813 DavTag *t = elm->data;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2814 ucx_map_cstr_put(map1, t->name, t);
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2815 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2816
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2817 int equal = 1;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2818 int i = 0;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2819 UCX_FOREACH(elm, tags2) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2820 DavTag *t = elm->data;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2821 if(!ucx_map_cstr_get(map1, t->name)) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2822 equal = 0;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2823 break;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2824 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2825 i++;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2826 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2827
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2828 if(i != map1->count) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2829 equal = 0;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2830 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2831 ucx_map_free(map1);
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2832 return equal;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2833 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2834
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2835 int sync_store_metadata(SyncDirectory *dir, const char *path, LocalResource *local, DavResource *res) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2836 int ret = 0;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2837
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2838 DavXmlNode *fileinfo = dav_get_property_ns(res, DAV_NS, "finfo");
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2839 if(fileinfo) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2840 FileInfo f;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2841 finfo_get_values(fileinfo, &f);
539
8deb52292c99 fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 536
diff changeset
2842 if((dir->metadata & FINFO_DATE) == FINFO_DATE && f.date_set) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2843 // set mtime
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2844 struct utimbuf t;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2845 t.actime = f.last_modified;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2846 t.modtime = f.last_modified;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2847 if(utime(path, &t)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2848 fprintf(stderr, "utime failed for file: %s : %s\n", path, strerror(errno));
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2849 ret = 1;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2850 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2851 }
539
8deb52292c99 fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 536
diff changeset
2852 if((dir->metadata & FINFO_MODE) == FINFO_MODE && f.mode_set) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2853 // set mode
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2854 if(chmod(path, f.mode)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2855 fprintf(stderr, "chmod failed for file: %s : %s\n", path, strerror(errno));
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2856 ret = 1;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2857 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2858 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2859 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2860
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2861 DavXmlNode *xattr_prop = dav_get_property_ns(res, DAV_NS, "xattributes");
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2862 if(xattr_prop) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2863 XAttributes *xattr = xml_get_attributes(xattr_prop);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2864 if(xattr) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2865 if(!sync_store_xattr(dir, path, xattr)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2866 if(local->xattr_hash) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2867 free(local->xattr_hash);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2868 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2869 local->xattr_hash = xattr->hash;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2870 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2871 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2872 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2873
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2874 if(sync_store_tags(dir, path, local, res)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2875 ret = 1;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2876 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2877
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2878 return ret;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2879 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2880
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2881 int sync_store_xattr(SyncDirectory *dir, const char *path, XAttributes *xattr) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2882 for(int i=0;i<xattr->nattr;i++) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2883 sstr_t value = xattr->values[i];
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2884 if(xattr_set(path, xattr->names[i], value.ptr, value.length)) {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2885 fprintf(
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2886 stderr,
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2887 "Cannot store xattr '%s' for file: %s\n",
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2888 xattr->names[i],
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2889 path);
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2890 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2891 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2892 return 0;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2893 }
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2894
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2895 int sync_store_tags(SyncDirectory *dir, const char *path, LocalResource *local, DavResource *res) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2896 if(!dir->tagconfig) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2897 return 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2898 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2899
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2900 UcxList *tags = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2901 if(dir->tagconfig) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2902 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags");
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2903 if(tagsprop) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2904 tags = parse_dav_xml_taglist(tagsprop);
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
2905
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2906 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2907 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2908
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2909 DavBool store_tags = FALSE;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2910 DavBool tags_changed = FALSE;
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2911 UcxList *local_tags = sync_get_file_tags(dir, local, &tags_changed, NULL);
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2912 if(tags_changed) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2913 switch(dir->tagconfig->conflict) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2914 case TAG_NO_CONFLICT: {
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2915 store_tags = TRUE;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2916 break;
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2917 }
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2918 case TAG_KEEP_LOCAL: {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2919 store_tags = FALSE;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2920 break;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2921 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2922 case TAG_KEEP_REMOTE: {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2923 store_tags = TRUE;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2924 local->tags_updated = FALSE;
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
2925 break;
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2926 }
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2927 case TAG_MERGE: {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
2928 UcxList *new_tags = merge_tags(local_tags, tags);
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2929 // TODO: free tags and local_tags
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2930 tags = new_tags;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2931 store_tags = TRUE;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2932 // make sure the merged tags will be pushed the next time
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2933 local->tags_updated = TRUE;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2934 break;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2935 }
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2936 }
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2937 } else {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2938 if(!sync_tags_equal(tags, local_tags)) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2939 store_tags = TRUE;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2940 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2941 // TODO: free local_tags
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2942 }
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2943
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2944 if(!store_tags) {
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2945 return 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2946 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2947
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2948 int ret = sync_store_tags_local(dir, local, path, tags);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2949
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2950 // TODO: free stuff
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2951
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2952 return ret;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2953 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2954
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2955 int sync_store_tags_local(SyncDirectory *dir, LocalResource *local, const char *path, UcxList *tags) {
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2956 int ret = 0;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2957 if(dir->tagconfig->store == TAG_STORE_XATTR) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2958 UcxBuffer *data = NULL;
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2959 if(tags) {
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2960 switch(dir->tagconfig->local_format) {
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2961 default: break;
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2962 case TAG_FORMAT_TEXT: {
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2963 data = create_text_taglist(tags);
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2964 break;
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2965 }
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2966 case TAG_FORMAT_CSV: {
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2967 data = create_csv_taglist(tags);
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2968 break;
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2969 }
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2970 case TAG_FORMAT_MACOS: {
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2971 data = create_macos_taglist(tags);
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2972 break;
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2973 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
2974 }
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2975
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2976 if(data) {
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
2977 char *data_hash = dav_create_hash(data->space, data->size);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2978 int update = 1;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2979 if(local) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2980 if(!local->tags_hash || strcmp(data_hash, local->tags_hash)) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
2981 //printf("update: %s\n", local->path);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2982 } else {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2983 update = 0;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2984 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2985 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
2986 if(update) {
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
2987 ret = xattr_set(path, dir->tagconfig->xattr_name, data->space, data->pos);
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2988 if(local) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2989 if(local->tags_hash) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2990 free(local->tags_hash);
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2991 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2992 local->tags_hash = data_hash;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2993 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2994 } else {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
2995 free(data_hash);
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
2996 }
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2997 ucx_buffer_free(data);
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2998 } else {
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
2999 ret = -1;
363
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
3000 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3001 } else {
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
3002 if(local) {
526
e3c0440bd599 adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 525
diff changeset
3003 //printf("update: %s\n", local->path);
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
3004 }
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
3005 // ignore errors on remove
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
3006 xattr_remove(path, dir->tagconfig->xattr_name);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3007 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3008 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3009
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
3010 if(!ret) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
3011 local->tags_updated = 0;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
3012 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
3013
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3014 return ret;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3015 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3016
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3017 UcxBuffer* sync_get_file_tag_data(SyncDirectory *dir, LocalResource *res) {
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3018 if(!dir->tagconfig) {
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3019 return NULL;
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3020 }
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3021 if(res->cached_tags) {
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3022 return res->cached_tags;
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3023 }
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3024 UcxBuffer *buf = NULL;
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3025 if(dir->tagconfig->store == TAG_STORE_XATTR) {
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3026 ssize_t tag_length = 0;
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
3027 char *local_path = create_local_path(dir, res->path);
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3028 char* tag_data = xattr_get(
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3029 local_path,
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3030 dir->tagconfig->xattr_name,
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3031 &tag_length);
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3032 free(local_path);
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3033
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3034 if(tag_length > 0) {
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3035 buf = ucx_buffer_new(tag_data, (size_t)tag_length, UCX_BUFFER_AUTOFREE);
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3036 buf->size = (size_t)tag_length;
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3037 }
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3038 }
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3039 res->cached_tags = buf;
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3040 return buf;
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3041 }
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3042
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3043 UcxList* sync_get_file_tags(SyncDirectory *dir, LocalResource *res, DavBool *changed, char **newhash) {
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3044 if(changed) *changed = FALSE;
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3045
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3046 UcxList *tags = NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3047
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
3048 if(!res) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
3049 return NULL;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
3050 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
3051
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3052 if(!dir->tagconfig) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3053 return NULL;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3054 }
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
3055 if(changed && res->tags_updated) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
3056 *changed = TRUE;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
3057 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3058 if(dir->tagconfig->store == TAG_STORE_XATTR) {
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3059 UcxBuffer *tag_buf = res->cached_tags ?
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3060 res->cached_tags :
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3061 sync_get_file_tag_data(dir, res);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3062
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3063 if(tag_buf) {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3064 char *new_hash = dav_create_hash(tag_buf->space, tag_buf->size);
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3065 if(res->tags_hash) {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3066 if(changed && strcmp(res->tags_hash, new_hash)) {
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3067 *changed = TRUE;
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3068 }
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3069 free(res->tags_hash);
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3070 } else {
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3071 if(changed) *changed = TRUE;
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3072 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3073 if(!newhash) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3074 *newhash = new_hash;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3075 } else {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3076 free(newhash);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3077 }
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3078
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3079 switch(dir->tagconfig->local_format) {
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3080 default: break;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3081 case TAG_FORMAT_TEXT: {
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3082 tags = parse_text_taglist(tag_buf->space, tag_buf->size);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3083 break;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3084 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3085 case TAG_FORMAT_CSV: {
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3086 tags = parse_csv_taglist(tag_buf->space, tag_buf->size);
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3087 break;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3088 }
363
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
3089 case TAG_FORMAT_MACOS: {
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 366
diff changeset
3090 tags = parse_macos_taglist(tag_buf->space, tag_buf->size);
363
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
3091 break;
e9ed8e130ccf adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 361
diff changeset
3092 }
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3093 }
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3094 res->cached_tags = tag_buf;
368
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3095 } else if(res->tags_hash) {
11797f33bc24 adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
3096 if(changed) *changed = TRUE;
361
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3097 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3098 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3099
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3100 return tags;
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3101 }
b6f2462ee055 adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 347
diff changeset
3102
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3103 static int file_seek(FILE *f, curl_off_t offset, int origin) {
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3104 int ret = fseek(f, offset, origin);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3105 return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK;
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3106 }
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3107
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3108 size_t myread(void *ptr, size_t size, size_t nmemb, FILE *f) {
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3109 size_t ret = fread(ptr, size, nmemb, f);
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3110 return ret;
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3111 }
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3112
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3113 int gen_random_name(char *buf, size_t len) {
513
893a659768b3 fixes signedness issue in get_random_name()
Mike Becker <universe@uap-core.de>
parents: 510
diff changeset
3114 unsigned char name_prefix[8];
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3115 memset(name_prefix, 0, 8);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3116 dav_rand_bytes(name_prefix, 8);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3117 char *pre = util_hexstr(name_prefix, 8);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3118 int64_t ts = (int64_t)time(NULL);
516
39f5f17c3bc3 change format of version history resource names
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 514
diff changeset
3119 int w = snprintf(buf, len, "%"PRId64"-%s", ts, pre);
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3120 free(pre);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3121 return w >= len;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3122 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3123
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3124 #define VBEGIN_ERROR_MKCOL 1
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3125 #define VBEGIN_ERROR_MOVE 2
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3126 #define VBEGIN_ERROR_PROPPATCH 3
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3127 #define VBEGIN_ERROR_CHECKOUT 4
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3128 int versioning_begin(SyncDirectory *dir, DavResource *res) {
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3129 int ret = 0;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3130
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3131 if(dir->versioning->type == VERSIONING_SIMPLE && res->exists) {
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3132 DavResource *history_collection = dav_resource_new(
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3133 res->session,
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3134 dir->versioning->collection);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3135
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3136 // get the path to the version history collection for this resource
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3137 // if propfind fails we just assume that it doesn't exist
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3138 // better error handling is done later (sync_put_resource)
510
d6e801f97e7a more sstr to scstr conversion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 506
diff changeset
3139 // if there is no history collection for this resource, we create one
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3140
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3141 char *history_href = NULL;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3142 char *vcol_path = dav_get_string_property_ns(res, DAV_NS, VERSION_PATH_PROPERTY);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3143 if(!vcol_path) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3144 DavResource *history_res = NULL;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3145
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3146 // create a new collection for version history
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3147 // the name is a combination of a random prefix and a timestamp
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3148 while(!history_res) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3149 char history_res_name[128];
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3150 gen_random_name(history_res_name, 128);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3151
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3152 history_res = dav_resource_new_child(
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3153 res->session,
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3154 history_collection,
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3155 history_res_name);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3156 if(dav_exists(history_res)) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3157 dav_resource_free(history_res);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3158 history_res = NULL;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3159 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3160 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3161
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3162 history_res->iscollection = TRUE;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3163 if(dav_create(history_res)) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3164 dav_resource_free(history_res);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3165 dav_resource_free(history_collection);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3166 return VBEGIN_ERROR_MKCOL;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3167 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3168
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3169 history_href = strdup(history_res->href);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3170
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3171 dav_resource_free(history_res);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3172 } else {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3173 history_href = vcol_path;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3174 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3175
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3176 // find a free url and move 'res' to this location
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3177 DavResource *version_res = NULL;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3178 while(!version_res) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3179 char version_name[128];
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3180 gen_random_name(version_name, 128);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3181
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3182 char *href = util_concat_path(history_href, version_name);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3183 version_res = dav_resource_new_href(res->session, href);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3184 free(href);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3185
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3186 char *dest = util_get_url(res->session, version_res->href);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3187 int err = dav_moveto(res, dest, FALSE);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3188 free(dest);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3189
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3190 if(err) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3191 dav_resource_free(version_res);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3192 version_res = NULL;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3193 if(res->session->error != DAV_PRECONDITION_FAILED) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3194 ret = VBEGIN_ERROR_MOVE;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3195 break;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3196 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3197 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3198 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3199
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3200 if(!ret) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3201 dav_set_string_property_ns(version_res, DAV_NS, "origin", res->href);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3202 if(dav_store(version_res)) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3203 ret = VBEGIN_ERROR_PROPPATCH;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3204 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3205 dav_resource_free(version_res);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3206
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3207 // we can just set the property here and don't need dav_store
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3208 // because sync_put_resource will call dav_store(res) later
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3209 dav_set_string_property_ns(
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3210 res,
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3211 DAV_NS,
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3212 VERSION_PATH_PROPERTY,
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3213 history_href);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3214 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3215
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3216 if(vcol_path != history_href) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3217 free(history_href);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3218 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3219
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3220 dav_resource_free(history_collection);
522
46f96dcd6eab adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 521
diff changeset
3221 } else if(dir->versioning->type == VERSIONING_DELTAV){
492
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3222 // DeltaV is so much easier :)
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3223 if(dav_checkout(res)) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3224 ret = VBEGIN_ERROR_CHECKOUT;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3225 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3226 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3227
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3228 return ret;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3229 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3230
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3231 int versioning_end(SyncDirectory *dir, DavResource *res) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3232 if(dir->versioning->type == VERSIONING_DELTAV) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3233 return dav_checkin(res);
504
bf3695fee719 fix missiong return in versioning_end()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 503
diff changeset
3234 } else {
bf3695fee719 fix missiong return in versioning_end()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 503
diff changeset
3235 return 0;
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3236 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3237 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3238
492
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3239 int versioning_delete(SyncDirectory *dir, DavResource *res) {
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3240 if(dir->versioning->type == VERSIONING_SIMPLE) {
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3241 // TODO
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3242 }
522
46f96dcd6eab adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 521
diff changeset
3243 return 0;
492
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3244 }
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3245
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3246 static void update_metadata_hashes(LocalResource *local, MetadataHashes hashes) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3247 if(hashes.tags) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3248 if(local->tags_hash) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3249 free(local->tags_hash);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3250 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3251 local->tags_hash = hashes.tags;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3252 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3253 if(hashes.tags_remote) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3254 if(local->remote_tags_hash) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3255 free(local->remote_tags_hash);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3256 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3257 local->remote_tags_hash = hashes.tags_remote;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3258 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3259 if(hashes.xattr) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3260 if(local->xattr_hash) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3261 free(local->xattr_hash);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3262 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3263 local->xattr_hash = hashes.xattr;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3264 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3265 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3266
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3267 // this macro is only a workaround for a netbeans bug
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3268 #define LOG10 log10
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3269
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3270 static UcxList* upload_parts(
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3271 LocalResource *local,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3272 DavResource *res,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3273 FILE *in,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3274 uint64_t filesize,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3275 size_t blocksize,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3276 uint64_t *blockcount,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3277 int *err)
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3278 {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3279 // Make sure the resource is a collection. If it was a normal
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3280 // resource until now, delete it and recreate it as collection
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3281 if(res->exists) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3282 if(!res->iscollection) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3283 if(dav_delete(res)) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3284 print_resource_error(res->session, res->path);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3285 *err = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3286 return NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3287 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3288 res->exists = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3289 return upload_parts(local, res, in, filesize, blocksize, blockcount, err);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3290 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3291 } else {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3292 res->iscollection = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3293 if(dav_create(res)) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3294 print_resource_error(res->session, res->path);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3295 *err = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3296 return NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3297 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3298 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3299 res->exists = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3300
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3301 if(!res->href) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3302 // this should never happen, but just make sure it doesn't crash
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3303 fprintf(stderr, "href is NULL\n");
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3304 *err = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3305 return NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3306 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3307
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3308 char *buffer = malloc(blocksize);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3309 if(!buffer) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3310 fprintf(stderr, "Out of memory\n");
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3311 *err = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3312 return NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3313 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3314
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3315 // calculate the maximal length of resource names
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3316 // names should have all the same length and contain the block number
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3317 int nblocks = filesize / blocksize;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3318 int digits = LOG10((double)nblocks) + 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3319 if(digits > 127) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3320 fprintf(stderr, "Too many parts\n");
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3321 *err = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3322 return NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3323 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3324
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3325 UcxMap *updated_parts_map = ucx_map_new((nblocks/2)+64);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3326
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3327 int blockindex = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3328 int uploaded_parts = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3329 size_t r;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3330
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3331 // temporarly disable name encryption, because we don't need it for
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3332 // part names
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3333 uint32_t session_flags = res->session->flags;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3334 res->session->flags ^= DAV_SESSION_ENCRYPT_NAME;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3335
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3336 DAV_SHA_CTX *sha = dav_hash_init();
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3337
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3338 while((r = fread(buffer, 1, blocksize, in)) > 0) {
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3339 dav_hash_update(sha, buffer, r);
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3340
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3341 int upload_block = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3342 char *block_hash = dav_create_hash(buffer, r);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3343 if(blockindex >= local->numparts) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3344 // we don't have a hash for this block, therefore it must be new
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3345 upload_block = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3346 } else {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3347 FilePart part = local->parts[blockindex];
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3348 if(!strcmp(part.hash, block_hash)) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3349 // no change
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3350 free(block_hash);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3351 block_hash = NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3352 } else {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3353 // block has changed
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3354 upload_block = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3355 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3356 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3357
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3358 if(upload_block) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3359 char name[128];
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3360 snprintf(name, 128, "%0*d", digits, blockindex);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3361
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3362 char *part_href = util_concat_path(res->href, name);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3363 DavResource *part = dav_resource_new_href(res->session, part_href);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3364 free(part_href);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3365
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3366 // upload part
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3367 dav_set_content_data(part, buffer, r);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3368 if(dav_store(part)) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3369 *err = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3370 print_resource_error(res->session, part->path);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3371 } else {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3372 // successfully uploaded part
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3373
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3374 // store the FilePart in a map
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3375 // later we do a propfind and add the etag
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3376 FilePart *f = calloc(1, sizeof(FilePart));
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3377 f->block = blockindex;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3378 f->hash = block_hash;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3379 ucx_map_cstr_put(updated_parts_map, name, f);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3380 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3381 dav_resource_free(part);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3382 uploaded_parts++;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3383 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3384 if(*err) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3385 break;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3386 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3387 blockindex++;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3388 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3389 *blockcount = blockindex;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3390
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3391 // restore flags
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3392 res->session->flags = session_flags;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3393
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3394 free(buffer);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3395 if(*err) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3396 ucx_map_free_content(updated_parts_map, (ucx_destructor)filepart_free);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3397 ucx_map_free(updated_parts_map);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3398 return NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3399 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3400
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3401 // set content-hash
558
1a9e6a5c1e79 fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents: 557
diff changeset
3402 unsigned char content_hash[DAV_SHA256_DIGEST_LENGTH];
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3403 dav_hash_final(sha, content_hash);
542
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
3404 sync_set_content_hash(res, content_hash);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
3405 local->hash = util_hexstr(content_hash, DAV_SHA256_DIGEST_LENGTH);
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3406
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3407 // get etags from uploaded resources
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3408 // also delete everything, that is not part of the file
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3409 UcxList *updated_parts = NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3410 DavResource *parts = dav_query(res->session, "select D:getetag from %s order by name", res->path);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3411 if(!parts) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3412 print_resource_error(res->session, parts->path);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3413 *err = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3414 ucx_map_free_content(updated_parts_map, (ucx_destructor)filepart_free);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3415 ucx_map_free(updated_parts_map);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3416 return NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3417 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3418 DavResource *part = parts->children;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3419 while(part) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3420 FilePart *fp = ucx_map_cstr_remove(updated_parts_map, part->name);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3421 // every part we uploaded is in the map
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3422 // if we get parts that are not in the map, someone else uploaded it
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3423 if(fp) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3424 char *etag = dav_get_string_property(part, "D:getetag");
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3425 if(etag) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3426 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3427 etag = etag + 2;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3428 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3429
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3430 fp->etag = strdup(etag);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3431 updated_parts = ucx_list_append(updated_parts, fp);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3432 } // else { wtf is wrong with this resource }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3433 } else {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3434 uint64_t name_partnum = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3435 char *res_name = part->name;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3436 while(res_name[0] == '0' && res_name[1] != '\0') {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3437 res_name++;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3438 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3439 DavBool delete_part = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3440 if(strlen(part->name) != digits) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3441 delete_part = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3442 } else if(util_strtouint(res_name, &name_partnum)) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3443 if(name_partnum >= blockindex) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3444 delete_part = 1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3445 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3446 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3447
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3448 if(delete_part) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3449 if(dav_delete(part)) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3450 print_resource_error(part->session, part->path);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3451 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3452 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3453 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3454 part = part->next;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3455 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3456 dav_resource_free_all(parts);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3457
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3458 ucx_map_free_content(updated_parts_map, (ucx_destructor)filepart_free);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3459 ucx_map_free(updated_parts_map);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3460
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3461 *err = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3462 return updated_parts;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3463 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3464
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
3465 void update_parts(LocalResource *local, UcxList *updates, uint64_t numparts) {
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3466 size_t old_num = local->numparts;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3467 if(old_num > numparts) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3468 // free old parts
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3469 for(size_t i=numparts;i<old_num;i++) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3470 FilePart p = local->parts[i];
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3471 if(p.etag) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3472 free(p.etag);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3473 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3474 if(p.hash) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3475 free(p.hash);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3476 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3477 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3478 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3479 if(numparts != local->numparts) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3480 local->parts = realloc(local->parts, numparts * sizeof(FilePart));
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3481 local->numparts = numparts;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3482 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3483
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3484 UCX_FOREACH(elm, updates) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3485 FilePart *p = elm->data;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3486 if(p->block > numparts) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3487 // just make sure things don't explode in case some weird stuff
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3488 // is going on
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3489 continue;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3490 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3491
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3492 FilePart *old = &local->parts[p->block];
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3493 if(p->block < old_num) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3494 // cleanup existing part
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3495 if(old->hash) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3496 free(old->hash);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3497 old->hash = NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3498 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3499 if(old->etag) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3500 free(old->etag);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3501 old->etag = NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3502 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3503 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3504 old->block = p->block;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3505 old->hash = p->hash;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3506 old->etag = p->etag;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3507 free(p);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3508 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3509 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3510
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3511 int sync_put_resource(
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3512 SyncDirectory *dir,
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3513 DavResource *res,
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3514 LocalResource *local,
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3515 int *counter)
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3516 {
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
3517 char *local_path = create_local_path(dir, res->path);
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3518
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
3519 SYS_STAT s;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
3520 if(sys_stat(local_path, &s)) {
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3521 fprintf(stderr, "Cannot stat file: %s\n", local_path);
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3522 perror("");
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3523 free(local_path);
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3524 return -1;
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3525 }
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3526
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3527 DavBool islink = local->link_target ? 1 : 0;
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3528 if(!local->link_target && local->link_updated) {
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3529 dav_remove_property_ns(res, DAV_NS, "link");
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3530 }
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3531
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3532 size_t split_blocksize = resource_get_blocksize(dir, local, res, s.st_size);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3533
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
3534 FILE *in = sys_fopen(local_path, "rb");
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3535 if(!in) {
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3536 fprintf(stderr, "Cannot open file %s\n", local_path);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3537 free(local_path);
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3538 return -1;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3539 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3540
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3541 DavBool issplit = split_blocksize == 0 ? FALSE : TRUE;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3542 int split_err = 0;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3543 UcxList *parts = NULL;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3544 uint64_t blockcount = 0;
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3545
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3546 if(islink) {
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3547 dav_set_string_property_ns(res, DAV_NS, "link", local->link_target);
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3548 } else if(issplit) {
541
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3549 // set split property
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3550 char blocksize_str[32];
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3551 snprintf(blocksize_str, 32, "%zu", split_blocksize);
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3552 dav_set_string_property_ns(res, DAV_NS, "split", blocksize_str);
e59a989d890d adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 539
diff changeset
3553
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3554 // splitted/partial upload
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3555 parts = upload_parts(
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3556 local,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3557 res,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3558 in,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3559 s.st_size,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3560 split_blocksize,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3561 &blockcount,
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3562 &split_err);
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3563 } else {
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3564 // regular file upload
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3565 dav_set_content(res, in, (dav_read_func)myread, (dav_seek_func)file_seek);
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3566 dav_set_content_length(res, s.st_size);
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3567 }
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3568 if(split_err) {
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3569 free(local_path);
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3570 return -1;
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3571 }
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3572
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3573 MetadataHashes hashes;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3574 hashes = sync_set_metadata_properties(dir, res->session, res, local);
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3575
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3576 // before sync_put_resource, remote_resource_is_changed does a propfind
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3577 // and sets res->exists
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3578 int exists = res->exists;
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3579 if(dir->versioning && dir->versioning->always && !issplit) {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3580 int err = versioning_begin(dir, res);
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3581 if(err) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3582 fprintf(stderr, "Cannot store version for resource: %s\n", res->href);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3583 free(local_path);
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3584 return -1;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3585 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3586 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3587
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3588 int ret = -1;
244
47791bdf1725 changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
3589 for(int i=0;i<=dir->max_retry;i++) {
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3590 if(!exists && dav_create(res)) {
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3591 continue;
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3592 }
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3593 exists = 1;
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3594 if(dav_store(res)) {
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3595 continue;
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3596 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3597 ret = 0;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3598 break;
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3599 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3600
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3601 if(dir->versioning && dir->versioning->always && !issplit) {
491
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3602 if(versioning_end(dir, res)) {
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3603 fprintf(stderr, "Cannot checkin resource\n");
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3604 ret = 1;
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3605 }
fdc2fb090cc7 adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 490
diff changeset
3606 }
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3607
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3608 if(ret == 0) {
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3609 (*counter)++;
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3610
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3611 update_metadata_hashes(local, hashes);
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3612 update_parts(local, parts, blockcount);
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3613
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3614 // check contentlength and get new etag
536
877f7c4a203b adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 533
diff changeset
3615 DavResource *up_res = dav_get(res->session, res->path, "D:getetag,idav:status");
48
08d5544c92fb fixed etag handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
3616
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3617 if(up_res) {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3618 // the new content length must be equal or greater than the file size
577
f49964cf7228 store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 576
diff changeset
3619 if(up_res->contentlength < s.st_size && !issplit && !islink) {
478
baa63fef5c5c fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 460
diff changeset
3620 fprintf(stderr, "Incomplete Upload: %s\n", local_path);
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3621 ret = -1;
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3622 // try to set the resource status to 'broken'
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3623 sync_set_status(res, "broken");
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3624 } else {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3625 // everything seems fine, we can update the local resource
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
3626 char *etag = dav_get_string_property(up_res, "D:getetag");
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3627 if(etag) {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3628 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3629 etag = etag + 2;
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3630 }
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3631 }
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3632
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3633 if(local->etag) {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3634 free(local->etag);
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3635 }
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3636
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3637 if(etag) {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3638 local->etag = strdup(etag);
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3639 } else {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3640 local->etag = NULL;
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3641 }
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3642
550
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
3643 if(!issplit && dir->hashing) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
3644 if(local->hash) {
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
3645 free(local->hash);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
3646 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
3647 // TODO: calculate hash on upload
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
3648 local->hash = util_file_hash(local_path);
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
3649 }
8c700eae3eb8 add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 548
diff changeset
3650
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
3651 if(dav_get_string_property(up_res, "idav:status")) {
227
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
3652 sync_remove_status(up_res);
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
3653 }
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
3654
bf485439222a fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 225
diff changeset
3655 dav_resource_free(up_res);
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3656 }
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
3657 }
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3658 } else {
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3659 ret = -1;
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3660 sync_set_status(res, "broken");
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3661 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3662
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3663 fclose(in);
144
c2c02c9b3be4 dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 135
diff changeset
3664 free(local_path);
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3665
64
112dbf7ba8b0 changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 61
diff changeset
3666 return ret;
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3667 }
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3668
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3669 int sync_mkdir(SyncDirectory *dir, DavResource *res, LocalResource *local) {
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3670 res->iscollection = 1;
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3671 int ret = -1;
244
47791bdf1725 changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 243
diff changeset
3672 for(int i=0;i<=dir->max_retry;i++) {
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3673 if(dav_create(res)) {
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3674 continue;
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3675 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3676 ret = 0;
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3677 break;
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3678 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3679 return ret;
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3680 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3681
552
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3682 int sync_move_remote_resource(
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3683 SyncDirectory *dir,
569
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
3684 SyncDatabase *db,
552
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3685 DavResource *origin,
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3686 LocalResource *local,
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3687 DavBool copy,
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3688 int *counter)
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3689 {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3690 char *local_path = create_local_path(dir, local->path);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3691
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3692 SYS_STAT s;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3693 if(sys_stat(local_path, &s)) {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3694 fprintf(stderr, "Cannot stat file: %s\n", local_path);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3695 perror("");
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3696 free(local_path);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3697 return -1;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3698 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3699 free(local_path);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3700
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3701 int result = 0;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3702 if(copy) {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3703 result = dav_copy_o(origin, local->path, FALSE);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3704 } else {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3705 result = dav_move_o(origin, local->path, FALSE);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3706 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3707
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3708 if(result != 0) {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3709 return result;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3710 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3711
569
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
3712 LocalResource *local_origin = local->origin;
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
3713 if(!copy) {
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
3714 ucx_map_cstr_remove(db->resources, local_origin->path);
cafdc13b6820 remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 568
diff changeset
3715 }
552
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3716 // replace LocalResource with origin content
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3717 local->origin = NULL;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3718 char *path = strdup(local->path);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3719 // TODO: free stuff before replacing it
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3720 memcpy(local, local_origin, sizeof(LocalResource));
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3721 local->path = path;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3722
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3723 free(local_origin); // only free origin pointer
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3724
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3725 // get new etag
553
891823d8dd7b fix move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 552
diff changeset
3726 DavResource *up_res = dav_get(origin->session, local->path, "D:getetag");
552
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3727 if(up_res) {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3728 (*counter)++;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3729
554
ebac6e1ac190 update metadata on copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 553
diff changeset
3730 // set metadata
ebac6e1ac190 update metadata on copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 553
diff changeset
3731 MetadataHashes hashes;
ebac6e1ac190 update metadata on copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 553
diff changeset
3732 hashes = sync_set_metadata_properties(dir, up_res->session, up_res, local);
ebac6e1ac190 update metadata on copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 553
diff changeset
3733 if(dav_store(up_res)) {
ebac6e1ac190 update metadata on copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 553
diff changeset
3734 fprintf(stderr, "Error: cannot store resource metadata\n");
ebac6e1ac190 update metadata on copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 553
diff changeset
3735 }
ebac6e1ac190 update metadata on copy/move
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 553
diff changeset
3736
552
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3737 // everything seems fine, we can update the local resource
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3738 char *etag = dav_get_string_property(up_res, "D:getetag");
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3739 if(etag) {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3740 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3741 etag = etag + 2;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3742 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3743 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3744
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3745 if(local->etag) {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3746 free(local->etag);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3747 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3748
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3749 if(etag) {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3750 local->etag = strdup(etag);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3751 } else {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3752 local->etag = NULL;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3753 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3754
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3755 local->last_modified = s.st_mtime;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3756
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3757 dav_resource_free(up_res);
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3758 } else {
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3759 result = 1;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3760 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3761
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3762 return result;
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3763 }
e1a12762bf0a improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 551
diff changeset
3764
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3765 int sync_delete_remote_resource(
492
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3766 SyncDirectory *dir,
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3767 DavSession *sn,
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3768 LocalResource *local_res,
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3769 int *counter,
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3770 UcxList **cols)
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3771 {
570
00b7b8e86c48 fix deletion of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 569
diff changeset
3772 DavResource *res = dav_get(sn, local_res->path, "D:getetag,idav:split");
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3773 if(!res) {
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3774 return sn->error == DAV_NOT_FOUND ? 0 : 1;
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3775 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3776
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3777 int ret = 0;
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3778 sn->error = DAV_OK;
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3779 if(res->iscollection) {
570
00b7b8e86c48 fix deletion of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 569
diff changeset
3780 DavXmlNode *split = dav_get_property_ns(res, DAV_NS, "split");
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3781 if(cols) {
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3782 *cols = ucx_list_append(*cols, local_res);
570
00b7b8e86c48 fix deletion of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 569
diff changeset
3783 } else if(split || !res->children) {
460
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3784 printf("delete: %s\n", res->path);
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3785 if(dav_delete(res)) {
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3786 ret = 1;
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3787 fprintf(stderr, "Cannot delete collection %s\n", res->path);
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3788 } else {
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3789 (*counter)++;
22522ff52a62 adds check to make sure dav-sync doesn't delete collections when children are modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
3790 }
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3791 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3792 } else {
331
9ca1e4706acc adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 318
diff changeset
3793 char *etag = dav_get_string_property(res, "D:getetag");
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3794 if(etag) {
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3795 if(strlen(etag) > 2 && etag[0] == 'W' && etag[1] == '/') {
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3796 etag = etag + 2;
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3797 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3798 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3799
565
26898e00ddff fix dav-sync push not deleting files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 564
diff changeset
3800 if(!nullstrcmp(etag, local_res->etag)) {
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3801 // local resource metadata == remote resource metadata
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3802 // resource can be deleted
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3803 printf("delete: %s\n", res->path);
492
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3804
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3805 if(dir->versioning && dir->versioning->always) {
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3806 if(versioning_delete(dir, res)) {
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3807 fprintf(
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3808 stderr,
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3809 "Cannot save resource version before deletion\n");
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3810 ret = 1;
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3811 }
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3812 }
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3813
7bde663719dc Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 491
diff changeset
3814 if(!ret && dav_delete(res)) {
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3815 if(sn->error != DAV_NOT_FOUND) {
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3816 fprintf(stderr, "Cannot delete resource %s\n", res->path);
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3817 ret = 1;
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3818 }
192
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3819 } else {
d10194a51304 dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 191
diff changeset
3820 (*counter)++;
190
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3821 }
a76e43d89f55 dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
3822 }
565
26898e00ddff fix dav-sync push not deleting files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 564
diff changeset
3823 // else TODO: should we inform the user that the file was modified on
26898e00ddff fix dav-sync push not deleting files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 564
diff changeset
3824 // the server and delete was skipped?
65
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3825 }
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3826
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3827 // cleanup
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3828 dav_resource_free(res);
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3829
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3830 return ret;
d4077e8175f3 added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 64
diff changeset
3831 }
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
3832
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3833 MetadataHashes sync_set_metadata_properties(
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3834 SyncDirectory *dir,
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3835 DavSession *sn,
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3836 DavResource *res,
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3837 LocalResource *local)
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3838 {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3839 MetadataHashes hashes = {NULL, NULL, NULL};
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3840 if(dir->tagconfig) {
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3841 // get local tags
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3842 DavBool changed = 0;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3843 char *tags_hash = NULL;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3844 UcxList *tags = sync_get_file_tags(dir, local, &changed, &tags_hash);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3845 if(changed || local->tags_updated) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3846 hashes.tags = tags_hash;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3847
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3848 DavBool store_tags = TRUE;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3849 // get remote tags
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3850 UcxList *remote_tags = NULL;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3851 DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags");
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3852 if(tagsprop) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3853 remote_tags = parse_dav_xml_taglist(tagsprop);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3854 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3855 char *remote_hash = create_tags_hash(remote_tags);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3856 if(nullstrcmp(remote_hash, local->remote_tags_hash)) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3857 // the tags have changed on the server
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3858 switch(dir->tagconfig->conflict) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3859 case TAG_NO_CONFLICT: break;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3860 case TAG_KEEP_LOCAL: break;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3861 case TAG_KEEP_REMOTE: {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3862 store_tags = FALSE;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3863 local->tags_updated = FALSE;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3864 break;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3865 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3866 case TAG_MERGE: {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3867 UcxList *new_tags = merge_tags(tags, remote_tags);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3868 free_taglist(tags);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3869 tags = new_tags;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3870 break;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3871 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3872 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3873 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3874
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3875 if(dir->tagconfig->local_format == TAG_FORMAT_CSV) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3876 // csv tag lists don't have colors, so we have to add
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3877 // the colors from the remote tag list
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3878 add_tag_colors(tags, remote_tags);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3879 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3880
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3881 if(store_tags) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3882 if(tags) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3883 DavXmlNode *tagprop = create_xml_taglist(tags);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3884 dav_set_property_ns(res, DAV_NS, "tags", tagprop);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3885 } else {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3886 dav_remove_property_ns(res, DAV_NS, "tags");
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3887 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3888 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3889
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3890 free_taglist(remote_tags);
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3891 } else {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3892 if(tags_hash) {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3893 free(tags_hash);
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3894 }
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3895 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3896 free_taglist(tags);
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3897 }
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3898
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3899 if(local->finfo_updated) {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3900 struct stat s;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3901 s.st_mode = local->mode;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3902 s.st_mtime = local->last_modified;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3903 s.st_uid = local->uid;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3904 s.st_gid = local->gid;
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3905 resource_set_finfo_s(&s, res, dir->metadata);
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3906 }
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3907
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3908 if(local->xattr_updated) {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3909 if(local->xattr) {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3910 resource_set_xattr(res, local->xattr);
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3911 hashes.xattr = strdup(local->xattr->hash);
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3912 } else {
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3913 dav_remove_property(res, "idav:xattributes");
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3914 }
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3915 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3916 return hashes;
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3917 }
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3918
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3919 int sync_update_metadata(
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3920 SyncDirectory *dir,
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3921 DavSession *sn,
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3922 DavResource *res,
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3923 LocalResource *local)
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3924 {
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3925 MetadataHashes hashes = sync_set_metadata_properties(dir, sn, res, local);
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3926
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3927 int err = 0;
370
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
3928 printf("update: %s\n", local->path);
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
3929 if(dav_store(res)) {
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
3930 print_resource_error(sn, local->path);
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3931 err = 1;
370
ab9c5afdc243 pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 369
diff changeset
3932 } else {
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3933 update_metadata_hashes(local, hashes);
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3934 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
3935
523
923a4528a2ae adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 522
diff changeset
3936 return err;
369
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3937 }
4322b8953bd5 adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 368
diff changeset
3938
218
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3939 void remove_deleted_conflicts(SyncDirectory *dir, SyncDatabase *db) {
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3940 char **dc = calloc(sizeof(void*), db->conflict->count);
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3941 int numdc = 0;
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3942
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3943 UcxMapIterator i = ucx_map_iterator(db->conflict);
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3944 LocalResource *res;
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3945 UCX_MAP_FOREACH(key, res, i) {
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
3946 char *path = create_local_path(dir, res->path);
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
3947 SYS_STAT s;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
3948 if(sys_stat(path, &s)) {
218
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3949 if(errno == ENOENT) {
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3950 dc[numdc] = res->path;
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3951 numdc++;
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3952 } else {
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3953 fprintf(stderr, "Cannot stat file: %s\n", path);
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3954 perror("");
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3955 }
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3956 }
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3957 free(path);
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3958 }
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3959
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3960 for(int i=0;i<numdc;i++) {
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3961 ucx_map_cstr_remove(db->conflict, dc[i]);
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3962 }
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
3963
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
3964 free(dc);
218
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3965 }
5f1f7602cf77 automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 217
diff changeset
3966
257
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3967 static void resolve_skipped(SyncDatabase *db) {
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3968 UcxKey k;
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3969 LocalResource *res;
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3970 UcxMapIterator i = ucx_map_iterator(db->resources);
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3971 int skipped = 0;
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3972 UCX_MAP_FOREACH(k, res, i) {
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3973 if(res->skipped) {
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3974 skipped++;
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3975 fprintf(stderr, "skipped from push: %s\n", res->path);
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3976 }
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3977 }
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3978 if(skipped > 0) {
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3979 fprintf(stderr,
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3980 " To resolve conflict resources skipped by push run dav-sync pull first\n"
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3981 " before resolve-conflicts or delete-conflicts.\n\n");
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3982 }
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3983 }
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
3984
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3985 int cmd_resolve_conflicts(CmdArgs *a) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3986 if(a->argc != 1) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3987 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3988 return -1;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3989 }
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3990
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3991 SyncDirectory *dir = scfg_get_dir(a->argv[0]);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3992 if(!dir) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3993 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3994 return -1;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3995 }
233
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
3996 if(scfg_check_dir(dir)) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
3997 return -1;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
3998 }
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
3999
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4000 SyncDatabase *db = load_db(dir->database);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4001 if(!db) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4002 fprintf(stderr, "Cannot load database file: %s\n", dir->database);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4003 return -1;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4004 }
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4005
257
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
4006 resolve_skipped(db);
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
4007
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4008 int ret = 0;
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4009
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4010 // remove conflicts
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4011 int num_conflict = db->conflict->count;
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
4012 ucx_map_free_content(db->conflict, (ucx_destructor)local_resource_free);
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4013 ucx_map_clear(db->conflict);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4014
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4015 // store db
521
c5bbae4b3cca extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 516
diff changeset
4016 if(store_db(db, dir->database, dir->db_settings)) {
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4017 fprintf(stderr, "Cannot store sync db\n");
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4018 fprintf(stderr, "Abort\n");
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
4019 ret = -2;
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4020 }
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
4021
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
4022 // cleanup
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4023 destroy_db(db);
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4024
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4025 // Report
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
4026 if(ret != -2) {
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4027 char *str_conflict = num_conflict == 1 ? "conflict" : "conflicts";
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4028 printf("Result: %d %s resolved\n", num_conflict, str_conflict);
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4029 }
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4030
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4031 return ret;
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4032 }
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4033
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4034 int cmd_delete_conflicts(CmdArgs *a) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4035 if(a->argc != 1) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4036 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4037 return -1;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4038 }
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4039
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4040 SyncDirectory *dir = scfg_get_dir(a->argv[0]);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4041 if(!dir) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4042 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4043 return -1;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4044 }
233
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
4045 if(scfg_check_dir(dir)) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
4046 return -1;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
4047 }
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4048
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4049 SyncDatabase *db = load_db(dir->database);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4050 if(!db) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4051 fprintf(stderr, "Cannot load database file: %s\n", dir->database);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4052 return -1;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4053 }
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4054
257
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
4055 resolve_skipped(db);
49f3c58cc06c fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
4056
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4057 int num_del = 0;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4058 int num_err = 0;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4059
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4060 int ret = 0;
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4061
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4062 // delete all conflict files
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4063 UcxMapIterator i = ucx_map_iterator(db->conflict);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4064 LocalResource *res;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4065 UCX_MAP_FOREACH(key, res, i) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4066 printf("delete: %s\n", res->path);
544
9e85e1ec1155 adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 543
diff changeset
4067 char *path = create_local_path(dir, res->path);
412
dc74f736aea1 adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
4068 if(sys_unlink(path)) {
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4069 if(errno != ENOENT) {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4070 perror("unlink");
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4071 num_err++;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4072 }
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4073 } else {
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4074 num_del++;
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4075 }
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4076 free(path);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4077 }
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
4078 ucx_map_free_content(db->conflict, (ucx_destructor)local_resource_free);
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4079 ucx_map_clear(db->conflict);
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4080
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4081 // store db
521
c5bbae4b3cca extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 516
diff changeset
4082 if(store_db(db, dir->database, dir->db_settings)) {
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4083 fprintf(stderr, "Cannot store sync db\n");
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4084 fprintf(stderr, "Abort\n");
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4085 ret = -1;
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4086 }
224
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
4087
4b55f05f4e00 added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 223
diff changeset
4088 // cleanup
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4089 destroy_db(db);
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4090
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4091 // Report
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4092 if(ret == 0) {
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4093 char *str_delete = num_del == 1 ? "file" : "files";
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4094 char *str_error = num_err == 1 ? "error" : "errors";
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4095 printf("Result: %d conflict %s deleted, %d %s\n",
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4096 num_del, str_delete,
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4097 num_err, str_error);
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4098 }
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4099
222
7b73058d782e fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
4100 return ret;
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4101 }
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4102
563
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4103 int cmd_list_conflicts(CmdArgs *a) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4104 if(a->argc != 1) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4105 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4106 return -1;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4107 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4108
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4109 SyncDirectory *dir = scfg_get_dir(a->argv[0]);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4110 if(!dir) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4111 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4112 return -1;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4113 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4114 if(scfg_check_dir(dir)) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4115 return -1;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4116 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4117
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4118 SyncDatabase *db = load_db(dir->database);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4119 if(!db) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4120 fprintf(stderr, "Cannot load database file: %s\n", dir->database);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4121 return -1;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4122 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4123
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4124 remove_deleted_conflicts(dir, db);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4125
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4126 // get all conflict sources
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4127 UcxMapIterator i = ucx_map_iterator(db->conflict);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4128 LocalResource *res;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4129 UcxList* conflict_sources = NULL;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4130 UCX_MAP_FOREACH(key, res, i) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4131 conflict_sources = ucx_list_append(conflict_sources, res->conflict_source);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4132 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4133
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4134 // print unique conflict sources
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4135 conflict_sources = ucx_list_sort(conflict_sources, ucx_cmp_str, NULL);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4136 UCX_FOREACH(elem, conflict_sources) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4137 char* path = elem->data;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4138 if(cmd_getoption(a, "verbose")) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4139 int confl_count = 1;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4140 while(elem->next && !strcmp(elem->next->data, path)) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4141 elem = elem->next;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4142 ++confl_count;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4143 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4144 printf("%s (%d)\n", path, confl_count);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4145 } else {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4146 printf("%s\n", path);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4147 while(elem->next && !strcmp(elem->next->data, path)) {
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4148 elem = elem->next;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4149 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4150 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4151 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4152
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4153 // cleanup
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4154 destroy_db(db);
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4155
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4156 return 0;
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4157 }
3dffe58a573f adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents: 561
diff changeset
4158
217
12bad63cf5a8 added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 216
diff changeset
4159
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4160 // TODO: remove code dup (main.c ls_size_str)
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4161 static char* size_str(uint64_t size) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4162 char *str = malloc(16);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4163
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4164 if(size < 0x400) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4165 snprintf(str, 16, "%" PRIu64 " bytes", size);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4166 } else if(size < 0x100000) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4167 float s = (float)size/0x400;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4168 int diff = (s*100 - (int)s*100);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4169 if(diff > 90) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4170 diff = 0;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4171 s += 0.10f;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4172 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4173 if(size < 0x2800 && diff != 0) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4174 // size < 10 KiB
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4175 snprintf(str, 16, "%.1f KiB", s);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4176 } else {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4177 snprintf(str, 16, "%.0f KiB", s);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4178 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4179 } else if(size < 0x40000000) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4180 float s = (float)size/0x100000;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4181 int diff = (s*100 - (int)s*100);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4182 if(diff > 90) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4183 diff = 0;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4184 s += 0.10f;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4185 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4186 if(size < 0xa00000 && diff != 0) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4187 // size < 10 MiB
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4188 snprintf(str, 16, "%.1f MiB", s);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4189 } else {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4190 size /= 0x100000;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4191 snprintf(str, 16, "%.0f MiB", s);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4192 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4193 } else if(size < 0x1000000000ULL) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4194 float s = (float)size/0x40000000;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4195 int diff = (s*100 - (int)s*100);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4196 if(diff > 90) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4197 diff = 0;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4198 s += 0.10f;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4199 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4200 if(size < 0x280000000 && diff != 0) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4201 // size < 10 GiB
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4202 snprintf(str, 16, "%.1f GiB", s);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4203 } else {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4204 size /= 0x40000000;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4205 snprintf(str, 16, "%.0f GiB", s);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4206 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4207 } else {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4208 size /= 1024;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4209 float s = (float)size/0x40000000;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4210 int diff = (s*100 - (int)s*100);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4211 if(diff > 90) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4212 diff = 0;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4213 s += 0.10f;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4214 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4215 if(size < 0x280000000 && diff != 0) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4216 // size < 10 TiB
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4217 snprintf(str, 16, "%.1f TiB", s);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4218 } else {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4219 size /= 0x40000000;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4220 snprintf(str, 16, "%.0f TiB", s);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4221 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4222 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4223 return str;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4224 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4225
531
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4226 void print_resource_version(DavResource *res, char *name) {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4227 time_t now = res->lastmodified;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4228 struct tm *date = gmtime(&now);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4229 char str[32];
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4230 putenv("LC_TIME=C");
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4231 size_t len = strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT", date);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4232
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4233 printf("name: %s\n", name);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4234 printf("lastmodified: %s\n", str);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4235 char *server = util_url_base(res->session->base_url);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4236 char *url = util_concat_path(server, res->href);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4237 printf("url: %s\n", url);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4238 free(server);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4239 free(url);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4240 }
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4241
529
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4242 int cmd_list_versions(CmdArgs *a) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4243 if(a->argc != 1) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4244 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4245 return -1;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4246 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4247
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4248 SyncFile file;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4249 int ret = 0;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4250 char *path = a->argv[0];
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4251
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4252 int err = sync_get_file(a, path, &file, TRUE);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4253 if(err) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4254 sync_print_get_file_err(path, err);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4255 return 1;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4256 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4257 SyncDirectory *dir = file.dir;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4258
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4259 if(!dir->versioning) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4260 fprintf(stderr, "No versioning configured for syncdir %s\n", dir->name);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4261 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4262
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4263 Repository *repo = get_repository(sstr(dir->repository));
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4264 if(!repo) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4265 fprintf(stderr, "Unknown repository %s\n", dir->repository);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4266 return -1;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4267 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4268
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4269 SyncDatabase *db = load_db(dir->database);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4270 if(!db) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4271 fprintf(stderr, "Cannot load database file: %s\n", dir->database);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4272 return -1;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4273 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4274 remove_deleted_conflicts(dir, db);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4275
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4276 DavSession *sn = create_session(ctx, repo, dir->collection);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4277 ucx_mempool_reg_destr(sn->mp, db, (ucx_destructor)destroy_db);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4278 if (cmd_getoption(a, "verbose")) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4279 curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4280 curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4281 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4282
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4283 DavResource *res = dav_resource_new(sn, file.path);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4284 if(dir->versioning->type == VERSIONING_SIMPLE) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4285 do {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4286 DavPropName p;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4287 p.ns = DAV_NS;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4288 p.name = VERSION_PATH_PROPERTY;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4289 if(dav_load_prop(res, &p, 1)) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4290 print_resource_error(sn, file.path);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4291 ret = 1;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4292 break;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4293 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4294 char *vcol_href = dav_get_string_property_ns(res, DAV_NS, VERSION_PATH_PROPERTY);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4295 if(!vcol_href) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4296 ret = 1;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4297 break;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4298 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4299
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4300 DavResource *vcol = dav_resource_new_href(sn, vcol_href);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4301 if(!vcol) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4302 ret = 1;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4303 break;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4304 }
530
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4305
529
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4306 if(dav_load_prop(vcol, NULL, 0)) {
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4307 print_resource_error(sn, vcol->path);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4308 ret = 1;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4309 break;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4310 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4311
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4312 DavResource *child = vcol->children;
530
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4313 UcxList *children = NULL;
529
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4314 while(child) {
530
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4315 children = ucx_list_append(children, child);
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4316 child = child->next;
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4317 }
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4318 children = ucx_list_sort(children, ucx_cmp_str, NULL);
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4319
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4320 DavBool first = 1;
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4321 UCX_FOREACH(elm, children) {
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4322 DavResource *c = elm->data;
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4323 if(!first) {
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4324 putchar('\n');
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4325 }
531
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4326 print_resource_version(c, c->name);
530
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4327 first = 0;
529
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4328 }
530
29e660161b73 changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
4329 ucx_list_free(children);
529
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4330 } while(0);
531
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4331 } else if(dir->versioning->type == VERSIONING_DELTAV) {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4332 DavResource *versions = dav_versiontree(res, NULL);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4333 DavResource *v = versions;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4334 DavBool first = 1;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4335 while(v) {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4336 if(!first) {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4337 putchar('\n');
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4338 }
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4339 char *vname = dav_get_string_property(v, "D:version-name");
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4340 print_resource_version(v, vname);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4341 first = 0;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4342 v = v->next;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4343 }
529
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4344 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4345
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4346 free(file.path);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4347 dav_session_destroy(sn);
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4348
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4349 return ret;
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4350 }
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4351
dc3f82b04733 adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 528
diff changeset
4352
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4353 int cmd_trash_info(CmdArgs *a) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4354 if(a->argc != 1) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4355 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4356 return -1;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4357 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4358
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4359 SyncDirectory *syncdir = scfg_get_dir(a->argv[0]);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4360 if(!syncdir) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4361 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4362 return -1;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4363 }
233
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
4364 if(scfg_check_dir(syncdir)) {
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
4365 return -1;
d8042cede66c improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 228
diff changeset
4366 }
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4367
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4368 if(!syncdir->trash) {
205
bf756f6c3581 fixed some warnings and wrong usage of curl_easy_getinfo
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 204
diff changeset
4369 printf("trash not configured for %s\n", syncdir->name);
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4370 return 0;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4371 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4372
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4373 SYS_DIR dir = sys_opendir(syncdir->trash);
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4374 if(!dir) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4375 fprintf(stderr, "cannot open trash directory: %s\n", syncdir->trash);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4376 perror("opendir");
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4377 return -1;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4378 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4379
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4380 uint64_t trashsize = 0;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4381 int count = 0;
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4382 SysDirEnt *ent;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4383 while((ent = sys_readdir(dir)) != NULL) {
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4384 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) {
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4385 continue;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4386 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4387
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4388 char *path = util_concat_path(syncdir->trash, ent->name);
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4389
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4390 SYS_STAT s;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4391 if(sys_stat(path, &s)) {
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4392 perror("stat");
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4393 } else {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4394 trashsize += s.st_size;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4395 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4396 count++;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4397
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4398 free(path);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4399 }
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4400 sys_closedir(dir);
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4401
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4402 printf("path: %s\n", syncdir->trash);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4403 printf("%d %s\n", count, count == 1 ? "file" : "files");
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4404 char *sizestr = size_str(trashsize);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4405 printf("%s\n", sizestr);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4406 free(sizestr);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4407
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4408 return 0;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4409 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4410
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4411
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4412 int cmd_empty_trash(CmdArgs *a) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4413 if(a->argc != 1) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4414 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many");
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4415 return -1;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4416 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4417
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4418 SyncDirectory *syncdir = scfg_get_dir(a->argv[0]);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4419 if(!syncdir) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4420 fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4421 return -1;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4422 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4423
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4424 if(!syncdir->trash) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4425 fprintf(stderr, "trash not configured for %s\n", syncdir->name);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4426 return -1;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4427 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4428
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4429 SYS_DIR dir = sys_opendir(syncdir->trash);
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4430 if(!dir) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4431 fprintf(stderr, "cannot open trash directory: %s\n", syncdir->trash);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4432 perror("opendir");
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4433 return -1;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4434 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4435
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4436 SysDirEnt *ent;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4437 while((ent = sys_readdir(dir)) != NULL) {
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4438 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) {
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4439 continue;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4440 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4441
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4442 char *path = util_concat_path(syncdir->trash, ent->name);
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4443 printf("delete: %s\n", path);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4444
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4445 SYS_STAT s;
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4446 if(sys_stat(path, &s)) {
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4447 perror("stat");
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4448 free(path);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4449 continue;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4450 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4451 if(S_ISDIR(s.st_mode)) {
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4452 if(rmdir(path)) {
274
5577d3eae04c dav-sync command documentation complete
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 272
diff changeset
4453 perror("rmdir");
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4454 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4455 } else {
412
dc74f736aea1 adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 411
diff changeset
4456 if(sys_unlink(path)) {
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4457 perror("unlink");
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4458 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4459 }
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4460
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4461 free(path);
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4462 }
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4463 sys_closedir(dir);
204
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4464
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4465 return 0;
4f0207044837 added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 200
diff changeset
4466 }
47
fbbbeed4ba8f added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
4467
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4468 #define CMD_TAG_ADD 0
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4469 #define CMD_TAG_REMOVE 1
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
4470 #define CMD_TAG_SET 2
377
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4471 #define CMD_TAG_LIST 3
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4472 int cmd_add_tag(CmdArgs *args) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4473 if(args->argc != 2) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4474 fprintf(stderr, "Too %s arguments\n", args->argc <= 1 ? "few" : "many");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4475 return -1;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4476 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
4477 return cmd_tagop(args, CMD_TAG_ADD);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4478 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4479
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4480 int cmd_remove_tag(CmdArgs *args) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4481 if(args->argc != 2) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4482 fprintf(stderr, "Too %s arguments\n", args->argc <= 1 ? "few" : "many");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4483 return -1;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4484 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
4485 return cmd_tagop(args, CMD_TAG_REMOVE);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4486 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4487
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
4488 int cmd_set_tags(CmdArgs *args) {
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4489 if(args->argc < 1 || args->argc > 2) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4490 fprintf(stderr, "Too %s arguments\n", args->argc < 1 ? "few" : "many");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4491 return -1;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4492 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
4493 return cmd_tagop(args, CMD_TAG_SET);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4494 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4495
377
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4496 int cmd_list_tags(CmdArgs *args) {
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4497 if(args->argc != 1) {
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4498 fprintf(stderr, "Too %s arguments\n", args->argc <= 1 ? "few" : "many");
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4499 return -1;
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4500 }
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
4501 return cmd_tagop(args, CMD_TAG_LIST);
377
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4502 }
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4503
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
4504 int cmd_tagop(CmdArgs *args, int cmd) {
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4505 SyncFile file;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4506 int ret = 0;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4507 char *path = args->argv[0];
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4508
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4509 int err = sync_get_file(args, path, &file, TRUE);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4510 if(err) {
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4511 sync_print_get_file_err(path, err);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4512 return -1;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4513 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4514
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4515 if(!file.dir->tagconfig) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4516 fprintf(stderr, "Tags are not supported for this sync directory\n");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4517 return -1;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4518 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4519
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4520 SyncDatabase *db = load_db(file.dir->database);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4521 if(!db) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4522 fprintf(stderr, "Cannot load sync directory database\n");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4523 return -1;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4524 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4525
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4526 LocalResource *localres = ucx_map_cstr_get(db->resources, file.path);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4527 UcxList *tags = NULL;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4528 DavBool store_tags = FALSE;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4529
380
8a0c727aa409 adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
4530 if(cmd != CMD_TAG_SET) {
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4531 char *tag = args->argv[1];
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4532 char *tagcolor = NULL; // TODO: get color
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4533
525
26a1d5b9d9d2 improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 524
diff changeset
4534 tags = sync_get_file_tags(file.dir, localres, NULL, NULL);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4535 UcxList *x = NULL;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4536 UCX_FOREACH(elm, tags) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4537 DavTag *t = elm->data;
377
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4538 if(cmd == CMD_TAG_LIST) {
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4539 printf("%s\n", t->name);
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4540 } else if(!strcmp(t->name, tag)) {
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4541 x = elm;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4542 break;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4543 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4544 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4545
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4546 if(cmd == CMD_TAG_ADD) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4547 if(!x) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4548 DavTag *newtag = malloc(sizeof(DavTag));
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4549 newtag->name = tag;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4550 newtag->color = tagcolor;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4551 tags = ucx_list_append(tags, newtag);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4552 store_tags = TRUE;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4553 }
377
d6d7c16dd066 adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 374
diff changeset
4554 } else if(cmd == CMD_TAG_REMOVE) {
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4555 if(tags) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4556 tags = ucx_list_remove(tags, x);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4557 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4558 store_tags = TRUE;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4559 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4560 } else {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4561 if(args->argc == 2) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4562 char *tags_str = args->argv[1];
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4563 tags = parse_csv_taglist(tags_str, strlen(tags_str));
378
d64ecd8d6969 fixes dav-sync update-tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 377
diff changeset
4564 store_tags = TRUE;
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4565 // TODO: read from stdin if tags_str is "-"
381
17ccf828a2f2 fixes dav-sync set-tags without tag string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
4566 } else if (args->argc == 1) {
17ccf828a2f2 fixes dav-sync set-tags without tag string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
4567 store_tags = TRUE;
17ccf828a2f2 fixes dav-sync set-tags without tag string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
4568 } else {
17ccf828a2f2 fixes dav-sync set-tags without tag string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
4569 fprintf(stderr, "Too many arguments\n");
17ccf828a2f2 fixes dav-sync set-tags without tag string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 380
diff changeset
4570 ret = -1;
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4571 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4572 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4573
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4574 if(store_tags) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4575 if(sync_store_tags_local(file.dir, NULL, path, tags)) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4576 fprintf(stderr, "Cannot store tags\n");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4577 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4578 if(localres) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4579 localres->tags_updated = TRUE;
379
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
4580 if(!tags) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
4581 if(localres->tags_hash) {
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
4582 free(localres->tags_hash);
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
4583 }
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
4584 localres->tags_hash = NULL;
cdaf5a3d3a50 fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
4585 }
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4586 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4587 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4588
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4589 // store db
521
c5bbae4b3cca extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 516
diff changeset
4590 if(store_db(db, file.dir->database, file.dir->db_settings)) {
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4591 fprintf(stderr, "Cannot store sync db\n");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4592 ret = -2;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4593 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4594
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4595 free(file.path);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4596 return ret;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4597 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4598
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4599 int isfileindir(SyncDirectory *dir, const char *path, SyncFile *f) {
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4600 char *fullpath;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4601 if(path[0] != '/') {
386
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4602 size_t wdlen = 256;
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4603 char *wd = malloc(wdlen);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4604 while(!getcwd(wd, wdlen)) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4605 if(errno == ERANGE) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4606 wdlen *= 2;
386
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4607 char *newbuf = realloc(wd, wdlen);
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4608 if (newbuf) {
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4609 wd = newbuf;
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4610 } else {
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4611 free(wd);
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4612 return 0;
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4613 }
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4614 } else {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4615 free(wd);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4616 return 0;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4617 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4618 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4619
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4620 fullpath = util_concat_path(wd, path);
386
99193580aa9d fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents: 381
diff changeset
4621 free(wd);
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4622 } else {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4623 fullpath = strdup(path);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4624 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4625
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4626 // TODO: normalize path
531
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4627 DavBool not_in_dir = 0;
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4628
531
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4629 scstr_t fp = scstr(fullpath);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4630 scstr_t dp = scstr(dir->path);
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4631 if(fp.length == dp.length) {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4632 if(sstrcmp(fp, dp)) {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4633 not_in_dir = 1;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4634 }
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4635 } else if(fp.length < dp.length) {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4636 not_in_dir = 1;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4637 } else {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4638 if(!sstrprefix(fp, dp)) {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4639 not_in_dir = 1;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4640 } else {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4641 if(dp.ptr[dp.length-1] == '/') {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4642 dp.length--;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4643 }
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4644 if(fp.ptr[dp.length] != '/') {
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4645 not_in_dir = 1;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4646 }
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4647 }
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4648 }
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4649
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4650 if(not_in_dir) {
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4651 free(fullpath);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4652 return 0;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4653 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4654
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4655 // TODO: check filter
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4656
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4657 f->dir = dir;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4658 f->path = util_concat_path("/", fullpath + strlen(dir->path));
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4659
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4660 free(fullpath);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4661 return 1;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4662 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4663
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4664 int sync_get_file(CmdArgs *args, const char *path, SyncFile *f, DavBool dostat) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4665 if(dostat) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4666 SYS_STAT s;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4667 if(sys_stat(path, &s)) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4668 switch(errno) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4669 case EACCES: return 2;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4670 case ENOENT: return 1;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4671 default: return 3;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4672 }
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4673 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4674 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4675
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4676 char *sdir = cmd_getoption(args, "syncdir");
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4677
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4678 if(sdir) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4679 SyncDirectory *dir = scfg_get_dir(sdir);
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4680 if(!dir) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4681 return 6;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4682 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4683 if(!isfileindir(dir, path, f)) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4684 return 4;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4685 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4686 } else {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4687 SyncDirectory *target = NULL;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4688
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4689 UcxMapIterator i = scfg_directory_iterator();
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4690 UcxKey k;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4691 SyncDirectory *dir;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4692 UCX_MAP_FOREACH(key, dir, i) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4693 if(isfileindir(dir, path, f)) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4694 if(target) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4695 return 5;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4696 } else {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4697 target = dir;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4698 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4699 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4700 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4701
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4702 if(!target) {
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4703 return 4;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4704 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4705 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4706
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4707 return 0;
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4708 }
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4709
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4710 void sync_print_get_file_err(const char *path, int err) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4711 switch(err) {
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4712 case 1: fprintf(stderr, "File %s: not found\n", path); break;
539
8deb52292c99 fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 536
diff changeset
4713 case 2: fprintf(stderr, "File %s: permission denied\n", path); break;
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4714 case 3: fprintf(stderr, "File %s: stat failed: %s\n", path, strerror(errno)); break;
531
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4715 case 4: fprintf(stderr, "File %s is not in any syncdir\n", path); break;
fa54e3a1250a implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 530
diff changeset
4716 case 5: fprintf(stderr, "File %s is in multiple syncdirs\n", path); break;
527
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4717 case 6: fprintf(stderr, "Syncdir not found\n"); break;
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4718 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4719 }
d0e37224eba1 adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 526
diff changeset
4720
372
2e15ff88a0ab adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 370
diff changeset
4721
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4722 int cmd_add_directory(CmdArgs *args) {
294
dd5c0ebdf54f fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
4723 if(!get_repositories()) {
dd5c0ebdf54f fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
4724 fprintf(stderr, "No repositories available. Run 'dav add-repository' first.\n");
dd5c0ebdf54f fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
4725 fprintf(stderr, "Abort\n");
dd5c0ebdf54f fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
4726 return -1;
dd5c0ebdf54f fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
4727 }
dd5c0ebdf54f fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 288
diff changeset
4728
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4729 printf("Each sync directory must have an unique name.\n");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4730 char *name = assistant_getcfg("name");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4731 if(!name) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4732 fprintf(stderr, "Abort\n");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4733 return -1;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4734 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4735 if(scfg_get_dir(name)) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4736 fprintf(stderr, "Directory %s already exists.\nAbort\n", name);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4737 return -1;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4738 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4739
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4740 printf("Enter local directory path.\n");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4741 char *path = assistant_getcfg("path");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4742 if(!path) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4743 fprintf(stderr, "Abort\n");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4744 return -1;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4745 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4746
215
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4747 printf("Specify webdav repository.\n");
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4748 UcxList *repos = get_repositories();
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4749 int i = 0;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4750 UCX_FOREACH(elm, repos) {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4751 Repository *r = elm->data;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4752 printf("%d) %s\n", i, r->name);
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4753 i++;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4754 }
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4755 char *repository = assistant_getcfg("repository");
215
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4756 char *reponame = NULL;
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4757 if(!repository) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4758 fprintf(stderr, "Abort\n");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4759 return -1;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4760 }
215
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4761 int64_t reponum = 0;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4762 if(util_strtoint(repository, &reponum)) {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4763 if(reponum < 0) {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4764 fprintf(stderr, "Wrong input.\nAbort\n");
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4765 return -1;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4766 }
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4767 UcxList *elm = ucx_list_get(repos, reponum);
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4768 if(elm) {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4769 Repository *r = elm->data;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4770 reponame = r->name;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4771 } else {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4772 fprintf(stderr, "Wrong input.\nAbort\n");
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4773 return -1;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4774 }
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4775 } else {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4776 if(get_repository(sstr(repository))) {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4777 reponame = repository;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4778 } else {
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4779 fprintf(stderr, "Repository %s doesn't exist.\nAbort\n", repository);
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4780 return -1;
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4781 }
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4782 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4783
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4784 printf("Enter collection relative to the repository base url.\n");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4785 char *collection = assistant_getdefcfg("collection", "/");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4786
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4787 char *db = generate_db_name(name);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4788
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4789 SyncDirectory dir;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4790 memset(&dir, 0, sizeof(SyncDirectory));
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4791 dir.name = name;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4792 dir.path = path;
215
781aee172901 dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 214
diff changeset
4793 dir.repository = reponame;
200
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4794 dir.collection = collection;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4795 dir.trash = ".trash";
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4796 dir.database = db;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4797
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4798 int ret = 0;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4799 if(add_directory(&dir)) {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4800 fprintf(stderr, "Cannot write sync.xml\n");
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4801 ret = -1;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4802 } else {
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4803 printf("\nAdded directory: %s (%s)\n", name, path);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4804 }
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4805
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4806 free(name);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4807 free(path);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4808 free(repository);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4809 free(collection);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4810 free(db);
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4811
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4812 return ret;
cc474cf2c2f5 added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 199
diff changeset
4813 }
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
4814
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4815 int cmd_list_dirs() {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4816 UcxMapIterator iter = scfg_directory_iterator();
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4817 SyncDirectory *dir;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4818 UCX_MAP_FOREACH(key, dir, iter) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4819 printf("%s\n", dir->name);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4820 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4821 return 0;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4822 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4823
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
4824 int cmd_check_repositories() {
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4825 int ret = EXIT_SUCCESS;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4826
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4827 UcxList *reponames = NULL;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4828 {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4829 UcxMapIterator iter = scfg_directory_iterator();
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4830 SyncDirectory *dir;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4831 UCX_MAP_FOREACH(key, dir, iter) {
505
481802342fdf ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 504
diff changeset
4832 reponames = ucx_list_append(reponames, dir->repository);
256
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4833 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4834 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4835
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4836 UCX_FOREACH(listelem, reponames) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4837 char *reponame = listelem->data;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4838 printf("Checking %s... ", reponame);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4839 Repository* repo = get_repository(sstr(reponame));
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4840 if (!repo) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4841 printf(" not found in config.xml!\n");
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4842 ret = EXIT_FAILURE;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4843 } else {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4844 DavSession *sn = create_session(ctx, repo, repo->url);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4845 if (sn) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4846 DavResource *res = dav_query(sn,
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4847 "select - from / with depth = 0");
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4848 if (res) {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4849 printf("OK.\n");
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4850 dav_resource_free(res);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4851 } else {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4852 printf("unavailable!\n");
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4853 ret = EXIT_FAILURE;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4854 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4855 dav_session_destroy(sn);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4856 } else {
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4857 printf("cannot create session!\n");
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4858 ret = EXIT_FAILURE;
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4859 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4860 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4861 }
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4862
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4863 ucx_list_free(reponames);
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4864
54433cb371df implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents: 254
diff changeset
4865 return ret;
252
6b8e287269fc improves config error reporting and adds check (check-config) command + dav-sync no longer aborts on missing sync.xml
Mike Becker <universe@uap-core.de>
parents: 244
diff changeset
4866 }
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4867
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4868 char* create_locktoken_file(const char *syncdirname, const char *locktoken) {
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4869 sstr_t fname = ucx_sprintf("locktoken-%s.txt", syncdirname);
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4870 char *path = config_file_path(fname.ptr);
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4871 free(fname.ptr);
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4872
411
a182e503617b using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 405
diff changeset
4873 FILE *file = sys_fopen(path, "w");
313
d721250984d0 fixes possible UAF for locktocken paths, if file could not be opened
Mike Becker <universe@uap-core.de>
parents: 302
diff changeset
4874 if(file) {
d721250984d0 fixes possible UAF for locktocken paths, if file could not be opened
Mike Becker <universe@uap-core.de>
parents: 302
diff changeset
4875 fprintf(file, "%s\n", locktoken);
d721250984d0 fixes possible UAF for locktocken paths, if file could not be opened
Mike Becker <universe@uap-core.de>
parents: 302
diff changeset
4876 fclose(file);
d721250984d0 fixes possible UAF for locktocken paths, if file could not be opened
Mike Becker <universe@uap-core.de>
parents: 302
diff changeset
4877 return path;
d721250984d0 fixes possible UAF for locktocken paths, if file could not be opened
Mike Becker <universe@uap-core.de>
parents: 302
diff changeset
4878 } else {
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4879 perror("Cannot create locktoken file");
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4880 free(path);
313
d721250984d0 fixes possible UAF for locktocken paths, if file could not be opened
Mike Becker <universe@uap-core.de>
parents: 302
diff changeset
4881 return NULL;
296
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4882 }
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4883 }
bb49953b1cf8 dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 294
diff changeset
4884
542
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4885 char* sync_get_content_hash(DavResource *res) {
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4886 uint32_t flags = res->session->flags;
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4887 if((flags & DAV_SESSION_ENCRYPT_CONTENT) == DAV_SESSION_ENCRYPT_CONTENT) {
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4888 char *enc_hash = dav_get_string_property_ns(res, DAV_NS, "crypto-hash");
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4889 char *keyname = dav_get_string_property_ns(res, DAV_NS, "crypto-key");
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4890 if(enc_hash && keyname) {
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4891 DavKey *key = dav_context_get_key(res->session->context, keyname);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4892 if(!key) {
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4893 return NULL;
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4894 }
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4895
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4896 size_t len = 0;
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4897 char *dec_hash = aes_decrypt(enc_hash, &len, key);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4898 if(!dec_hash) {
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4899 return NULL;
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4900 }
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4901
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4902 char *hex_hash = util_hexstr((unsigned char*)dec_hash, len);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4903 free(dec_hash);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4904 return hex_hash;
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4905 }
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4906 } else {
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4907 return dav_get_string_property_ns(res, DAV_NS, "content-hash");
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4908 }
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4909 return NULL;
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4910 }
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4911
558
1a9e6a5c1e79 fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents: 557
diff changeset
4912 void sync_set_content_hash(DavResource *res, const unsigned char *hashdata) {
542
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4913 uint32_t flags = res->session->flags;
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4914 if((flags & DAV_SESSION_ENCRYPT_CONTENT) == DAV_SESSION_ENCRYPT_CONTENT) {
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4915 if(res->session->key) {
558
1a9e6a5c1e79 fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents: 557
diff changeset
4916 char *enc_hash = aes_encrypt((const char*)hashdata, DAV_SHA256_DIGEST_LENGTH, res->session->key);
542
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4917 if(enc_hash) {
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4918 dav_set_string_property_ns(res, DAV_NS, "crypto-hash", enc_hash);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4919 free(enc_hash);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4920 }
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4921 }
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4922 } else {
558
1a9e6a5c1e79 fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents: 557
diff changeset
4923 char *hex_hash = util_hexstr(hashdata, DAV_SHA256_DIGEST_LENGTH);
542
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4924 dav_set_string_property_ns(res, DAV_NS, "content-hash", hex_hash);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4925 free(hex_hash);
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4926 }
060a8cda7f62 adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
4927 }

mercurial