Mon, 06 Jan 2025 21:18:36 +0100
update ucx
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> |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
33 | |
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> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include <libxml/xmlerror.h> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include <sys/types.h> |
750 | 38 | #include <cx/map.h> |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
39 | #include <cx/utils.h> |
750 | 40 | #include <cx/list.h> |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
41 | #include <cx/hash_map.h> |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
42 | #include <cx/printf.h> |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
43 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
44 | #ifndef _WIN32 |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
45 | // unix includes |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
46 | #include <unistd.h> |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
47 | #include <utime.h> |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
48 | #include <pthread.h> |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
49 | #else |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
50 | //windows includes |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
51 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
52 | #endif |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
53 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
55 | #include <math.h> |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
56 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | #include <libidav/webdav.h> |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | #include <libidav/utils.h> |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
59 | #include <libidav/crypto.h> |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
399
a985a587787f
fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
61 | #include <libidav/session.h> |
a985a587787f
fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
62 | |
a985a587787f
fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
63 | #include "sync.h" |
a985a587787f
fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
64 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | #include "config.h" |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | #include "sopt.h" |
191
0e45b04236a7
more specific error messages in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
190
diff
changeset
|
67 | #include "error.h" |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
68 | #include "assistant.h" |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
69 | #include "libxattr.h" |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
70 | #include "tags.h" |
833 | 71 | #include "connect.h" |
399
a985a587787f
fixes header include order (dav-sync)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
72 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
73 | #include "system.h" |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
75 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
76 | #ifdef _WIN32 |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
77 | #define strcasecmp _stricmp |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
78 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
79 | #ifndef S_ISDIR |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
80 | #define S_ISDIR(mode) ((mode) & _S_IFMT) == _S_IFDIR |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
81 | #define S_ISREG(mode) ((mode) & _S_IFMT) == _S_IFREG |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
82 | #endif |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
83 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
84 | #endif |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
85 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | static DavContext *ctx; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
88 | static int sync_shutdown = 0; |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
89 | |
779
a0e02b70dad1
add log_printf function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
90 | static FILE *synclog; |
a0e02b70dad1
add log_printf function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
91 | |
784
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
92 | static int orig_argc; |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
93 | static char **orig_argv; |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
94 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | 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
|
96 | 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
|
97 | 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
|
98 | 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
|
99 | va_end(ap); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
102 | static DavPropName defprops[] = { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
103 | { "DAV:", "getetag" }, |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
104 | { DAV_NS, "status" }, |
541
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
105 | { DAV_NS, "content-hash" }, |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
106 | { DAV_NS, "split" }, |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
107 | { DAV_PROPS_NS, "finfo" }, |
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
108 | { DAV_PROPS_NS, "tags" }, |
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
109 | { DAV_PROPS_NS, "xattributes" }, |
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
110 | { DAV_PROPS_NS, "link" } |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
111 | }; |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
112 | static size_t numdefprops = 8 ; |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
113 | |
780
cd1c869720e0
remove loglevel parameter from log_printf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
779
diff
changeset
|
114 | void log_printf(const char *fmt, ...) { |
779
a0e02b70dad1
add log_printf function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
115 | va_list ap; |
a0e02b70dad1
add log_printf function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
116 | va_start(ap, fmt); |
a0e02b70dad1
add log_printf function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
117 | cxmutstr str = cx_vasprintf(fmt, ap); |
780
cd1c869720e0
remove loglevel parameter from log_printf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
779
diff
changeset
|
118 | |
cd1c869720e0
remove loglevel parameter from log_printf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
779
diff
changeset
|
119 | printf("%s", str.ptr); |
cd1c869720e0
remove loglevel parameter from log_printf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
779
diff
changeset
|
120 | if(synclog) { |
cd1c869720e0
remove loglevel parameter from log_printf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
779
diff
changeset
|
121 | fprintf(synclog, "%s", str.ptr); |
cd1c869720e0
remove loglevel parameter from log_printf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
779
diff
changeset
|
122 | } |
cd1c869720e0
remove loglevel parameter from log_printf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
779
diff
changeset
|
123 | free(str.ptr); |
cd1c869720e0
remove loglevel parameter from log_printf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
779
diff
changeset
|
124 | |
779
a0e02b70dad1
add log_printf function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
125 | va_end(ap); |
a0e02b70dad1
add log_printf function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
126 | } |
a0e02b70dad1
add log_printf function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
775
diff
changeset
|
127 | |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
128 | void log_error(const char *fmt, ...) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
129 | va_list ap; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
130 | va_start(ap, fmt); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
131 | cxmutstr str = cx_vasprintf(fmt, ap); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
132 | |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
133 | fprintf(stderr, "%s", str.ptr); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
134 | if(synclog) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
135 | fprintf(synclog, "%s", str.ptr); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
136 | } |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
137 | free(str.ptr); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
138 | |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
139 | va_end(ap); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
140 | } |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
141 | |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
142 | void log_resource_error(DavSession *sn, const char *path) { |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
143 | print_resource_error(sn, path); |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
144 | if(synclog) { |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
145 | print_resource_error_to_file(synclog, sn, path); |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
146 | } |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
147 | } |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
148 | |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
149 | |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
150 | int logfile_open(SyncDirectory *dir) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
151 | int ret = 0; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
152 | if(dir && dir->logfile) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
153 | char *lf_path = dir->logfile; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
154 | char *lf_path_fr = NULL; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
155 | if(dir->logfile[0] != '/') { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
156 | lf_path = config_file_path(dir->logfile); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
157 | lf_path_fr = lf_path; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
158 | } |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
159 | |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
160 | synclog = fopen(lf_path, "a"); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
161 | if(!synclog) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
162 | fprintf(stderr, "Cannot open logfile %s: %s\n", lf_path, strerror(errno)); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
163 | ret = 1; |
784
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
164 | } else { |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
165 | time_t t = time(NULL); |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
166 | char *now = ctime(&t); |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
167 | size_t len = strlen(now); |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
168 | if(now[len-1] == '\n') { |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
169 | len--; |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
170 | } |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
171 | |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
172 | fprintf(synclog, "[%.*s] ", (int)len, now); |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
173 | for(int i=0;i<orig_argc;i++) { |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
174 | fprintf(synclog, "%s ", orig_argv[i]); |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
175 | } |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
176 | fprintf(synclog, "\n"); |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
177 | } |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
178 | if(lf_path_fr) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
179 | free(lf_path_fr); |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
180 | } |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
181 | } |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
182 | return ret; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
183 | } |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
184 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
185 | /* |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
186 | * 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
|
187 | */ |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
188 | 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
|
189 | if(!s1 && s2) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
190 | return -1; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
191 | } |
532
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
192 | if(s1 && !s2) { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
193 | return 1; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
194 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
195 | if(!s1 && !s2) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
196 | return 0; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
197 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
198 | return strcmp(s1, s2); |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
199 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
200 | |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
201 | static char* nullstrdup(const char *s) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
202 | return s ? strdup(s) : NULL; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
203 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
204 | |
557
90ad7324bbbc
fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
556
diff
changeset
|
205 | static void nullfree(void *p) { |
90ad7324bbbc
fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
556
diff
changeset
|
206 | if(p) { |
90ad7324bbbc
fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
556
diff
changeset
|
207 | free(p); |
90ad7324bbbc
fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
556
diff
changeset
|
208 | } |
90ad7324bbbc
fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
556
diff
changeset
|
209 | } |
90ad7324bbbc
fix dav-sync push conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
556
diff
changeset
|
210 | |
749
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
211 | |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
212 | |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
213 | static CxIterator mapIteratorValues(CxMap *map) { |
750 | 214 | return cxMapIteratorValues(map ? map : cxEmptyMap); |
749
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
215 | } |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
216 | |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
217 | static CxIterator listIterator(CxList *list) { |
750 | 218 | return cxListIterator(list ? list : cxEmptyList); |
749
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
219 | } |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
220 | |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
221 | typedef void*(*clonefunc)(void *elm, void *userdata); |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
222 | |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
223 | static CxMap* mapClone(const CxAllocator *a, CxMap *map, clonefunc clone, void *userdata) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
224 | CxMap *newmap = cxHashMapCreate( |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
225 | a, |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
226 | cxMapIsStoringPointers(map) ? CX_STORE_POINTERS : map->collection.elem_size, |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
227 | cxMapSize(map) + 4 |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
228 | ); |
749
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
229 | |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
230 | CxIterator i = cxMapIterator(map); |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
231 | if(clone) { |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
232 | cx_foreach(CxMapEntry*, entry, i) { |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
233 | void *newdata = clone(entry->value, userdata); |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
234 | cxMapPut(newmap, *entry->key, newdata); |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
235 | } |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
236 | } else { |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
237 | cx_foreach(CxMapEntry*, entry, i) { |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
238 | cxMapPut(newmap, *entry->key, entry->value); |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
239 | } |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
240 | } |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
241 | |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
242 | return newmap; |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
243 | } |
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
244 | |
687
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
245 | int dav_sync_main(int argc, char **argv); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
246 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
247 | #ifdef _WIN32 |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
248 | static char* wchar2utf8(const wchar_t *wstr, size_t wlen) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
249 | size_t maxlen = wlen * 4; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
250 | char *ret = malloc(maxlen + 1); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
251 | int ret_len = WideCharToMultiByte( |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
252 | CP_UTF8, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
253 | 0, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
254 | wstr, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
255 | wlen, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
256 | ret, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
257 | maxlen, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
258 | NULL, |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
259 | NULL); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
260 | ret[ret_len] = 0; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
261 | return ret; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
262 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
263 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
264 | int wmain(int argc, wchar_t **argv) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
265 | char **argv_utf8 = calloc(argc, sizeof(char*)); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
266 | for(int i=0;i<argc;i++) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
267 | argv_utf8[i] = wchar2utf8(argv[i], wcslen(argv[i])); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
268 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
269 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
270 | int ret = dav_sync_main(argc, argv_utf8); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
271 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
272 | for(int i=0;i<argc;i++) { |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
273 | free(argv_utf8[i]); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
274 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
275 | free(argv_utf8); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
276 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
277 | return ret; |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
278 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
279 | #else |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | int main(int argc, char **argv) { |
687
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
281 | return dav_sync_main(argc, argv); |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
282 | } |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
283 | #endif |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
284 | |
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
285 | int dav_sync_main(int argc, char **argv) { |
784
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
286 | orig_argc = argc; |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
287 | orig_argv = argv; |
592ff4ca2aaa
log command line arguments
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
783
diff
changeset
|
288 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | if(argc < 2) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | fprintf(stderr, "Missing command\n"); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | print_usage(argv[0]); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | return -1; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | char *cmd = argv[1]; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | if(!args) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | print_usage(argv[0]); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | return -1; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | } |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
301 | int ret = EXIT_FAILURE; |
54 | 302 | |
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
|
303 | 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
|
304 | || !strcasecmp(cmd, "--version")) { |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
305 | 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
|
306 | cmd_args_free(args); |
0468df02e18f
fixed dav get with -u option
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
233
diff
changeset
|
307 | return -1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | |
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
|
310 | 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
|
311 | initGenericErrorDefaultFunc(&fnc); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
312 | sys_init(); |
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
|
313 | 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
|
314 | 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
|
315 | |
680
e66f2645be65
ignore sigpipe in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
679
diff
changeset
|
316 | // ignore sigpipe to make sure the program doesn't exit |
e66f2645be65
ignore sigpipe in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
679
diff
changeset
|
317 | // if stdout will be closed (for example by using dav-sync ... | head) |
687
9922a349a61a
add support for unicode args on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
686
diff
changeset
|
318 | #ifndef _WIN32 |
680
e66f2645be65
ignore sigpipe in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
679
diff
changeset
|
319 | struct sigaction act; |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
320 | memset(&act, 0, sizeof(struct sigaction)); |
680
e66f2645be65
ignore sigpipe in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
679
diff
changeset
|
321 | act.sa_handler = SIG_IGN; |
e66f2645be65
ignore sigpipe in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
679
diff
changeset
|
322 | sigaction(SIGPIPE, &act, NULL); |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
323 | |
680
e66f2645be65
ignore sigpipe in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
679
diff
changeset
|
324 | // prepare signal handler thread |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
325 | pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
326 | pthread_mutex_lock(&mutex); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
327 | pthread_t tid; |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
328 | #else |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
329 | int tid; |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
330 | int mutex; |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
331 | #endif |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
332 | |
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
|
333 | 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
|
334 | 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
|
335 | 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
|
336 | 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
|
337 | } 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
|
338 | /* 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
|
339 | 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
|
340 | } |
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
|
341 | } 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
|
342 | if(!strcmp(cmd, "pull")) { |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
343 | tid = start_sighandler(&mutex); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
344 | ret = cmd_pull(args, FALSE); |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
345 | 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
|
346 | } else if(!strcmp(cmd, "push")) { |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
347 | tid = start_sighandler(&mutex); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
348 | ret = cmd_push(args, FALSE, FALSE); |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
349 | stop_sighandler(&mutex, tid); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
350 | } else if(!strcmp(cmd, "outgoing")) { |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
351 | ret = cmd_push(args, TRUE, FALSE); |
299
c517502d3e38
adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
352 | } else if(!strcmp(cmd, "archive")) { |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
353 | tid = start_sighandler(&mutex); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
354 | ret = cmd_push(args, FALSE, TRUE); |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
355 | stop_sighandler(&mutex, tid); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
356 | } else if(!strcmp(cmd, "restore")) { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
357 | tid = start_sighandler(&mutex); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
358 | ret = cmd_restore(args); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
359 | stop_sighandler(&mutex, tid); |
563
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
360 | } else if(!strcmp(cmd, "list-conflicts")) { |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
361 | 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
|
362 | } 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
|
363 | 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
|
364 | } 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
|
365 | ret = cmd_delete_conflicts(args); |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
366 | } else if(!strcmp(cmd, "list-versions")) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
367 | 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
|
368 | } 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
|
369 | 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
|
370 | } 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
|
371 | ret = cmd_empty_trash(args); |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
372 | } else if(!strcmp(cmd, "add-tag")) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
373 | ret = cmd_add_tag(args); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
374 | } else if(!strcmp(cmd, "remove-tag")) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
375 | ret = cmd_remove_tag(args); |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
376 | } else if(!strcmp(cmd, "set-tags")) { |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
377 | ret = cmd_set_tags(args); |
377
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
378 | } else if(!strcmp(cmd, "list-tags")) { |
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
379 | ret = cmd_list_tags(args); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
380 | } else if(!strcmp(cmd, "add-dir") |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
381 | || !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
|
382 | ret = cmd_add_directory(args); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
383 | } else if(!strcmp(cmd, "list-dirs") |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
384 | || !strcmp(cmd, "list-directories")) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
385 | ret = cmd_list_dirs(); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
386 | } else if(!strcmp(cmd, "check-repos") |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
387 | || !strcmp(cmd, "check-repositories")) { |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
388 | ret = cmd_check_repositories(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
|
389 | } 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
|
390 | 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
|
391 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
394 | // cleanup |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
395 | cmd_args_free(args); |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
396 | dav_context_destroy(ctx); |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
397 | |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
398 | free_config(); |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
399 | free_sync_config(); |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
400 | |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
401 | curl_global_cleanup(); |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
402 | xmlCleanupParser(); |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
403 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
404 | sys_uninit(); |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
405 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | return ret; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | void print_usage(char *cmd) { |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
410 | 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
|
411 | |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
412 | fprintf(stderr, "Commands:\n"); |
405
6b85d745e402
fixes some char type mismatch warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
403
diff
changeset
|
413 | 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
|
414 | 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
|
415 | 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
|
416 | fprintf(stderr, |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
417 | " 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
|
418 | 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
|
419 | 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
|
420 | 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
|
421 | 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
|
422 | fprintf(stderr, " empty-trash <directory>\n"); |
702
444aa8fe133f
finish documentation of new dav-sync commands and options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
693
diff
changeset
|
423 | fprintf(stderr, " list-versions [-s <syncdir>] <file>\n"); |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
424 | 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
|
425 | 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
|
426 | fprintf(stderr, " set-tags [-s <syncdir>] <file> [tags]\n"); |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
427 | 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
|
428 | |
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
429 | fprintf(stderr, "Options:\n"); |
693
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
430 | fprintf(stderr, " -c Disable conflict detection\n"); |
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
431 | fprintf(stderr, " -l Lock the repository before access\n"); |
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
432 | fprintf(stderr, " -d Don't lock the repository\n"); |
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
433 | fprintf(stderr, " -t <tags> " |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
434 | "Only sync files which have the specified tags\n"); |
693
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
435 | fprintf(stderr, " -r " |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
436 | "Remove resources not matching the tag filter\n"); |
693
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
437 | fprintf(stderr, " -V <vers> Restore specific version\n"); |
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
438 | fprintf(stderr, " -S Save previous file version\n"); |
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
439 | fprintf(stderr, " -R Restore removed files\n"); |
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
440 | fprintf(stderr, " -M Restore modified files\n"); |
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
441 | fprintf(stderr, " -s <syncdir> Name of the syncdir the file is in\n"); |
8ca795c1ae1c
add -s option to dav-sync usage output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
692
diff
changeset
|
442 | 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
|
443 | |
44054c452de1
added list-repositories and list-directories commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
192
diff
changeset
|
444 | fprintf(stderr, "Config commands:\n"); |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
445 | 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
|
446 | fprintf(stderr, " list-directories\n"); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
447 | 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
|
448 | fprintf(stderr, " check-repositories\n\n"); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
451 | static void handlesig(int sig) { |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
452 | if(sync_shutdown) { |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
453 | exit(-1); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
454 | } |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
455 | fprintf(stderr, "abort\n"); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
456 | sync_shutdown = 1; |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
457 | } |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
458 | |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
459 | #ifndef _WIN32 |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
460 | static void* sighandler(void *data) { |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
461 | signal(SIGTERM, handlesig); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
462 | signal(SIGINT, handlesig); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
463 | |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
464 | pthread_mutex_t *mutex = data; |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
465 | pthread_mutex_lock(mutex); // block thread |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
466 | return NULL; |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
467 | } |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
468 | |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
469 | 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
|
470 | pthread_t tid; |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
471 | if(pthread_create(&tid, NULL, sighandler, mutex)) { |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
472 | perror("pthread_create"); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
473 | exit(-1); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
474 | } |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
475 | return tid; |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
476 | } |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
477 | |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
478 | 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
|
479 | pthread_mutex_unlock(mutex); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
480 | void *data; |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
481 | pthread_join(tid, &data); |
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
482 | } |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
483 | #else |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
484 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
485 | int start_sighandler(int* mutex) { |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
486 | return 0; |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
487 | } |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
488 | int stop_sighandler(int* mutex, int tid) { |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
489 | return 0; |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
490 | } |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
491 | |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
492 | #endif |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
493 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
494 | 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
|
495 | 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
|
496 | 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
|
497 | 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
|
498 | 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
|
499 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
500 | return local_path; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
501 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
502 | |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
503 | static int res_matches_filter(Filter *filter, char *res_path) { |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
504 | // include/exclude filter |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
505 | CxIterator i = cxListIterator(filter->include); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
506 | cx_foreach(regex_t*, pattern, i) { |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
507 | if (regexec(pattern, res_path, 0, NULL, 0) == 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
508 | CxIterator e = cxListIterator(filter->exclude); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
509 | cx_foreach(regex_t*, expat, e) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
510 | if (regexec(expat, res_path, 0, NULL, 0) == 0) { |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
511 | return 1; |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
512 | } |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
513 | } |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
514 | return 0; |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
515 | } |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
516 | } |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
517 | return 1; |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
518 | } |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
519 | |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
520 | static int res_matches_dir_filter(SyncDirectory *dir, char *res_path) { |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
521 | // trash filter |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
522 | if (dir->trash) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
523 | cxmutstr rpath = cx_mutstr(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
|
524 | 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
|
525 | free(rpath.ptr); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
526 | return 1; |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
527 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
528 | free(rpath.ptr); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
529 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
530 | |
543
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
531 | // versioning filter |
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
532 | if (dir->versioning) { |
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
533 | 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
|
534 | return 1; |
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
535 | } |
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
536 | } |
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
537 | |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
538 | return res_matches_filter(&dir->filter, res_path); |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
539 | } |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
540 | |
389
fe855ce911f9
introduces SyncTagFilter type which for now implements the old tag list filter
Mike Becker <universe@uap-core.de>
parents:
386
diff
changeset
|
541 | 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
|
542 | 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
|
543 | return 1; |
6e1861e8262c
check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
544 | } |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
545 | // NOTE: currently not implementable |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
546 | //int scope = res->iscollection ? |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
547 | // DAV_SYNC_TAGFILTER_SCOPE_COLLECTION |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
548 | // : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE; |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
549 | //if((tagfilter->scope & scope) != scope) { |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
550 | // return 1; |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
551 | //} |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
552 | if(res->iscollection) { |
414
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
553 | return 1; |
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
554 | } |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
555 | |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
556 | DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
557 | CxList *res_tags = parse_dav_xml_taglist(tagsprop); |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
558 | |
397
ddda42712f39
fixes tag filter evaluation not respecting mode for subfilter combination
Mike Becker <universe@uap-core.de>
parents:
396
diff
changeset
|
559 | int ret = matches_tagfilter(res_tags, tagfilter); |
390
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
389
diff
changeset
|
560 | |
852 | 561 | cxListFree(res_tags); |
390
26998dc980f9
adds tag filter evaluation functions
Mike Becker <universe@uap-core.de>
parents:
389
diff
changeset
|
562 | |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
563 | return ret; |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
564 | } |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
565 | |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
566 | static int localres_matches_tags( |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
567 | SyncDirectory *dir, |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
568 | LocalResource *res, |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
569 | SyncTagFilter *tagfilter) |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
570 | { |
415
6e1861e8262c
check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
571 | 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
|
572 | return 1; |
6e1861e8262c
check tagfilter scope after checking tagfilter existence
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
414
diff
changeset
|
573 | } |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
574 | //int scope = res->isdirectory ? |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
575 | // DAV_SYNC_TAGFILTER_SCOPE_COLLECTION |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
576 | // : DAV_SYNC_TAGFILTER_SCOPE_RESOURCE; |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
577 | //if((tagfilter->scope & scope) != scope) { |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
578 | // return 1; |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
579 | //} |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
580 | if(res->isdirectory) { |
414
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
581 | return 1; |
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
582 | } |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
583 | |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
584 | DavBool changed = 0; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
585 | CxList *res_tags = sync_get_file_tags(dir, res, &changed, NULL); |
767
f4acc783f25e
fix tag filter crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
766
diff
changeset
|
586 | if(!res_tags) { |
f4acc783f25e
fix tag filter crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
766
diff
changeset
|
587 | res_tags = cxEmptyList; |
f4acc783f25e
fix tag filter crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
766
diff
changeset
|
588 | } |
389
fe855ce911f9
introduces SyncTagFilter type which for now implements the old tag list filter
Mike Becker <universe@uap-core.de>
parents:
386
diff
changeset
|
589 | |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
590 | int ret = matches_tagfilter(res_tags, tagfilter); |
852 | 591 | cxListFree(res_tags); |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
592 | return ret; |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
593 | } |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
594 | |
760
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
595 | static int localres_cmp_path(LocalResource *a, LocalResource *b, void *n) { |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
596 | return strcmp(a->path, b->path); |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
597 | } |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
598 | |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
599 | static int localres_cmp_path_desc(LocalResource *a, LocalResource *b, void *n) { |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
600 | return -strcmp(a->path, b->path); |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
601 | } |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
602 | |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
603 | static DavSession* create_session(CmdArgs *a, DavContext *davctx, DavCfgRepository *repo, char *collection) { |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
604 | int flags = dav_repository_get_flags(repo); |
497
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
605 | DavBool find_collection = TRUE; |
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
606 | if((flags & DAV_SESSION_DECRYPT_NAME) != DAV_SESSION_DECRYPT_NAME) { |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
607 | char *url = util_concat_path(repo->url.value.ptr, collection); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
608 | dav_repository_set_url(get_config(), repo, cx_str(url)); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
609 | free(url); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
610 | collection = NULL; |
497
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
611 | find_collection = FALSE; |
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
612 | } |
502
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
613 | 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
|
614 | // 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
|
615 | // 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
|
616 | // the base url |
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
617 | find_collection = FALSE; |
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
618 | } |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
619 | |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
620 | DavSession *sn = connect_to_repo(davctx, repo, collection, request_auth, a); |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
621 | |
497
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
622 | sn->flags = flags; |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
623 | sn->key = dav_context_get_key(davctx, repo->default_key.value.ptr); |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
624 | curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
625 | curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
626 | if(repo->cert.value.ptr) { |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
627 | curl_easy_setopt(sn->handle, CURLOPT_CAPATH, repo->cert.value.ptr); |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
628 | } |
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
629 | if(!repo->verification.value) { |
199
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
630 | curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYPEER, 0); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
631 | curl_easy_setopt(sn->handle, CURLOPT_SSL_VERIFYHOST, 0); |
f448fc8c9191
enabled cert verification
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
198
diff
changeset
|
632 | } |
497
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
633 | |
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
634 | if(find_collection) { |
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
635 | 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
|
636 | 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
|
637 | // 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
|
638 | // 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
|
639 | // and we can't handle it here |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
640 | char *newurl = util_concat_path(repo->url.value.ptr, util_resource_name(col->href)); |
497
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
641 | 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
|
642 | free(newurl); |
411bd1098175
fixes DavSession creation in dav-sync with enabled encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
495
diff
changeset
|
643 | } |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
644 | |
73
41e88442ad4e
ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
645 | return sn; |
41e88442ad4e
ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
646 | } |
41e88442ad4e
ssl version is now configurable
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
647 | |
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
|
648 | 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
|
649 | 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
|
650 | 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
|
651 | 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
|
652 | 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
|
653 | 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
|
654 | } |
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
|
655 | 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
|
656 | 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
|
657 | 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
|
658 | } |
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
|
659 | 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
|
660 | 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
|
661 | } |
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
|
662 | 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
|
663 | } |
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
|
664 | |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
665 | static void localres_keep(SyncDatabase *db, const char *path) { |
852 | 666 | LocalResource *local = NULL; |
667 | cxMapRemoveAndGet(db->resources, cx_hash_key_str(path), &local); | |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
668 | if(local) { |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
669 | local->keep = TRUE; |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
670 | } |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
671 | } |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
672 | |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
673 | static int xattr_filter(const char *name, SyncDirectory *dir) { |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
674 | // exclude tag xattr |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
675 | if( |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
676 | dir->tagconfig && |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
677 | dir->tagconfig->store == TAG_STORE_XATTR && |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
678 | !strcmp(dir->tagconfig->xattr_name, name)) |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
679 | { |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
680 | return 0; |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
681 | } |
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
682 | return 1; |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
683 | } |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
684 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
685 | void res2map(DavResource *root, CxMap *map) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
686 | CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
687 | cxListInsert(stack, 0, root->children); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
688 | while(cxListSize(stack) > 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
689 | DavResource *res = cxListAt(stack, 0); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
690 | cxListRemove(stack, 0); |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
691 | |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
692 | while(res) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
693 | cxMapPut(map, cx_hash_key_str(res->path), res); |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
694 | |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
695 | if(res->children) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
696 | cxListInsert(stack, 0, res->children); |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
697 | } |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
698 | res = res->next; |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
699 | } |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
700 | } |
852 | 701 | cxListFree(stack); |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
702 | } |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
703 | |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
704 | static CxHashKey resource_path_key(DavResource *res) { |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
705 | CxHashKey key = { NULL, 0, 0 }; |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
706 | if(res && res->path) { |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
707 | cxstring res_path = cx_str(res->path); |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
708 | if(res_path.length > 0 && res_path.ptr[res_path.length-1] == '/') { |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
709 | res_path.length--; |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
710 | } |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
711 | key = cx_hash_key(res_path.ptr, res_path.length); |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
712 | } |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
713 | return key; |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
714 | } |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
715 | |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
716 | int cmd_pull(CmdArgs *a, DavBool incoming) { |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717 | if(a->argc != 1) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718 | 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
|
719 | return -1; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | } |
392
4853fbad5014
adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents:
391
diff
changeset
|
721 | // 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
|
722 | SyncTagFilter* tagfilter = parse_tagfilter_string( |
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
723 | 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
|
724 | if (!tagfilter) { |
4853fbad5014
adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents:
391
diff
changeset
|
725 | 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
|
726 | return -1; |
4853fbad5014
adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents:
391
diff
changeset
|
727 | } |
395
b491d207ee16
fixes whitespace handling and error detection for basic tag filters
Mike Becker <universe@uap-core.de>
parents:
394
diff
changeset
|
728 | // 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
|
729 | // 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
|
730 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
731 | SyncDirectory *dir = scfg_get_dir(a->argv[0]); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
732 | if(!dir) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
733 | fprintf(stderr, "Unknown sync dir: %s\n", a->argv[0]); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734 | return -1; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
735 | } |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
736 | if(scfg_check_dir(dir)) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
737 | return -1; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
738 | } |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
739 | if(logfile_open(dir)) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
740 | return -1; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
741 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | |
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
|
743 | 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
|
744 | 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
|
745 | 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
|
746 | 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
|
747 | } |
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
|
748 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
749 | DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(dir->repository)); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
750 | if(!repo) { |
495
52cbd310b881
fixes 'Unkown repository' error message in dav-sync
Mike Becker <universe@uap-core.de>
parents:
493
diff
changeset
|
751 | fprintf(stderr, "Unknown repository %s\n", dir->repository); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752 | return -1; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
753 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | |
49
c5759ac76c1b
dav-sync detects locally removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
755 | SyncDatabase *db = load_db(dir->database); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | if(!db) { |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757 | fprintf(stderr, "Cannot load database file: %s\n", dir->database); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
758 | return -1; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759 | } |
218
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
760 | remove_deleted_conflicts(dir, db); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
761 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
762 | CxMap *hashes = NULL; |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
763 | if(SYNC_HASHING(dir)) { |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
764 | hashes = create_hash_index(db); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
765 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
766 | |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
767 | DavSession *sn = create_session(a, ctx, repo, dir->collection); |
775 | 768 | cxMempoolRegister(sn->mp, db, (cx_destructor_func)destroy_db); |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
66
diff
changeset
|
769 | if (cmd_getoption(a, "verbose")) { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
66
diff
changeset
|
770 | 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
|
771 | curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
788
9b9420041d8e
add request/response body to verbose output / add DavSession logfunc
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
784
diff
changeset
|
772 | sn->logfunc = dav_verbose_log; |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
66
diff
changeset
|
773 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
775 | // lock repository |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
776 | char *locktokenfile = NULL; |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
777 | DavBool locked = FALSE; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
778 | DavResource *root = dav_resource_new(sn, "/"); |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
779 | root->iscollection = TRUE; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
780 | 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
|
781 | if(dav_lock_t(root, dir->lock_timeout)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
782 | log_resource_error(sn, "/"); |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
783 | dav_session_destroy(sn); |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
784 | log_error("Abort\n"); |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
785 | return -1; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
786 | } |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
787 | DavLock *lock = dav_get_lock(sn, "/"); |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
788 | if(lock) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
789 | log_printf("Lock-Token: %s\n", lock->token); |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
790 | } |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
791 | locked = TRUE; |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
792 | 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
|
793 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
794 | |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
795 | int ret = 0; |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
796 | DavResource *ls = dav_query(sn, "select D:getetag,idav:split,idav:status,`idav:content-hash`,idavprops:tags,idavprops:finfo,idavprops:xattributes,idavprops:link from / with depth = infinity"); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797 | if(!ls) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
798 | log_resource_error(sn, "/"); |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
799 | if(locked) { |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
800 | if(dav_unlock(root)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
801 | log_resource_error(sn, "/"); |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
802 | } else { |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
803 | locked = FALSE; |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
804 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
805 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
806 | |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
807 | log_error("Abort\n"); |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
808 | |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
809 | dav_session_destroy(sn); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
810 | // TODO: free |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
811 | return -1; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
812 | } |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
813 | if(!ls->iscollection) { |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
814 | 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
|
815 | if(locked) { |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
816 | if(dav_unlock(root)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
817 | log_resource_error(sn, "/"); |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
818 | } else { |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
819 | locked = FALSE; |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
820 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
821 | } |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
822 | // TODO: free |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
823 | 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
|
824 | |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
825 | if(!locked && locktokenfile) { |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
826 | remove(locktokenfile); |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
827 | } |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
828 | |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
829 | return -1; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
830 | } |
50
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
831 | |
402
babdf40dd22c
dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
400
diff
changeset
|
832 | 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
|
833 | |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
834 | int sync_success = 0; |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
835 | int sync_delete = 0; |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
836 | int sync_error = 0; |
561
5e6df4f502d3
harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents:
560
diff
changeset
|
837 | int sync_conflict = 0; |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
838 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
839 | CxList *res_modified = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
840 | CxList *res_new = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
763
fc24d1d1d695
fix dav-sync pull not storing finfo metadata correctly in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
762
diff
changeset
|
841 | CxList *res_moved = cxLinkedListCreateSimple(CX_STORE_POINTERS); // type: MovedFile* |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
842 | CxList *res_link = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
843 | CxList *res_conflict = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
844 | CxList *res_mkdir = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
845 | CxList *res_metadata = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
846 | CxList *res_broken = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
847 | CxMap *lres_removed = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 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
|
848 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
849 | //UcxMap *svrres = ucx_map_new(db->resources->count); |
749
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
850 | CxMap *dbres = mapClone(cxDefaultAllocator, db->resources, NULL, NULL); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
851 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
852 | CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
853 | cxListInsert(stack, 0, ls->children); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
854 | while(cxListSize(stack) > 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
855 | DavResource *res = cxListAt(stack, 0); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
856 | cxListRemove(stack, 0); |
49
c5759ac76c1b
dav-sync detects locally removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
857 | |
810
baf199df500e
don't store directories with a trailing path separator in the sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
799
diff
changeset
|
858 | while(res) { |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
859 | DavBool res_filtered = FALSE; |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
860 | if (res_matches_dir_filter(dir, res->path)) { |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
861 | res_filtered = TRUE; |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
862 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
863 | CxIterator iter = cxListIterator(dir->filter.tags); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
864 | cx_foreach(SyncTagFilter *, tf, iter) { |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
865 | if(!res_matches_tags(res, tf)) { |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
866 | res_filtered = TRUE; |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
867 | break; |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
868 | } |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
869 | } |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
870 | } |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
871 | if(res_filtered) { |
402
babdf40dd22c
dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
400
diff
changeset
|
872 | // 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
|
873 | localres_keep(db, res->path); |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
874 | res = res->next; |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
875 | continue; |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
876 | } |
402
babdf40dd22c
dav-sync pull applies config tag filter now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
400
diff
changeset
|
877 | |
392
4853fbad5014
adds error message for invalid tag filter syntax
Mike Becker <universe@uap-core.de>
parents:
391
diff
changeset
|
878 | 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
|
879 | if(!remove_file) { |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
880 | localres_keep(db, res->path); |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
881 | } |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
882 | res = res->next; |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
883 | continue; |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
884 | } |
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
885 | |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
886 | 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
|
887 | if(status && !strcmp(status, "broken")) { |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
888 | localres_keep(db, res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
889 | cxListAdd(res_broken, res); |
759
a3e35cae098b
fix dav-sync push crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
750
diff
changeset
|
890 | res = res->next; |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
891 | continue; |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
892 | } |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
893 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
894 | // 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
|
895 | 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
|
896 | switch(change) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
897 | 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
|
898 | case REMOTE_CHANGE_MODIFIED: { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
899 | cxListAdd(res_modified, res); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
900 | break; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
901 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
902 | case REMOTE_CHANGE_NEW: { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
903 | cxListAdd(res_new, res); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
904 | break; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
905 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
906 | 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
|
907 | case REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED: { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
908 | cxListAdd(res_conflict, res); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
909 | break; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
910 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
911 | case REMOTE_CHANGE_METADATA: { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
912 | cxListAdd(res_metadata, res); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
913 | break; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
914 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
915 | case REMOTE_CHANGE_MKDIR: { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
916 | cxListAdd(res_mkdir, res); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
917 | break; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
918 | } |
580
caf23cf7f96d
separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
579
diff
changeset
|
919 | case REMOTE_CHANGE_LINK: { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
920 | cxListAdd(res_link, res); |
580
caf23cf7f96d
separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
579
diff
changeset
|
921 | break; |
caf23cf7f96d
separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
579
diff
changeset
|
922 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
923 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
924 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
925 | // 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
|
926 | // 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
|
927 | // on the server |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
928 | cxMapRemove(dbres, resource_path_key(res)); |
272
b321a3be0a38
fixes unnecessary mkcol in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
257
diff
changeset
|
929 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
930 | if(!dav_get_property_ns(res, DAV_NS, "split") && res->children) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
931 | cxListInsert(stack, 0, res->children); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
932 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | res = res->next; |
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 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
936 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
937 | // find deleted resources |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
938 | // 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
|
939 | // and will replace the current db->resources map later |
749
bbadf84cfc2d
fix dav-sync crash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
747
diff
changeset
|
940 | CxIterator i = mapIteratorValues(dbres); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
941 | cx_foreach(LocalResource *, local, i) { |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
942 | if (res_matches_dir_filter(dir, local->path)) { |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
943 | continue; |
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
944 | } |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
945 | if(!local->keep) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
946 | cxMapPut(lres_removed, cx_hash_key_str(local->path), local); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
947 | |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
948 | // TODO: what is the meaning of this code? without overflow the condition is never true |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
949 | // if(lres_removed->size > lres_removed->size * 2) { |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
950 | // cxMapRehash(lres_removed); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
951 | // } |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
952 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
953 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
954 | |
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
|
955 | // |
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
|
956 | // 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
|
957 | // |
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
|
958 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
959 | // the first thing we need are all directories to put the files in |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
960 | i = cxListIterator(res_mkdir); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
961 | cx_foreach(DavResource *, res, i) { |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
962 | if(sync_get_collection(a, dir, res, db)) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
963 | sync_error++; |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
964 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
965 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
966 | |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
967 | // we need a map for all conflicts for fast lookups |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
968 | CxMap *conflicts = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, cxListSize(res_conflict)+16); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
969 | i = cxListIterator(res_conflict); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
970 | cx_foreach(DavResource *, res, i) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
971 | cxMapPut(conflicts, cx_hash_key_str(res->path), res); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
972 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
973 | |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
974 | if(SYNC_HASHING(dir)) { |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
975 | // check for moved/copied files |
608
3e4c0285a868
fix build on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
607
diff
changeset
|
976 | SYS_STAT s; |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
977 | CxIterator mut_iter = cxListMutIterator(res_new); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
978 | cx_foreach(DavResource *, res, mut_iter) { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
979 | if(dav_get_property_ns(res, DAV_PROPS_NS, "link")) { |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
980 | continue; |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
981 | } |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
982 | |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
983 | 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
|
984 | if(!hash) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
985 | continue; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
986 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
987 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
988 | LocalResource *local = cxMapGet(hashes, cx_hash_key_str(hash)); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
989 | if(!local) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
990 | continue; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
991 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
992 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
993 | char *local_path = util_concat_path(dir->path, local_resource_path(local)); |
608
3e4c0285a868
fix build on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
607
diff
changeset
|
994 | int staterr = sys_stat(local_path, &s); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
995 | free(local_path); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
996 | if(staterr) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
997 | // 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
|
998 | continue; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
999 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1000 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1001 | MovedFile *mf = malloc(sizeof(MovedFile)); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1002 | mf->content = local; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1003 | mf->resource = res; |
852 | 1004 | if(cxMapRemove(lres_removed, cx_hash_key_str(local->path))) { |
1005 | mf->copy = TRUE; | |
1006 | } else { | |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1007 | mf->copy = FALSE; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1008 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1009 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1010 | cxListAdd(res_moved, mf); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1011 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1012 | // remove item from res_new |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1013 | cxIteratorFlagRemoval(mut_iter); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1014 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1015 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1016 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1017 | // do copy/move operations |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1018 | i = cxListIterator(res_moved); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1019 | cx_foreach(MovedFile *, mf, i) { |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1020 | if(sync_shutdown) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1021 | break; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1022 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1023 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1024 | DavBool issplit = dav_get_property_ns(mf->resource, DAV_NS, "split") ? 1 : 0; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1025 | if(cxMapGet(conflicts, cx_hash_key_str(mf->resource->path))) { |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1026 | 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
|
1027 | sync_conflict++; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1028 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1029 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1030 | // move file |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1031 | 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
|
1032 | 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
|
1033 | sync_error++; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1034 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1035 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1036 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1037 | // download all new, modified and conflict files |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1038 | for(int n=0;n<4;n++) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1039 | CxList *list; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1040 | if(n == 0) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1041 | list = res_new; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1042 | } else if(n == 1) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1043 | list = res_modified; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1044 | } else if(n == 2) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1045 | list = res_conflict; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1046 | } else { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1047 | list = res_link; |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1048 | } |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1049 | CxIterator iter = cxListIterator(list); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1050 | cx_foreach(DavResource *, res, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1051 | if(sync_shutdown) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1052 | break; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1053 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1054 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1055 | DavBool issplit = dav_get_property_ns(res, DAV_NS, "split") ? 1 : 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1056 | if(cxMapGet(conflicts, cx_hash_key_str(res->path))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1057 | rename_conflict_file(dir, db, res->path, issplit); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1058 | sync_conflict++; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1059 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1060 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1061 | // download the resource |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1062 | if(sync_get_resource(a, dir, res->path, res, db, TRUE, &sync_success)) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1063 | fprintf(stderr, "resource download failed: %s\n", res->path); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1064 | sync_error++; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1065 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1066 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1067 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1068 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1069 | // update metadata |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1070 | i = cxListIterator(res_metadata); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1071 | cx_foreach(DavResource *, res, i) { |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1072 | if(sync_shutdown) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1073 | break; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1074 | } |
302
395763c0ee69
adds SIGINT handler to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
299
diff
changeset
|
1075 | |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1076 | LocalResource *local = cxMapGet(db->resources, resource_path_key(res)); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1077 | if(local) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1078 | log_printf("update: %s\n", res->path); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1079 | char *res_path = resource_local_path(res); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1080 | char *local_path = create_local_path(dir, res->path); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1081 | free(res_path); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1082 | 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
|
1083 | 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
|
1084 | sync_error++; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1085 | } else { |
608
3e4c0285a868
fix build on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
607
diff
changeset
|
1086 | SYS_STAT s; |
3e4c0285a868
fix build on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
607
diff
changeset
|
1087 | if(sys_stat(local_path, &s)) { |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1088 | 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
|
1089 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1090 | 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
|
1091 | sync_success++; |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1092 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1093 | free(local_path); |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1094 | } else { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1095 | // 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
|
1096 | fprintf(stderr, |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1097 | "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
|
1098 | res->path); |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1099 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1100 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1101 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1102 | CxList *rmdirs = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_pathlen_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1103 | i = cxMapIteratorValues(lres_removed); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1104 | cx_foreach(LocalResource *, removed_res, i) { |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1105 | if(sync_shutdown) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1106 | break; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1107 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1108 | |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1109 | int rmlocal_ret = sync_remove_local_resource(dir, removed_res); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1110 | if(rmlocal_ret == -1) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1111 | cxListAdd(rmdirs, removed_res); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1112 | } else if(rmlocal_ret == 0) { |
852 | 1113 | LocalResource *local = NULL; |
1114 | cxMapRemoveAndGet(db->resources, cx_hash_key_str(removed_res->path), &local); | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1115 | if(local) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1116 | 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
|
1117 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1118 | sync_delete++; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1119 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1120 | } |
852 | 1121 | cxMapFree(lres_removed); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1122 | |
626
2f735b0e87fa
fix order of dir deletions in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1123 | // sort dir list, we need to delete dirs with higher depth first |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1124 | cxListSort(rmdirs); |
626
2f735b0e87fa
fix order of dir deletions in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1125 | // delete dirs |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1126 | i = cxListIterator(rmdirs); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1127 | cx_foreach(LocalResource *, local_dir, i) { |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1128 | if(!sync_remove_local_directory(dir, local_dir)) { |
626
2f735b0e87fa
fix order of dir deletions in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
621
diff
changeset
|
1129 | // dir successfully removed, now remove the related db entry |
852 | 1130 | LocalResource *local = NULL; |
1131 | cxMapRemoveAndGet(db->resources, cx_hash_key_str(local_dir->path), &local); | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1132 | if(local) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1133 | 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
|
1134 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1135 | sync_delete++; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1136 | } |
50
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1137 | } |
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1138 | |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1139 | // unlock repository |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1140 | if(locked) { |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1141 | if(dav_unlock(root)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
1142 | log_resource_error(sn, "/"); |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1143 | ret = -1; |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
1144 | } else { |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
1145 | locked = FALSE; |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1146 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1147 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1148 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1149 | // store db |
521
c5bbae4b3cca
extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
516
diff
changeset
|
1150 | 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
|
1151 | 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
|
1152 | ret = -2; |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
1153 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1154 | |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
1155 | // cleanup |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1156 | dav_session_destroy(sn); |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1157 | |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
1158 | if(!locked && locktokenfile) { |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
1159 | remove(locktokenfile); |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
1160 | } |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
1161 | |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1162 | // Report |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
1163 | if(ret != -2) { |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1164 | char *str_success = sync_success == 1 ? "file" : "files"; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1165 | char *str_delete = sync_delete == 1 ? "file" : "files"; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1166 | 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
|
1167 | char *str_conflict = sync_conflict == 1 ? "conflict" : "conflicts"; |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1168 | log_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
|
1169 | sync_success, str_success, |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1170 | sync_delete,str_delete, |
561
5e6df4f502d3
harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents:
560
diff
changeset
|
1171 | sync_conflict, str_conflict, |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1172 | sync_error, str_error); |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1173 | } |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1174 | |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
1175 | return ret; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1176 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1177 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1178 | 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
|
1179 | CmdArgs *a, |
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
1180 | DavResource *res, |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1181 | SyncDirectory *dir, |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1182 | SyncDatabase *db) |
502
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
1183 | { |
686
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1184 | DavBool update_db = FALSE; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1185 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1186 | 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
|
1187 | if(!etag) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1188 | 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
|
1189 | 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
|
1190 | } |
649
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1191 | char *hash = sync_get_content_hash(res); |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1192 | |
543
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
1193 | 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
|
1194 | if(issplit) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1195 | util_remove_trailing_pathseparator(res->path); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1196 | } |
616
0b61755f2852
add missing isdirectory tag in db on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
615
diff
changeset
|
1197 | DavBool iscollection = res->iscollection && !issplit; |
543
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
1198 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1199 | 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
|
1200 | 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
|
1201 | |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1202 | LocalResource *local = cxMapGet(db->resources, resource_path_key(res)); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1203 | 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
|
1204 | |
580
caf23cf7f96d
separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
579
diff
changeset
|
1205 | char *link = SYNC_SYMLINK(dir) ? |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
1206 | dav_get_string_property_ns(res, DAV_PROPS_NS, "link") : NULL; |
580
caf23cf7f96d
separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
579
diff
changeset
|
1207 | |
502
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
1208 | 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
|
1209 | DavBool exists = 1; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1210 | 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
|
1211 | if(errno != ENOENT) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1212 | 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
|
1213 | free(local_path); |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1214 | 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
|
1215 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1216 | exists = 0; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1217 | } |
502
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
1218 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1219 | RemoteChangeType ret = REMOTE_NO_CHANGE; |
616
0b61755f2852
add missing isdirectory tag in db on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
615
diff
changeset
|
1220 | if(iscollection) { |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1221 | if(!exists) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1222 | ret = REMOTE_CHANGE_MKDIR; |
616
0b61755f2852
add missing isdirectory tag in db on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
615
diff
changeset
|
1223 | } else if(local && S_ISDIR(s.st_mode)) { |
0b61755f2852
add missing isdirectory tag in db on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
615
diff
changeset
|
1224 | local->isdirectory = 1; // make sure isdirectory is set |
0b61755f2852
add missing isdirectory tag in db on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
615
diff
changeset
|
1225 | } else { |
617
1c995e93bf40
change error handling in case of file/folder conflict
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
616
diff
changeset
|
1226 | // set change to REMOTE_CHANGE_MKDIR, which will fail later |
1c995e93bf40
change error handling in case of file/folder conflict
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
616
diff
changeset
|
1227 | ret = REMOTE_CHANGE_MKDIR; |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1228 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1229 | } else if(local) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1230 | DavBool nochange = FALSE; |
580
caf23cf7f96d
separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
579
diff
changeset
|
1231 | 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
|
1232 | 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
|
1233 | nochange = TRUE; |
686
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1234 | |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1235 | if(local->link_target) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1236 | LocalResource *local2 = local_resource_new(dir, db, local->path); |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1237 | if(type == REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED && nullstrcmp(local->link_target, local2->link_target)) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1238 | ret = REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1239 | } |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1240 | local_resource_free(local2); |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1241 | |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1242 | if(!nullstrcmp(link, local->link_target)) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1243 | ret = REMOTE_NO_CHANGE; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1244 | update_db = TRUE; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1245 | } |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1246 | } |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1247 | } else if(issplit && local->hash && hash) { |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1248 | if(!strcmp(local->hash, hash)) { |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1249 | // resource is already up-to-date on the client |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1250 | nochange = TRUE; |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1251 | } |
543
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
1252 | } else if(local->etag) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1253 | cxstring e = cx_str(etag); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1254 | if(cx_strprefix(e, CX_STR("W/"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1255 | e = cx_strsubs(e, 2); |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1256 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1257 | 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
|
1258 | // 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
|
1259 | nochange = TRUE; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1260 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1261 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1262 | |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1263 | if(!nochange) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1264 | 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
|
1265 | 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
|
1266 | } |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1267 | ret = type; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1268 | } |
580
caf23cf7f96d
separate link changes from normal changes and create links after downloads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
579
diff
changeset
|
1269 | } else if(link) { |
686
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1270 | // new file is a link |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1271 | ret = REMOTE_CHANGE_LINK; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1272 | |
685
487645580b5e
add symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
681
diff
changeset
|
1273 | if(exists && type == REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED) { |
686
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1274 | // a file with the same name already exists |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1275 | // if it is a link, compare the targets |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1276 | LocalResource *local2 = local_resource_new(dir, db, res->path); |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1277 | if(local2) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1278 | if(local2->link_target) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1279 | if(strcmp(link, local2->link_target)) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1280 | ret = REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1281 | } |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1282 | } else { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1283 | ret = REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1284 | } |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1285 | |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1286 | local_resource_free(local2); |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1287 | } |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1288 | } |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1289 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1290 | } else if(exists) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1291 | ret = type; |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1292 | } else { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1293 | 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
|
1294 | } |
649
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1295 | |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1296 | // if hashing is enabled we can compare the hash of the remote file |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1297 | // with the local file to test if a file is really modified |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1298 | char *update_hash = NULL; |
649
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1299 | if (!iscollection && |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1300 | !link && |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1301 | (ret == REMOTE_CHANGE_MODIFIED || ret == REMOTE_CHANGE_CONFLICT_LOCAL_MODIFIED) && |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1302 | exists && |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1303 | hash && |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1304 | !dir->pull_skip_hashing) |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1305 | { |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1306 | // because rehashing a file is slow, there is a config element for |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1307 | // disabling this (pull-skip-hashing) |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1308 | char *local_hash = util_file_hash(local_path); |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1309 | if(local_hash) { |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1310 | if(!strcmp(hash, local_hash)) { |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1311 | ret = REMOTE_NO_CHANGE; |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1312 | update_db = TRUE; |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1313 | update_hash = local_hash; |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1314 | |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1315 | // if local already exists, update the hash here |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1316 | // because it is possible that there are metadata updates |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1317 | // and in this case the db will updated later and needs |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1318 | // the current hash |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1319 | if(local) { |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1320 | if(local->hash) { |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1321 | free(local->hash); |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1322 | } |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1323 | local->hash = local_hash; |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1324 | } |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1325 | } else { |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1326 | free(local_hash); |
649
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1327 | } |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1328 | } |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1329 | } |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1330 | |
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
1331 | // if a file is not modified, check if the metadata has changed |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1332 | 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
|
1333 | // 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
|
1334 | if(dir->tagconfig) { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
1335 | DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1336 | CxList *remote_tags = NULL; |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1337 | if(tagsprop) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1338 | 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
|
1339 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1340 | 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
|
1341 | 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
|
1342 | ret = REMOTE_CHANGE_METADATA; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1343 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1344 | if(remote_hash) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1345 | free(remote_hash); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1346 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1347 | 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
|
1348 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1349 | if(ret == REMOTE_CHANGE_METADATA) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1350 | break; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1351 | } |
524
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
523
diff
changeset
|
1352 | } |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
523
diff
changeset
|
1353 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1354 | // 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
|
1355 | if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
1356 | DavXmlNode *xattr = dav_get_property_ns(res, DAV_PROPS_NS, "xattributes"); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1357 | 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
|
1358 | 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
|
1359 | ret = REMOTE_CHANGE_METADATA; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1360 | break; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1361 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1362 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1363 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1364 | // check if finfo has changed |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
1365 | DavXmlNode *finfo = dav_get_property_ns(res, DAV_PROPS_NS, "finfo"); |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
536
diff
changeset
|
1366 | 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
|
1367 | FileInfo f; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1368 | finfo_get_values(finfo, &f); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1369 | 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
|
1370 | ret = REMOTE_CHANGE_METADATA; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1371 | break; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1372 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1373 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1374 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1375 | break; |
524
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
523
diff
changeset
|
1376 | } |
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
523
diff
changeset
|
1377 | |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1378 | // if update_db is set, a file was modified on the server, but we already |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1379 | // have the file content, but we need to update the db |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1380 | if(ret == REMOTE_NO_CHANGE && update_db) { |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1381 | if(!local) { |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1382 | local = calloc(1, sizeof(LocalResource)); |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1383 | local->path = strdup(res->path); |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1384 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1385 | cxMapPut(db->resources, cx_hash_key_str(local->path), local); |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1386 | } |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1387 | |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1388 | // update local res |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1389 | SYS_STAT statdata; |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1390 | if(!sys_stat(local_path, &statdata)) { |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1391 | sync_set_metadata_from_stat(local, &statdata); |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1392 | } else { |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1393 | fprintf(stderr, "stat failed for file: %s : %s", local_path, strerror(errno)); |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1394 | } |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1395 | local_resource_set_etag(local, etag); |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1396 | if(!local->hash) { |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1397 | local->hash = update_hash; |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1398 | } // else: hash already updated |
686
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1399 | if(link) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1400 | nullfree(local->link_target); |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1401 | local->link_target = link; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
1402 | } |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1403 | } |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
1404 | |
502
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
1405 | free(local_path); |
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
1406 | return ret; |
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
1407 | } |
a23fedac340c
fixes DavSession creation in dav-sync when using root collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
501
diff
changeset
|
1408 | |
608
3e4c0285a868
fix build on windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
607
diff
changeset
|
1409 | void sync_set_metadata_from_stat(LocalResource *local, SYS_STAT *s) { |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1410 | local->last_modified = s->st_mtime; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1411 | local->mode = s->st_mode & 07777; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1412 | local->uid = s->st_uid; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1413 | local->gid = s->st_gid; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1414 | local->size = s->st_size; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1415 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1416 | |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1417 | #ifdef _WIN32 |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1418 | #define fseeko fseek |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1419 | #define ftello ftell |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1420 | #endif |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1421 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1422 | static CxList* sync_download_changed_parts( |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1423 | DavResource *res, |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1424 | LocalResource *local, |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1425 | FILE *out, |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1426 | size_t blocksize, |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1427 | uint64_t *blockcount, |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1428 | int64_t *truncate_file, |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1429 | int *err) |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1430 | { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1431 | CxList *updates = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
1432 | cxDefineDestructor(updates, filepart_free); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1433 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1434 | 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
|
1435 | fseeko(out, 0, SEEK_END); |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1436 | off_t end = ftello(out); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1437 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1438 | int error = 0; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1439 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1440 | CxBuffer *buf = cxBufferCreate(NULL, blocksize, cxDefaultAllocator, 0); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1441 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1442 | int64_t maxsize = -1; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1443 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1444 | DavResource *part = res->children; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1445 | uint64_t i = 0; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1446 | while(part) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1447 | char *res_name = part->name; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1448 | 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
|
1449 | res_name++; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1450 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1451 | uint64_t partnum = 0; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1452 | if(util_strtouint(res_name, &partnum)) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1453 | DavBool download_part = FALSE; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1454 | 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
|
1455 | if(partnum >= local_numparts) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1456 | // new part |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1457 | download_part = TRUE; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1458 | } else { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1459 | 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
|
1460 | if(etag) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1461 | if(nullstrcmp(etag, p.etag)) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1462 | download_part = TRUE; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1463 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1464 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1465 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1466 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1467 | uint64_t offset; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1468 | 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
|
1469 | if(mul_err || offset >= INT64_MAX) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1470 | error = 1; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1471 | 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
|
1472 | break; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1473 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1474 | |
546
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1475 | int64_t block_end = 0; |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1476 | if(download_part) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1477 | if(fseeko(out, offset, SEEK_SET)) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1478 | error = 1; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1479 | 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
|
1480 | break; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1481 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1482 | buf->pos = 0; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1483 | buf->size = 0; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1484 | if(dav_get_content(part, buf,(dav_write_func)cxBufferWrite)) { |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1485 | 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
|
1486 | error = 1; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1487 | break; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1488 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1489 | 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
|
1490 | perror("write"); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1491 | error = 1; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1492 | break; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1493 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1494 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1495 | FilePart *update = calloc(1, sizeof(FilePart)); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1496 | update->block = partnum; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1497 | update->etag = etag ? strdup(etag) : NULL; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1498 | update->hash = dav_create_hash(buf->space, buf->size); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1499 | cxListAdd(updates, update); |
546
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1500 | |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1501 | block_end = offset+buf->size; |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1502 | } else { |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1503 | if(offset+blocksize > end) { |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1504 | // 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
|
1505 | // 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
|
1506 | block_end = end; |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1507 | } else { |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1508 | block_end = offset+blocksize; |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1509 | } |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1510 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1511 | |
546
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1512 | if(block_end > maxsize) { |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1513 | maxsize = block_end; |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1514 | } |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1515 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1516 | i++; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1517 | } // 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
|
1518 | part = part->next; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1519 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1520 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1521 | cxBufferFree(buf); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1522 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1523 | if(error) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1524 | *err = 1; |
852 | 1525 | cxListFree(updates); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1526 | return NULL; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1527 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1528 | |
546
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1529 | if(maxsize < end) { |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1530 | *truncate_file = maxsize; |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1531 | } else { |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1532 | *truncate_file = -1; |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1533 | } |
33e312dd851d
truncate splitted file to correct size on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
545
diff
changeset
|
1534 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1535 | *err = 0; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1536 | *blockcount = i; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1537 | return updates; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1538 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1539 | |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1540 | 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
|
1541 | FILE *in = sys_fopen(from, "rb"); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1542 | if(!in) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1543 | return 1; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1544 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1545 | FILE *out = sys_fopen(to, "wb"); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1546 | if(!out) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1547 | fclose(in); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1548 | return 1; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1549 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1550 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1551 | cx_stream_copy(in, out, (cx_read_func)fread, (cx_write_func)fwrite); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1552 | fclose(in); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1553 | fclose(out); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1554 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1555 | return 0; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1556 | } |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1557 | |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1558 | 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
|
1559 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1560 | int sync_move_resource( |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1561 | CmdArgs *a, |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1562 | SyncDirectory *dir, |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1563 | DavResource *res, |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1564 | LocalResource *content, |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1565 | DavBool copy, |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1566 | SyncDatabase *db, |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1567 | int *counter) |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1568 | { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1569 | 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
|
1570 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1571 | char *new_path = util_concat_path(dir->path, res->path); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1572 | char *old_path = util_concat_path(dir->path, local_resource_path(content)); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1573 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1574 | log_printf("%s: %s -> %s\n", copy?"copy":"move", content->path, res->path); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1575 | if(fn(old_path, new_path)) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1576 | free(new_path); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1577 | free(old_path); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1578 | return 1; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1579 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1580 | (*counter)++; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1581 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1582 | 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
|
1583 | 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
|
1584 | |
569
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1585 | LocalResource *local = NULL; |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1586 | if(copy) { |
675
a8117c4feaad
fix sync_store_metadata
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
672
diff
changeset
|
1587 | // TODO: maybe we should not copy the whole resource |
a8117c4feaad
fix sync_store_metadata
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
672
diff
changeset
|
1588 | // with all metadata hashes |
569
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1589 | 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
|
1590 | } else { |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1591 | // reuse previous LocalResource (content) |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1592 | // remove it from db->resources, change path and put it back |
852 | 1593 | local = NULL; |
1594 | cxMapRemoveAndGet(db->resources, cx_hash_key_str(content->path), &local); | |
569
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1595 | if(!local) { |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1596 | // 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
|
1597 | local = content; |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1598 | } |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1599 | free(content->path); |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1600 | local->path = strdup(res->path); |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
1601 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1602 | cxMapPut(db->resources, cx_hash_key_str(local->path), local); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1603 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1604 | 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
|
1605 | 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
|
1606 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1607 | |
621
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
1608 | // dont free local->etag, because local_resource_set_etag will do that |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
1609 | |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1610 | if(local->hash) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1611 | free(local->hash); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1612 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1613 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1614 | SYS_STAT s; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1615 | if(sys_stat(new_path, &s)) { |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1616 | fprintf(stderr, |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1617 | "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
|
1618 | } |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1619 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1620 | // set metadata from stat |
621
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
1621 | local_resource_set_etag(local, etag); |
567
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1622 | local->hash = nullstrdup(content_hash); |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1623 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1624 | 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
|
1625 | local->skipped = FALSE; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1626 | |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1627 | return 0; |
b0ce8b27978b
implement copy/move for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
566
diff
changeset
|
1628 | } |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1629 | |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1630 | int sync_get_resource( |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1631 | CmdArgs *a, |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1632 | SyncDirectory *dir, |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
1633 | const char *path, |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1634 | DavResource *res, |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1635 | SyncDatabase *db, |
679
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1636 | DavBool update_db, |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1637 | int *counter) |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1638 | { |
581
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1639 | char *link = SYNC_SYMLINK(dir) ? |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
1640 | dav_get_string_property_ns(res, DAV_PROPS_NS, "link") : NULL; |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1641 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1642 | LocalResource *local = cxMapGet(db->resources, cx_hash_key_str(path)); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1643 | |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1644 | char *local_path; |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1645 | if(link) { |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1646 | char *res_path = resource_local_path(res); |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1647 | local_path = create_local_path(dir, res_path); |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1648 | free(res_path); |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1649 | } else { |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1650 | local_path = create_local_path(dir, path); |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1651 | } |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
1652 | |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
1653 | 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
|
1654 | SYS_STAT s; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
1655 | 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
|
1656 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1657 | 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
|
1658 | uint64_t blocksize = 0; |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1659 | DavBool issplit = FALSE; |
581
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1660 | if(blocksize_str && !link) { |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1661 | if(!util_strtouint(blocksize_str, &blocksize)) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1662 | 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
|
1663 | return 1; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1664 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1665 | issplit = TRUE; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1666 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1667 | CxList *part_updates = NULL; |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1668 | 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
|
1669 | char *content_hash = NULL; |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1670 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1671 | if(res->iscollection && !issplit) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1672 | // why are we here? |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1673 | return 0; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1674 | } |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1675 | |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1676 | int ret = 0; |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1677 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1678 | char *tmp_path = NULL; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1679 | FILE *out = NULL; |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1680 | if(!link) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1681 | if(!issplit) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1682 | tmp_path = create_tmp_download_path(local_path); |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1683 | if(!tmp_path) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1684 | 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
|
1685 | free(local_path); |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1686 | return -1; |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1687 | } |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1688 | out = sys_fopen(tmp_path , "wb"); |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1689 | } else { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1690 | out = sys_fopen(local_path, "r+b"); |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1691 | if(!out && errno == ENOENT) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1692 | out = sys_fopen(local_path, "wb"); |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1693 | } |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1694 | } |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1695 | if(!out) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1696 | 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
|
1697 | free(local_path); |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1698 | if(tmp_path) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1699 | free(tmp_path); |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1700 | } |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1701 | return -1; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1702 | } |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1703 | } |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1704 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1705 | int64_t truncate_file = -1; |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1706 | if(!link) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1707 | log_printf("get: %s\n", path); |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1708 | if(issplit) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1709 | 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
|
1710 | } else { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1711 | 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
|
1712 | } |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1713 | fclose(out); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1714 | } else { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1715 | log_printf("link: %s -> %s\n", path, link); |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1716 | if(sys_symlink(link, local_path)) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1717 | perror("symlink"); |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1718 | ret = 1; |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1719 | } |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1720 | } |
545
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1721 | |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
1722 | if(issplit || (SYNC_HASHING(dir) && !link)) { |
545
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1723 | if(truncate_file >= 0) { |
560
a816e805e5db
store origin of file conflicts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
559
diff
changeset
|
1724 | // only true if issplit is true |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1725 | if(sys_truncate(local_path, truncate_file)) { |
548
ab46acda1066
fixes truncate path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
1726 | perror("truncate"); |
ab46acda1066
fixes truncate path
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
1727 | } |
545
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1728 | } |
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1729 | |
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1730 | 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
|
1731 | if(res_hash) { |
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1732 | content_hash = res_hash; |
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1733 | } else { |
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1734 | 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
|
1735 | } |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1736 | } |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1737 | |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1738 | if(ret == 0) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1739 | (*counter)++; |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1740 | |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1741 | if(tmp_path) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1742 | if(dir->trash && dir->backuppull) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1743 | move_to_trash(dir, local_path); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1744 | } |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1745 | 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
|
1746 | fprintf( |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1747 | stderr, |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1748 | "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
|
1749 | tmp_path, |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1750 | local_path); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1751 | perror(""); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1752 | free(tmp_path); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1753 | free(local_path); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1754 | return -1; |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1755 | } |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
1756 | } |
679
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1757 | |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1758 | } else if(tmp_path) { |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1759 | if(sys_unlink(tmp_path)) { |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1760 | fprintf(stderr, "Cannot remove tmp file: %s\n", tmp_path); |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1761 | } |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1762 | } |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1763 | |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
1764 | if(update_db && ret == 0) { |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1765 | if(!local) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1766 | // new local resource |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1767 | local = calloc(1, sizeof(LocalResource)); |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
1768 | local->path = strdup(path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1769 | cxMapPut(db->resources, cx_hash_key_str(local->path), local); |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1770 | } |
543
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
1771 | |
2f85df8cd35e
fixes that pull downloads the history collection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
1772 | 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
|
1773 | 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
|
1774 | } |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1775 | |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1776 | if(local->etag) { |
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1777 | free(local->etag); |
581
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1778 | local->etag = NULL; |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1779 | } |
545
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1780 | if(local->hash) { |
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1781 | free(local->hash); |
581
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1782 | local->hash = NULL; |
545
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1783 | } |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1784 | if(local->link_target) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1785 | free(local->link_target); |
581
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1786 | local->link_target = NULL; |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1787 | } |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1788 | |
581
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1789 | stat_func statfn; |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1790 | if(link) { |
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1791 | local->link_target = strdup(link); |
581
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1792 | statfn = sys_lstat; |
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1793 | } else { |
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1794 | statfn = sys_stat; |
578
bb1e60fada74
create symlinks on pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
577
diff
changeset
|
1795 | } |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1796 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1797 | update_parts(local, part_updates, blockcount); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1798 | |
581
3f9a9c80a2d2
fix that symlink config was not used in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
580
diff
changeset
|
1799 | if(statfn(local_path, &s)) { |
547
4a249c645ae4
fixes that metadata is updated after stat in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
546
diff
changeset
|
1800 | fprintf(stderr, |
4a249c645ae4
fixes that metadata is updated after stat in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
546
diff
changeset
|
1801 | "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
|
1802 | } |
4a249c645ae4
fixes that metadata is updated after stat in sync_get_resource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
546
diff
changeset
|
1803 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1804 | // set metadata from stat |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1805 | if(!issplit) { |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1806 | local_resource_set_etag(local, etag); |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
1807 | } |
545
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1808 | if(content_hash) { |
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1809 | local->hash = content_hash; |
268157722a0e
store content hash for splitted resources in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
544
diff
changeset
|
1810 | } |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
1811 | 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
|
1812 | local->skipped = FALSE; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1813 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1814 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1815 | if(tmp_path) { |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1816 | free(tmp_path); |
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1817 | } |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1818 | free(local_path); |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1819 | return ret; |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1820 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1821 | |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1822 | int sync_get_collection( |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1823 | CmdArgs *a, |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1824 | SyncDirectory *dir, |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1825 | DavResource *res, |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1826 | SyncDatabase *db) |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1827 | { |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1828 | cxstring res_path = cx_str(res->path); |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1829 | if(res_path.length > 0 && res_path.ptr[res_path.length-1] == '/') { |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1830 | res_path.length--; |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1831 | } |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1832 | |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1833 | // TODO: use resource_local_path return value (necessary for creating links on windows) |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1834 | //char *res_path = resource_local_path(res); |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1835 | char *local_path = create_local_path(dir, res->path); |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1836 | //free(res_path); |
617
1c995e93bf40
change error handling in case of file/folder conflict
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
616
diff
changeset
|
1837 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1838 | log_printf("get: %s\n", res->path); |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1839 | // create directory |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1840 | // ignore error if it already exists |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1841 | if(sys_mkdir(local_path) && errno != EEXIST) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1842 | fprintf(stderr, |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1843 | "Cannot create directory %s: %s", |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1844 | local_path, strerror(errno)); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1845 | free(local_path); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1846 | return 1; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1847 | } |
617
1c995e93bf40
change error handling in case of file/folder conflict
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
616
diff
changeset
|
1848 | |
1c995e93bf40
change error handling in case of file/folder conflict
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
616
diff
changeset
|
1849 | // stat for getting metadata |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1850 | SYS_STAT s; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1851 | if(sys_stat(local_path, &s)) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1852 | fprintf(stderr, "Cannot stat directory %s: %s", local_path, strerror(errno)); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1853 | free(local_path); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1854 | return 1; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1855 | } |
617
1c995e93bf40
change error handling in case of file/folder conflict
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
616
diff
changeset
|
1856 | |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1857 | // if it doesn't exist in the db, create an entry for the dir |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1858 | LocalResource *local = cxMapGet(db->resources, cx_hash_key(res_path.ptr, res_path.length)); |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1859 | if(!local) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1860 | local = calloc(1, sizeof(LocalResource)); |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
1861 | local->path = cx_strdup(res_path).ptr; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1862 | cxMapPut(db->resources, cx_hash_key_str(local->path), local); |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1863 | } |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1864 | local->isdirectory = 1; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1865 | |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1866 | // cleanup LocalResource |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1867 | if(local->etag) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1868 | free(local->etag); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1869 | local->etag = NULL; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1870 | } |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1871 | if(local->hash) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1872 | free(local->hash); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1873 | local->hash = NULL; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1874 | } |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1875 | if(local->link_target) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1876 | free(local->link_target); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1877 | local->link_target = NULL; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1878 | } |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1879 | local->skipped = 0; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1880 | local->size = 0; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1881 | |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1882 | // set metadata |
763
fc24d1d1d695
fix dav-sync pull not storing finfo metadata correctly in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
762
diff
changeset
|
1883 | sync_set_metadata_from_stat(local, &s); |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1884 | if(sync_store_metadata(dir, local_path, local, res)) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1885 | fprintf(stderr, "Cannot store metadata: %s\n", res->path); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1886 | } |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1887 | |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1888 | // cleanup |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1889 | free(local_path); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1890 | return 0; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1891 | } |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
1892 | |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1893 | 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
|
1894 | 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
|
1895 | SYS_STAT s; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
1896 | if(sys_stat(local_path, &s)) { |
50
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1897 | free(local_path); |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1898 | return -2; |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1899 | } |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1900 | |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1901 | 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
|
1902 | free(local_path); |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1903 | return -1; |
50
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1904 | } |
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1905 | |
54 | 1906 | 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
|
1907 | free(local_path); |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1908 | return -2; |
50
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1909 | } |
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1910 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1911 | log_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
|
1912 | int ret = 0; |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1913 | if(dir->trash) { |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
1914 | move_to_trash(dir, local_path); |
412
dc74f736aea1
adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
411
diff
changeset
|
1915 | } else if(sys_unlink(local_path)) { |
50
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1916 | 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
|
1917 | ret = -2; |
50
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1918 | } |
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1919 | free(local_path); |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1920 | |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
1921 | return ret; |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1922 | } |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1923 | |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1924 | 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
|
1925 | int ret = 0; |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1926 | 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
|
1927 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1928 | log_printf("delete: %s\n", res->path); |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1929 | if(rmdir(local_path)) { |
633
b7de5ecc30fa
don't print error in case rmdir fails because of ENOTEMPTY
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
630
diff
changeset
|
1930 | // don't print error when dirs are not empty |
b7de5ecc30fa
don't print error in case rmdir fails because of ENOTEMPTY
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
630
diff
changeset
|
1931 | // because that can regulary happen, because the pull conflict |
b7de5ecc30fa
don't print error in case rmdir fails because of ENOTEMPTY
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
630
diff
changeset
|
1932 | // detection can prevent files from being deleted and in this case |
b7de5ecc30fa
don't print error in case rmdir fails because of ENOTEMPTY
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
630
diff
changeset
|
1933 | // the parent dir is not empty |
b7de5ecc30fa
don't print error in case rmdir fails because of ENOTEMPTY
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
630
diff
changeset
|
1934 | if(errno != ENOTEMPTY) { |
b7de5ecc30fa
don't print error in case rmdir fails because of ENOTEMPTY
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
630
diff
changeset
|
1935 | fprintf(stderr, "rmdir: %s : %s\n", local_path, strerror(errno)); |
b7de5ecc30fa
don't print error in case rmdir fails because of ENOTEMPTY
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
630
diff
changeset
|
1936 | } |
503
f84e64afee61
dav-sync pull refactoring: create list of changes before sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
502
diff
changeset
|
1937 | ret = 1; |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1938 | } |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1939 | |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
1940 | 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
|
1941 | return ret; |
50
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1942 | } |
9c486ea25161
dav-sync detects remote removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
49
diff
changeset
|
1943 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1944 | 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
|
1945 | char *local_path = create_local_path(dir, path); |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1946 | char *parent = util_parent_path(local_path); |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1947 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
1948 | 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
|
1949 | |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1950 | int rev = 0; |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
1951 | SYS_STAT s; |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1952 | int loop = 1; |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1953 | do { |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1954 | char *res_parent = util_parent_path(path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1955 | const char *res_name = util_resource_name(path); |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1956 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1957 | cxmutstr new_path = cx_asprintf( |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1958 | "%sorig.%d.%s", |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1959 | parent, |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1960 | rev, |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1961 | res_name); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1962 | cxmutstr new_res_path = cx_asprintf( |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1963 | "%sorig.%d.%s", |
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1964 | res_parent, |
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1965 | rev, |
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1966 | res_name); |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1967 | |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1968 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
1969 | if(sys_stat(new_path.ptr, &s)) { |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1970 | if(errno == ENOENT) { |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1971 | loop = 0; |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
1972 | log_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
|
1973 | 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
|
1974 | //printf("errno: %d\n", errno); |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1975 | fprintf( |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1976 | stderr, |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1977 | "Cannot rename file %s to %s\n", |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1978 | local_path, |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1979 | new_path.ptr); |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1980 | } else { |
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1981 | LocalResource *conflict = calloc(1, sizeof(LocalResource)); |
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1982 | conflict->path = strdup(new_res_path.ptr); |
560
a816e805e5db
store origin of file conflicts
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
559
diff
changeset
|
1983 | conflict->conflict_source = strdup(path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
1984 | cxMapPut(db->conflict, cx_hash_key_str(new_res_path.ptr), conflict); |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1985 | } |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1986 | } |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1987 | } |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1988 | rev++; |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1989 | free(res_parent); |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1990 | free(new_path.ptr); |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1991 | free(new_res_path.ptr); |
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1992 | |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1993 | } while(loop); |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1994 | free(parent); |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
1995 | free(local_path); |
52
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1996 | } |
91517b874a86
added conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
1997 | |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
1998 | char* create_tmp_download_path(char *path) { |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
1999 | char *new_path = NULL; |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2000 | char *parent = util_parent_path(path); |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2001 | for (int i=0;;i++) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2002 | cxmutstr np = cx_asprintf( |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2003 | "%sdownload%d-%s", |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2004 | parent, |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2005 | i, |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2006 | util_resource_name(path)); |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2007 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
2008 | SYS_STAT s; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
2009 | if(sys_stat(np.ptr, &s)) { |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2010 | if(errno == ENOENT) { |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2011 | new_path = np.ptr; |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2012 | } |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2013 | break; |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2014 | } |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2015 | free(np.ptr); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2016 | } |
145
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2017 | |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2018 | free(parent); |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2019 | return new_path; |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2020 | } |
82475dc12dd4
improved dav-sync data-loss prevention
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
144
diff
changeset
|
2021 | |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2022 | 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
|
2023 | char *new_path = NULL; |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2024 | for (int i=0;;i++) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2025 | cxmutstr np = cx_asprintf( |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2026 | "%s%d-%s", |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2027 | dir->trash, |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2028 | i, |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2029 | util_resource_name(path)); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2030 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
2031 | SYS_STAT s; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
2032 | if(sys_stat(np.ptr, &s)) { |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2033 | if(errno == ENOENT) { |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2034 | new_path = np.ptr; |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2035 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2036 | break; |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2037 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2038 | free(np.ptr); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2039 | } |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2040 | |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2041 | if(!new_path) { |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2042 | 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
|
2043 | return; |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2044 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2045 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
2046 | if(sys_rename(path, new_path)) { |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2047 | //printf("errno: %d\n", errno); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2048 | fprintf( |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2049 | stderr, |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2050 | "Cannot rename file %s to %s\n", |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2051 | path, |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2052 | new_path); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2053 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2054 | |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2055 | free(new_path); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2056 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
2057 | |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
2058 | static int res_isconflict(SyncDatabase *db, LocalResource *res) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2059 | return cxMapGet(db->conflict, cx_hash_key_str(res->path)) ? 1 : 0; |
216
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
2060 | } |
16d6b97fbf33
dav-sync push ignores conflict files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
2061 | |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2062 | int cmd_push(CmdArgs *a, DavBool outgoing, DavBool archive) { |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2063 | if(a->argc != 1) { |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2064 | 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
|
2065 | return -1; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2066 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2067 | |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2068 | // 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
|
2069 | SyncTagFilter* tagfilter = parse_tagfilter_string( |
ea50585ec9d9
adds tagfilter scope
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
412
diff
changeset
|
2070 | 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
|
2071 | if (!tagfilter) { |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2072 | fprintf(stderr, "Malformed tag filter\n"); |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2073 | return -1; |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2074 | } |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2075 | |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2076 | 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
|
2077 | if(!dir) { |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2078 | 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
|
2079 | return -1; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2080 | } |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
2081 | if(scfg_check_dir(dir)) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
2082 | return -1; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
2083 | } |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
2084 | if(logfile_open(dir)) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
2085 | return -1; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
2086 | } |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2087 | if(cmd_getoption(a, "snapshot")) { |
492
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
2088 | if(dir->versioning) { |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
2089 | dir->versioning->always = TRUE; |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
2090 | } else { |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
2091 | 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
|
2092 | return -1; |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
2093 | } |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
2094 | } |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2095 | |
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
|
2096 | 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
|
2097 | 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
|
2098 | 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
|
2099 | 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
|
2100 | 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
|
2101 | } |
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
|
2102 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2103 | DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(dir->repository)); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2104 | if(!repo) { |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2105 | 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
|
2106 | return -1; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2107 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2108 | |
49
c5759ac76c1b
dav-sync detects locally removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
2109 | SyncDatabase *db = load_db(dir->database); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2110 | if(!db) { |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2111 | 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
|
2112 | return -1; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2113 | } |
218
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
2114 | remove_deleted_conflicts(dir, db); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2115 | |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
2116 | DavSession *sn = create_session(a, ctx, repo, dir->collection); |
775 | 2117 | cxMempoolRegister(sn->mp, db, (cx_destructor_func)destroy_db); |
68
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
66
diff
changeset
|
2118 | if (cmd_getoption(a, "verbose")) { |
f6d3db6113d3
added verbose option + encryption flag fixes
Mike Becker <universe@uap-core.de>
parents:
66
diff
changeset
|
2119 | 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
|
2120 | 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
|
2121 | } |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
2122 | if(SYNC_STORE_HASH(dir)) { |
556
1a58014260e0
set content-hash property after uploads when syncdir hashing is enabled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
554
diff
changeset
|
2123 | 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
|
2124 | } |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2125 | |
445
c525f049c8b7
renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
444
diff
changeset
|
2126 | 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
|
2127 | 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
|
2128 | 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
|
2129 | 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
|
2130 | |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2131 | 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
|
2132 | if(!root) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2133 | log_resource_error(sn, "/"); |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2134 | dav_session_destroy(sn); |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2135 | log_error("Abort\n"); |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2136 | return -1; |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2137 | } |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2138 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2139 | CxMap *svrres = NULL; |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2140 | if(restore) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2141 | svrres = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 1024); |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2142 | res2map(root, svrres); |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2143 | } |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2144 | |
220
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
2145 | 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
|
2146 | |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2147 | // lock repository |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2148 | DavBool locked = FALSE; |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
2149 | char *locktokenfile = NULL; |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2150 | if((dir->lockpush || cmd_getoption(a, "lock")) && !cmd_getoption(a, "nolock") && !outgoing) { |
316
9d0505d80044
adds dav-sync lock timeout config element
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
313
diff
changeset
|
2151 | if(dav_lock_t(root, dir->lock_timeout)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2152 | log_resource_error(sn, "/"); |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2153 | dav_session_destroy(sn); |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2154 | log_error("Abort\n"); |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2155 | return -1; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2156 | } |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
2157 | DavLock *lock = dav_get_lock(sn, "/"); |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
2158 | if(lock) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2159 | log_printf("Lock-Token: %s\n", lock->token); |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
2160 | } |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2161 | locked = TRUE; |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
2162 | 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
|
2163 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2164 | |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2165 | 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
|
2166 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2167 | CxMap *db_hashes = NULL; |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
2168 | if(SYNC_HASHING(dir)) { |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2169 | db_hashes = create_hash_index(db); |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2170 | } |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2171 | |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2172 | int sync_success = 0; |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2173 | int sync_delete = 0; |
561
5e6df4f502d3
harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents:
560
diff
changeset
|
2174 | 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
|
2175 | int sync_error = 0; |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2176 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2177 | CxList *ls_new = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_path_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2178 | CxList *ls_modified = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_path_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2179 | CxList *ls_conflict = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_path_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2180 | CxList *ls_update = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_path_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2181 | CxList *ls_delete = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_path_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2182 | CxList *ls_move = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_path_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2183 | CxList *ls_copy = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_path_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2184 | CxList *ls_mkcol = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)resource_path_cmp, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2185 | |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2186 | |
51
e94bf8530d56
dav-sync deletes removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
2187 | // 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
|
2188 | //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
|
2189 | // read_changes(dir, db) : local_scan(dir, db); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2190 | CxList *resources = local_scan(dir, db); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2191 | CxMap *resources_map = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, cxListSize(resources)+16); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2192 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2193 | CxIterator iter = cxListIterator(resources); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2194 | cx_foreach(LocalResource *, local_res, iter) { |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2195 | // 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
|
2196 | |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2197 | // static include/exclude filter |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
2198 | if(res_matches_dir_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
|
2199 | continue; |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2200 | } |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2201 | // static tag filter |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2202 | if(dir->filter.tags) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2203 | CxIterator tag_iter = cxListIterator(dir->filter.tags); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2204 | cx_foreach(SyncTagFilter *, tf, tag_iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2205 | if(!localres_matches_tags(dir, local_res, tf)) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2206 | continue; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2207 | } |
417
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
2208 | } |
f340460a8b5d
disables tagfilter for directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
2209 | } |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2210 | |
810
baf199df500e
don't store directories with a trailing path separator in the sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
799
diff
changeset
|
2211 | |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2212 | // we need a fast file lookup map later to detect deleted files |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2213 | cxMapPut(resources_map, cx_hash_key_str(local_res->path), 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
|
2214 | |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2215 | // 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
|
2216 | 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
|
2217 | if(!remove_file) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2218 | LocalResource *dbres = cxMapGet( |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2219 | db->resources, |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2220 | cx_hash_key_str(local_res->path)); |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2221 | if(dbres) { |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2222 | // 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
|
2223 | 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
|
2224 | } |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2225 | } |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2226 | continue; |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2227 | } |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2228 | |
561
5e6df4f502d3
harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents:
560
diff
changeset
|
2229 | // 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
|
2230 | if(res_isconflict(db, local_res)) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2231 | cxListAdd(ls_conflict, 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
|
2232 | continue; |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2233 | } |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2234 | |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2235 | 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
|
2236 | dir, |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2237 | db, |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2238 | local_res, |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2239 | svrres, |
445
c525f049c8b7
renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
444
diff
changeset
|
2240 | restore_removed, |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
2241 | 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
|
2242 | if(is_changed) { |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2243 | if(local_res->isdirectory) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2244 | cxListAdd(ls_mkcol, local_res); |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2245 | } else if(local_res->isnew) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2246 | cxListAdd(ls_new, local_res); |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2247 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2248 | cxListAdd(ls_modified, local_res); |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2249 | } |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
2250 | } else if(local_res->metadata_updated) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2251 | cxListAdd(ls_update, 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
|
2252 | } |
614
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
2253 | |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
2254 | if(local_res->isnew) { |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
2255 | if(local_resource_load_metadata(dir, local_res)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2256 | log_error( |
614
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
2257 | "Failed to load metadata: %s\n", |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
2258 | local_resource_path(local_res)); |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
2259 | } |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
2260 | } |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2261 | } |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2262 | |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
2263 | if(SYNC_STORE_HASH(dir)) { |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2264 | // 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
|
2265 | // was moved or is a copy |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2266 | CxIterator mut_iter = cxListMutIterator(ls_new); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2267 | cx_foreach(LocalResource *, local, mut_iter) { |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
2268 | if(local->isdirectory || local->link_target) { |
551
99ef8202cd82
add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
2269 | continue; |
99ef8202cd82
add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
2270 | } |
99ef8202cd82
add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
2271 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
2272 | char *local_path = util_concat_path(dir->path, local_resource_path(local)); |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2273 | char *hash = util_file_hash(local_path); |
551
99ef8202cd82
add copy/move operation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
550
diff
changeset
|
2274 | local->hash = hash; |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2275 | // check if a file with this hash already exists |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2276 | LocalResource *origin = cxMapGet(db_hashes, cx_hash_key_str(hash)); |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2277 | if(origin) { |
552
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
2278 | 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
|
2279 | // the file is a copied/moved file |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2280 | // 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
|
2281 | // it still exists |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2282 | if(cxMapGet(resources_map, cx_hash_key_str(origin->path))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2283 | cxListAdd(ls_copy, local); |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2284 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2285 | cxListAdd(ls_move, local); |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2286 | // put file in resources_map to prevent deletion |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2287 | cxMapPut(resources_map, cx_hash_key_str(origin->path), local); |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2288 | } |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2289 | // remove list elemend from ls_new |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2290 | cxIteratorFlagRemoval(mut_iter); |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2291 | } |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2292 | |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2293 | free(local_path); |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2294 | } |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2295 | } |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
2296 | |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2297 | // find all deleted files and cleanup the database |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2298 | iter = cxMapIterator(db->resources); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2299 | CxList *removed_res = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2300 | cx_foreach(CxMapEntry *, entry, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2301 | LocalResource *local = entry->value; |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2302 | // all filtered files should be removed from the database |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
2303 | if(res_matches_dir_filter(dir, local->path+1)) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2304 | cxMapRemove(db->resources, local->path); |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2305 | continue; |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2306 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2307 | CxIterator tag_iter = cxListIterator(dir->filter.tags); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2308 | cx_foreach(SyncTagFilter *, tf, tag_iter) { |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2309 | if(!localres_matches_tags(dir, local, tf)) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2310 | cxMapRemove(db->resources, local->path); |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2311 | continue; |
58
1708cba82ca3
added include / exclude patterns
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
2312 | } |
403
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2313 | } |
8e1948eebef5
adds tag filters for push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
2314 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2315 | if(!cxMapGet(resources_map, *entry->key)) { |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2316 | // 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
|
2317 | // 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
|
2318 | // 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
|
2319 | if(!archive) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2320 | cxListAdd(ls_delete, local); |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2321 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2322 | cxListInsert(removed_res, 0, local); |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2323 | } |
57 | 2324 | } |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2325 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2326 | iter = cxListIterator(removed_res); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2327 | cx_foreach(LocalResource *, local, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2328 | cxMapRemove(db->resources, local->path); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2329 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2330 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2331 | cxListSort(ls_new); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2332 | cxListSort(ls_modified); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2333 | cxListSort(ls_conflict); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2334 | cxListSort(ls_update); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2335 | cxListSort(ls_delete); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2336 | cxListSort(ls_move); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2337 | cxListSort(ls_copy); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2338 | cxListSort(ls_mkcol); |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2339 | |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2340 | if(outgoing) { |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2341 | print_outgoing( |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2342 | a, |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2343 | ls_new, |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2344 | ls_modified, |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2345 | ls_conflict, |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2346 | ls_update, |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2347 | ls_delete, |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2348 | ls_move, |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2349 | ls_copy, |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2350 | ls_mkcol); |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2351 | return 0; |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2352 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2353 | |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2354 | // |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2355 | // BEGIN PUSH |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2356 | // |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2357 | |
568
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2358 | int ret = 0; |
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2359 | int error = 0; |
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2360 | |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2361 | // create collections |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2362 | iter = cxListIterator(ls_mkcol); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2363 | cx_foreach(LocalResource *, local_res, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2364 | if(sync_shutdown) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2365 | break; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2366 | } |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2367 | |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2368 | DavResource *res = dav_resource_new(sn, local_res->path); |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2369 | if(!res) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2370 | log_resource_error(sn, local_res->path); |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2371 | ret = -1; |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2372 | sync_error++; |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2373 | } |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2374 | |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2375 | int abort = 0; |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2376 | |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2377 | dav_exists(res); |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2378 | if(sn->error == DAV_NOT_FOUND) { |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2379 | // create collection |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2380 | // TODO: show 405 |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2381 | log_printf("mkcol: %s\n", local_res->path); |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2382 | if(sync_mkdir(dir, res, local_res) && sn->error != DAV_METHOD_NOT_ALLOWED) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2383 | log_resource_error(sn, res->path); |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2384 | ret = -1; |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2385 | sync_error++; |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2386 | error = 1; |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2387 | abort = 1; |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2388 | } |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2389 | } else if(sn->error != DAV_OK) { |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2390 | // dav_exists() failed |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2391 | log_resource_error(sn, local_res->path); |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2392 | ret = -1; |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2393 | sync_error++; |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2394 | error = 1; |
613
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2395 | abort = 1; |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2396 | } |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2397 | |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2398 | if(!abort) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2399 | // success |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2400 | if(local_res->metadata_updated) { |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2401 | sync_update_metadata(dir, sn, res, local_res); |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2402 | } |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2403 | |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2404 | // remove old db entry (if it exists) |
f6072141f5ee
fix directories not stored in db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
611
diff
changeset
|
2405 | // and add add new entry |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2406 | // TODO: free?? |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2407 | LocalResource *dbres = cxMapGet(db->resources, cx_hash_key_str(local_res->path)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2408 | cxMapPut(db->resources, cx_hash_key_str(local_res->path), local_res); |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2409 | } |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2410 | |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2411 | dav_resource_free(res); |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2412 | } |
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2413 | |
568
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2414 | // copy/move files |
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2415 | DavBool copy = TRUE; |
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2416 | if(!ls_copy) { |
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2417 | copy = FALSE; |
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2418 | ls_copy = ls_move; |
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2419 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2420 | iter = cxListIterator(ls_copy); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2421 | for(int i=0;i<2;i++) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2422 | cx_foreach(LocalResource*, local, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2423 | if(sync_shutdown) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2424 | break; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2425 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2426 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2427 | int err = 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2428 | DavResource *res = dav_resource_new(sn, local->path); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2429 | if(dav_exists(res)) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2430 | log_printf("conflict: %s\n", local->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2431 | local->last_modified = 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2432 | nullfree(local->etag); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2433 | local->etag = NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2434 | nullfree(local->hash); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2435 | local->hash = NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2436 | local->skipped = TRUE; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2437 | sync_conflict++; |
568
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2438 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2439 | DavResource *origin_res = dav_resource_new(sn, local->origin->path); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2440 | int origin_changed = remote_resource_is_changed( |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2441 | sn, |
568
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2442 | dir, |
569
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
2443 | db, |
568
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2444 | origin_res, |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2445 | local->origin, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2446 | NULL); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2447 | if(origin_changed) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2448 | // upload with put |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2449 | cxListInsert(ls_modified, 0, local); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2450 | } else { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2451 | log_printf("%s: %s -> %s\n", copy ? "copy":"move", local->origin->path, local->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2452 | err = sync_move_remote_resource( |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2453 | dir, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2454 | db, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2455 | origin_res, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2456 | local, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2457 | copy, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2458 | &sync_success); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2459 | } |
568
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2460 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2461 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2462 | if(err) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2463 | sync_error++; |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2464 | log_resource_error(sn, res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2465 | ret = -1; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2466 | error = 1; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2467 | } else { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2468 | LocalResource *dbres = cxMapGet(db->resources, cx_hash_key_str(local->path)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2469 | cxMapPut(db->resources, cx_hash_key_str(local->path), local); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2470 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2471 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2472 | copy = FALSE; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2473 | iter = cxListIterator(ls_move); |
568
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2474 | } |
a81cad6bb377
fix push operation order (move before put)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
567
diff
changeset
|
2475 | |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2476 | // upload changed files |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2477 | //ls_modified = ucx_list_concat(ls_new, ls_modified); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2478 | iter = cxListIterator(ls_new); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2479 | for(int i=0;i<2;i++) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2480 | cx_foreach(LocalResource*, local_res, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2481 | if(sync_shutdown) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2482 | break; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2483 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2484 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2485 | int err = 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2486 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2487 | DavResource *res = dav_resource_new(sn, local_res->path); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2488 | if(!res) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2489 | log_resource_error(sn, local_res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2490 | ret = -1; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2491 | sync_error++; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2492 | } else { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2493 | DavBool equal = FALSE; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2494 | DavBool res_conflict = FALSE; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2495 | int changed = remote_resource_is_changed(sn, dir, db, res, local_res, &equal); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2496 | if(equal) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2497 | char *etag = dav_get_string_property(res, "D:getetag"); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2498 | if(local_res->metadata_updated) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2499 | cxListInsert(ls_update, 0, local_res); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2500 | } else if(etag) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2501 | // update etag in db |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2502 | if(local_res->etag) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2503 | free(local_res->etag); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2504 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2505 | local_res->etag = strdup(etag); |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
2506 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2507 | } else if(cdt && changed) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2508 | log_printf("conflict: %s\n", local_res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2509 | local_res->last_modified = 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2510 | nullfree(local_res->etag); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2511 | local_res->etag = NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2512 | nullfree(local_res->hash); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2513 | local_res->hash = NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2514 | local_res->skipped = TRUE; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2515 | sync_conflict++; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2516 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2517 | if(local_res->link_target) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2518 | free(local_res->link_target); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2519 | local_res->link_target = local_res->link_target_db; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2520 | local_res->link_target_db = NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2521 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2522 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2523 | res_conflict = TRUE; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2524 | } else { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2525 | if(local_res->link_target) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2526 | log_printf( |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2527 | "link: %s -> %s\n", |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2528 | local_res->path, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2529 | local_res->link_target); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2530 | } else { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2531 | log_printf("put: %s\n", local_res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2532 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2533 | if(sync_put_resource(dir, res, local_res, &sync_success)) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2534 | sync_error++; |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2535 | log_resource_error(sn, res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2536 | ret = -1; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2537 | error = 1; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2538 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2539 | err = 1; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2540 | } |
639
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
2541 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2542 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2543 | if(!err) { |
852 | 2544 | LocalResource *dbres = NULL; |
2545 | cxMapRemoveAndGet(db->resources, cx_hash_key_str(local_res->path), &dbres); | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2546 | // in case of a conflict, don't store the resource |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2547 | // in the db, if it is new |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2548 | if(!res_conflict || dbres) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2549 | cxMapPut(db->resources, cx_hash_key_str(local_res->path), local_res); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2550 | } |
603
8e7e072c18c1
fix that db entries are updated on errors
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
599
diff
changeset
|
2551 | } |
585
41368a355222
create collections before doing other stuff on dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
584
diff
changeset
|
2552 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2553 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2554 | dav_resource_free(res); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2555 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2556 | iter = cxListIterator(ls_modified); |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2557 | } |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2558 | |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2559 | // metadata updates |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2560 | iter = cxListIterator(ls_update); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2561 | cx_foreach(LocalResource *, local_res, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2562 | if(sync_shutdown) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2563 | break; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2564 | } |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2565 | |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2566 | 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
|
2567 | if(local_res->metadata_updated) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2568 | log_printf("update: %s\n", local_res->path); |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
2569 | if(!sync_update_metadata(dir, sn, res, local_res)) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2570 | LocalResource *dbres = cxMapGet(db->resources, cx_hash_key_str(local_res->path)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2571 | cxMapPut(db->resources, cx_hash_key_str(local_res->path), local_res); |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
2572 | } |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2573 | } |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2574 | } |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2575 | |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2576 | // delete all removed files |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2577 | cxListSort(ls_delete); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2578 | |
760
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
2579 | CxList *cols = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)localres_cmp_path_desc, CX_STORE_POINTERS); |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
2580 | CxList *cols_del = cols; // remember pointer for cleanup |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2581 | CxList *col_list = cols; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2582 | CxList *deletelist = ls_delete; |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2583 | 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
|
2584 | // 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
|
2585 | // 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
|
2586 | // in the second run all collections will be deleted |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2587 | iter = cxListIterator(deletelist); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2588 | cx_foreach(LocalResource *, local, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2589 | if(sync_shutdown) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2590 | break; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2591 | } |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2592 | 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
|
2593 | continue; |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2594 | } |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2595 | 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
|
2596 | if(sn->error != DAV_NOT_FOUND) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2597 | log_resource_error(sn, local->path); |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2598 | sync_error++; |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2599 | 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
|
2600 | } |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2601 | } else { |
852 | 2602 | LocalResource *dbres = NULL; |
2603 | cxMapRemoveAndGet(db->resources, cx_hash_key_str(local->path), &dbres); | |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2604 | //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
|
2605 | } |
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
|
2606 | } |
760
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
2607 | cxListSort(cols); |
501
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2608 | deletelist = cols; |
868da3f76267
dav-sync push refactoring: create list of changes before executing sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
497
diff
changeset
|
2609 | col_list = NULL; |
760
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
2610 | } |
ae759e4be591
fix dav-sync push not deleting collections in the right order
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
759
diff
changeset
|
2611 | |
852 | 2612 | cxListFree(cols_del); |
51
e94bf8530d56
dav-sync deletes removed files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
2613 | |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2614 | // unlock repository |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2615 | if(locked) { |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2616 | if(dav_unlock(root)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2617 | log_resource_error(sn, "/"); |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2618 | ret = -1; |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
2619 | } else { |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
2620 | locked = FALSE; |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2621 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2622 | } |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2623 | |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2624 | // store db |
521
c5bbae4b3cca
extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
516
diff
changeset
|
2625 | if(store_db(db, dir->database, dir->db_settings)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2626 | log_error("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
|
2627 | ret = -2; |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2628 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
2629 | |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2630 | // cleanup |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
2631 | if(!locked && locktokenfile) { |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
2632 | remove(locktokenfile); |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
2633 | } |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
2634 | |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2635 | 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
|
2636 | |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2637 | // Report |
223
cbbdf207e67e
fixed some bugs in dav_create() and dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
222
diff
changeset
|
2638 | if(ret != -2) { |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2639 | char *str_success = sync_success == 1 ? "file" : "files"; |
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2640 | 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
|
2641 | 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
|
2642 | 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
|
2643 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2644 | log_printf("Result: %d %s pushed, ", sync_success, str_success); |
299
c517502d3e38
adds dav-sync archive command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
296
diff
changeset
|
2645 | if(!archive) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2646 | log_printf("%d %s deleted, ", sync_delete, str_delete); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2647 | } |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2648 | log_printf("%d %s, %d %s\n", |
561
5e6df4f502d3
harmonizes output of push and pull
Mike Becker <universe@uap-core.de>
parents:
560
diff
changeset
|
2649 | 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
|
2650 | } |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
2651 | |
221
e22c29b7ee2f
using locks in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
220
diff
changeset
|
2652 | return ret; |
46
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2653 | } |
0542668d0f26
added new sync tool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2654 | |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2655 | int cmd_restore(CmdArgs *a) { |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2656 | char *syncdir = cmd_getoption(a, "syncdir"); |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2657 | |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2658 | if(!syncdir && a->argc == 0) { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2659 | 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
|
2660 | return -1; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2661 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2662 | |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2663 | char *version = cmd_getoption(a, "version"); |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2664 | if(version) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2665 | if(a->argc != 1) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2666 | 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
|
2667 | return -1; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2668 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2669 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2670 | |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2671 | SyncDirectory *dir = NULL; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2672 | CxMap *files = NULL; |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2673 | if(syncdir) { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2674 | dir = scfg_get_dir(syncdir); |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2675 | } |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
2676 | if(logfile_open(dir)) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
2677 | return -1; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
2678 | } |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2679 | |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2680 | LocalResource nres; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2681 | if(a->argc > 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2682 | files = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, a->argc+8); |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2683 | // 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
|
2684 | SyncDirectory *sd = NULL; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2685 | 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
|
2686 | SyncFile f; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2687 | 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
|
2688 | if(err) { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2689 | 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
|
2690 | return 1; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2691 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2692 | if(!sd) { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2693 | sd = f.dir; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2694 | } else { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2695 | if(f.dir != sd) { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2696 | 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
|
2697 | return 1; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2698 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2699 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2700 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2701 | cxMapPut(files, cx_hash_key_str(f.path), &nres); |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2702 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2703 | dir = sd; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2704 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2705 | |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2706 | if(!dir) { |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2707 | 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
|
2708 | return -1; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2709 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2710 | if(scfg_check_dir(dir)) { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2711 | return -1; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2712 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2713 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2714 | 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
|
2715 | 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
|
2716 | print_allowed_cmds(dir); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2717 | return -1; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2718 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2719 | |
528
4c9c8c017d52
adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
2720 | 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
|
2721 | 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
|
2722 | if(!restore_modified && !restore_removed) { |
4c9c8c017d52
adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
2723 | restore_modified = 1; |
4c9c8c017d52
adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
2724 | restore_removed = 1; |
4c9c8c017d52
adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
2725 | } |
4c9c8c017d52
adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
2726 | |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2727 | SyncDatabase *db = load_db(dir->database); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2728 | if(!db) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2729 | log_error("Cannot load database file: %s\n", dir->database); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2730 | return -1; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2731 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2732 | remove_deleted_conflicts(dir, db); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2733 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2734 | CxList *modified = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)localres_cmp_path, CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2735 | CxList *deleted = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)localres_cmp_path, CX_STORE_POINTERS); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2736 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2737 | // 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
|
2738 | // modified or deleted |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2739 | CxIterator resiter = cxMapIterator(files ? files : db->resources); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2740 | cx_foreach(CxMapEntry *, entry, resiter) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2741 | LocalResource *resource = entry->value; |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2742 | if(resource == &nres) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2743 | resource = cxMapGet(db->resources, *entry->key); |
532
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2744 | if(!resource) { |
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2745 | continue; |
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2746 | } |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2747 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2748 | |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
2749 | 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
|
2750 | SYS_STAT s; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2751 | if(sys_stat(file_path, &s)) { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2752 | if(errno == ENOENT) { |
528
4c9c8c017d52
adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
2753 | if(restore_removed) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2754 | cxListAdd(deleted, resource); |
528
4c9c8c017d52
adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
2755 | } |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2756 | } else { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2757 | log_error("Cannot stat file: %s\n", file_path); |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2758 | log_error("%s\n", strerror(errno)); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2759 | } |
532
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2760 | } else { |
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2761 | if(files) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2762 | cxListAdd(modified, resource); |
532
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2763 | } 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
|
2764 | 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
|
2765 | if(restore_modified) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2766 | cxListAdd(modified, resource); |
532
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2767 | } |
528
4c9c8c017d52
adds -R and -M option to restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
527
diff
changeset
|
2768 | } |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2769 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2770 | } |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2771 | |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2772 | free(file_path); |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2773 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2774 | |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
2775 | if(files) { |
852 | 2776 | cxMapFree(files); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2777 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2778 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2779 | int ret = 0; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2780 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2781 | // create DavSession |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
2782 | DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(dir->repository)); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2783 | if(!repo) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2784 | log_error("Unkown repository %s\n", dir->name); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2785 | return -1; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2786 | } |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
2787 | DavSession *sn = create_session(a, ctx, repo, dir->collection); |
775 | 2788 | cxMempoolRegister(sn->mp, db, (cx_destructor_func)destroy_db); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2789 | if (cmd_getoption(a, "verbose")) { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2790 | curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2791 | curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2792 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2793 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2794 | // lock repository |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2795 | char *locktokenfile = NULL; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2796 | DavBool locked = FALSE; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2797 | DavResource *root = dav_resource_new(sn, "/"); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2798 | root->iscollection = TRUE; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2799 | 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
|
2800 | if(dav_lock_t(root, dir->lock_timeout)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2801 | log_resource_error(sn, "/"); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2802 | dav_session_destroy(sn); |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2803 | log_error("Abort\n"); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2804 | return -1; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2805 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2806 | DavLock *lock = dav_get_lock(sn, "/"); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2807 | if(lock) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2808 | log_printf("Lock-Token: %s\n", lock->token); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2809 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2810 | locked = TRUE; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2811 | locktokenfile = create_locktoken_file(dir->name, lock->token); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2812 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2813 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2814 | int sync_success = 0; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2815 | int sync_error = 0; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2816 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2817 | // TODO: old code sorted both modified and deleted, is this necessary? |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2818 | //UcxList *resources = ucx_list_concat(modified, deleted); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2819 | //resources = ucx_list_sort(resources, (cmp_func)localres_cmp_path, NULL); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2820 | cxListSort(deleted); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2821 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2822 | CxIterator iter = cxListIterator(modified); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2823 | for(int i=0;i<2;i++) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2824 | cx_foreach(LocalResource *, resource, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2825 | DavResource *res = dav_get(sn, resource->path, "D:getetag,idav:status,idav:version-collection,idav:split,`idav:content-hash`,idavprops:tags,idavprops:finfo,idavprops:xattributes,idavprops:link"); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2826 | if(!res) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2827 | log_printf("skip: %s\n", resource->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2828 | continue; |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2829 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2830 | char *status = dav_get_string_property(res, "idav:status"); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2831 | if(status && !strcmp(status, "broken")) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2832 | log_error("Resource %s broken\n", res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2833 | continue; |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2834 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2835 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2836 | DavResource *vres = NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2837 | DavBool update_local_entry = TRUE; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2838 | if(version) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2839 | if(dir->versioning->type == VERSIONING_SIMPLE) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2840 | vres = versioning_simple_find(res, version); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2841 | } else if(dir->versioning->type == VERSIONING_DELTAV) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2842 | vres = versioning_deltav_find(res, version); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2843 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2844 | if(!vres) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2845 | log_error("Cannot find specified version for resource %s\n", res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2846 | ret = 1; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2847 | break; |
532
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2848 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2849 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2850 | // By restoring an old version of a file, the local dir is not |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2851 | // in sync with the server anymore. Mark this file to change |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2852 | // the metadata later, to make sure, the file will be detected |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2853 | // as locally modified, on the next push/pull |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2854 | update_local_entry = FALSE; |
532
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2855 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2856 | vres = res; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2857 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2858 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2859 | // download the resource |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2860 | if(!sync_shutdown) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2861 | if(resource->isdirectory) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2862 | char *local_path = create_local_path(dir, res->path); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2863 | if(sys_mkdir(local_path) && errno != EEXIST) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2864 | log_error( |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2865 | "Cannot create directory %s: %s", |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2866 | local_path, strerror(errno)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2867 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2868 | free(local_path); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2869 | } else { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2870 | if(sync_get_resource(a, dir, res->path, vres, db, update_local_entry, &sync_success)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2871 | log_error("sync_get_resource failed for resource: %s\n", res->path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2872 | sync_error++; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2873 | } else if(!update_local_entry) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2874 | LocalResource *lr = cxMapGet(db->resources, cx_hash_key_str(res->path)); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2875 | if(lr) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2876 | lr->last_modified = 0; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2877 | nullfree(lr->hash); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2878 | lr->hash = NULL; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2879 | } // else should not happen |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2880 | } |
532
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2881 | } |
aeda47714978
fixes dav_copy_node and improves dav-sync restore
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
531
diff
changeset
|
2882 | } |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2883 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2884 | iter = cxListIterator(deleted); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2885 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2886 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2887 | // unlock repository |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2888 | if(locked) { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2889 | if(dav_unlock(root)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2890 | log_resource_error(sn, "/"); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2891 | ret = -1; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2892 | } else { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2893 | locked = FALSE; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2894 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2895 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2896 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2897 | // store db |
521
c5bbae4b3cca
extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
516
diff
changeset
|
2898 | if(store_db(db, dir->database, dir->db_settings)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
2899 | log_error("Cannot store sync db\n"); |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2900 | ret = -2; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2901 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2902 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2903 | // cleanup |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2904 | dav_session_destroy(sn); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2905 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2906 | if(!locked && locktokenfile) { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2907 | remove(locktokenfile); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2908 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2909 | |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2910 | // Report |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2911 | if(ret != -2) { |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2912 | char *str_success = sync_success == 1 ? "file" : "files"; |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2913 | char *str_error = sync_error == 1 ? "error" : "errors"; |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2914 | log_printf("Result: %d %s pulled, %d %s\n", |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2915 | sync_success, str_success, |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2916 | sync_error, str_error); |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2917 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2918 | |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
2919 | return ret; |
490
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2920 | } |
d94c4fd35c21
adds dav-sync restore command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
479
diff
changeset
|
2921 | |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2922 | static void print_outgoging_file(LocalResource *res) { |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2923 | char *lastmodified = util_date_str(res->last_modified); |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2924 | char *size = util_size_str(FALSE, res->size); |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2925 | log_printf(" %-49s %12s %10s\n", res->path+1, lastmodified, size); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2926 | free(lastmodified); |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2927 | free(size); |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2928 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2929 | |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2930 | void print_outgoing( |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2931 | CmdArgs *args, |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2932 | CxList *ls_new, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2933 | CxList *ls_modified, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2934 | CxList *ls_conflict, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2935 | CxList *ls_update, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2936 | CxList *ls_delete, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2937 | CxList *ls_move, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2938 | CxList *ls_copy, |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2939 | CxList *ls_mkcol) |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2940 | { |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2941 | int64_t total_size = 0; |
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2942 | |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2943 | size_t len_new = cxListSize(ls_new); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2944 | size_t len_mod = cxListSize(ls_modified); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2945 | size_t len_cnf = cxListSize(ls_conflict); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2946 | size_t len_upd = cxListSize(ls_update); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2947 | size_t len_del = cxListSize(ls_delete); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2948 | size_t len_mov = cxListSize(ls_move); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2949 | size_t len_cpy = cxListSize(ls_copy); |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2950 | size_t len_mkc = cxListSize(ls_mkcol); |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2951 | |
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2952 | size_t total = len_new + len_mod + len_cnf + len_upd + len_del + len_mov + len_cpy + len_mkc; |
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2953 | if(total == 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2954 | log_printf("no changes\n"); |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2955 | return; |
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2956 | } |
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2957 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2958 | log_printf("%s\n", "File Last Modified Size"); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2959 | log_printf("%s\n", "=============================================================================="); |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
2960 | |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2961 | if(cxListSize(ls_mkcol) > 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2962 | log_printf("Directories:\n"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2963 | CxIterator i = cxListIterator(ls_mkcol); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2964 | cx_foreach(LocalResource *, res, i) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2965 | log_printf(" %-49s\n", res->path+1); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2966 | total_size += res->size; |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2967 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2968 | } |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2969 | if(cxListSize(ls_new) > 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2970 | log_printf("New:\n"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2971 | CxIterator i = cxListIterator(ls_new); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2972 | cx_foreach(LocalResource *, res, i) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2973 | print_outgoging_file(res); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2974 | total_size += res->size; |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2975 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2976 | } |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2977 | if(cxListSize(ls_modified) > 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2978 | log_printf("Modified:\n"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2979 | CxIterator i = cxListIterator(ls_modified); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2980 | cx_foreach(LocalResource *, res, i) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2981 | print_outgoging_file(res); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2982 | total_size += res->size; |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2983 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2984 | } |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2985 | if(cxListSize(ls_update) > 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2986 | log_printf("Update:\n"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2987 | CxIterator i = cxListIterator(ls_update); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2988 | cx_foreach(LocalResource *, res, i) { |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2989 | char *lastmodified = util_date_str(res->last_modified); |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2990 | log_printf(" %-49s %12s\n", res->path+1, lastmodified); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2991 | free(lastmodified); |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2992 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2993 | } |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
2994 | if(cxListSize(ls_delete) > 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2995 | log_printf("Delete:\n"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2996 | CxIterator i = cxListIterator(ls_delete); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
2997 | cx_foreach(LocalResource *, res, i) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
2998 | log_printf(" %s\n", res->path+1); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
2999 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3000 | } |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
3001 | if(cxListSize(ls_copy) > 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3002 | log_printf("Copy:\n"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3003 | CxIterator i = cxListIterator(ls_copy); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3004 | cx_foreach(LocalResource *, res, i) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3005 | log_printf("%s -> %s\n", res->origin->path+1, res->path); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3006 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3007 | } |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
3008 | if(cxListSize(ls_move) > 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3009 | log_printf("Move:\n"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3010 | CxIterator i = cxListIterator(ls_move); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3011 | cx_foreach(LocalResource *, res, i) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3012 | log_printf("%s -> %s\n", res->origin->path+1, res->path); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3013 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3014 | } |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
3015 | if(cxListSize(ls_conflict) > 0) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3016 | log_printf("Conflict\n"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3017 | CxIterator i = cxListIterator(ls_conflict); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3018 | cx_foreach(LocalResource *, res, i) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3019 | log_printf(" %s\n", res->path+1); |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3020 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3021 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3022 | |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3023 | char *total_size_str = util_size_str(FALSE, total_size); |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
3024 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3025 | log_printf("\n"); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3026 | if(len_new > 0) log_printf("new: %zu, ", len_new); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3027 | if(len_mod > 0) log_printf("modified: %zu, ", len_mod); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3028 | if(len_upd > 0) log_printf("updated: %zu, ", len_upd); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3029 | if(len_cpy > 0) log_printf("copied: %zu, ", len_cpy); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3030 | if(len_mov > 0) log_printf("moved: %zu, ", len_mov); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3031 | if(len_del > 0) log_printf("deleted: %zu, ", len_del); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3032 | if(len_cnf > 0) log_printf("conflicts: %zu, ", len_cnf); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
3033 | log_printf("total size: %s\n", total_size_str); |
724
9c2f0072abed
sort files in outgoing cmd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
723
diff
changeset
|
3034 | |
723
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3035 | free(total_size_str); |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3036 | } |
5ca174b3247a
add dav-sync outgoing command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
702
diff
changeset
|
3037 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3038 | CxList* local_scan(SyncDirectory *dir, SyncDatabase *db) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3039 | CxList *resources = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3040 | |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3041 | char *path = strdup("/"); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3042 | CxList *stack = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3043 | cxListInsert(stack, 0, path); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
3044 | while(cxListSize(stack) > 0) { |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3045 | // 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
|
3046 | // 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
|
3047 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3048 | char *p = cxListAt(stack, 0); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3049 | cxListRemove(stack, 0); |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
3050 | 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
|
3051 | 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
|
3052 | |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3053 | if(!local_dir) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
3054 | log_error("Cannot open directory %s: %s\n", local_path, strerror(errno)); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3055 | } else { |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
3056 | SysDirEnt *ent; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
3057 | 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
|
3058 | 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
|
3059 | continue; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3060 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3061 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
3062 | char *new_path = util_concat_path(p, ent->name); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3063 | DavBool free_new_path = TRUE; |
573
b8f798d240ab
change local_resource_new signature
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
3064 | LocalResource *res = local_resource_new(dir, db, new_path); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3065 | if(res) { |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3066 | if(res->isdirectory) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3067 | cxListAdd(resources, res); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3068 | cxListInsert(stack, 0, new_path); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3069 | free_new_path = FALSE; |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3070 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3071 | cxListAdd(resources, res); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3072 | } |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3073 | } |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3074 | if(free_new_path) { |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3075 | free(new_path); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3076 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3077 | } |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
3078 | sys_closedir(local_dir); |
55
4cb389452a44
replaced readdir_r with readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
3079 | |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3080 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3081 | free(local_path); |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3082 | free(p); |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3083 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3084 | |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3085 | return resources; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3086 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
3087 | |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3088 | |
573
b8f798d240ab
change local_resource_new signature
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
570
diff
changeset
|
3089 | 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
|
3090 | 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
|
3091 | SYS_STAT s; |
574
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3092 | if(sys_lstat(file_path, &s)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
3093 | log_error("Cannot stat file %s: %s\n", file_path, strerror(errno)); |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3094 | free(file_path); |
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3095 | return NULL; |
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3096 | } |
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3097 | |
574
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3098 | LocalResource *res = calloc(1, sizeof(LocalResource)); |
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3099 | res->mode = s.st_mode & 07777; |
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3100 | res->uid = s.st_uid; |
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3101 | res->gid = s.st_gid; |
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3102 | res->last_modified = s.st_mtime; |
810
baf199df500e
don't store directories with a trailing path separator in the sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
799
diff
changeset
|
3103 | res->path = strdup(path); |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3104 | if(!S_ISDIR(s.st_mode)) { |
810
baf199df500e
don't store directories with a trailing path separator in the sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
799
diff
changeset
|
3105 | //res->path = strdup(path); |
64
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3106 | res->size = s.st_size; |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3107 | } else { |
810
baf199df500e
don't store directories with a trailing path separator in the sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
799
diff
changeset
|
3108 | //res->path = util_concat_path(path, "/"); |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
3109 | res->isdirectory = 1; |
574
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3110 | } |
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3111 | |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3112 | int skip_file = 0; |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3113 | if(SYS_ISLINK(file_path, s)) { |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3114 | char *lnkbuf = sys_readlink(file_path, &s); |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3115 | #ifdef SYS_LINK_EXT |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3116 | // on Windows, we interpret .lnk files as links |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3117 | // we dont want resource names with this extension |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3118 | // and possibly sync this to other operating systems |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3119 | // therefore we remove the .lnk extension from the file name |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3120 | // change res->path |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3121 | // we only do this, if there isn't any other file with this name |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3122 | cxstring fpath = cx_str(file_path); |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3123 | cxstring rpath = cx_str(path); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3124 | // remove last 4 chars (.lnk) |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3125 | cxmutstr new_file_path = cx_strdup(cx_strsubsl(fpath, 0 , fpath.length-4)); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3126 | // check if a file with this name exists |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3127 | SYS_STAT nfp_s; |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3128 | if(!sys_stat(new_file_path.ptr, &nfp_s)) { |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3129 | // we can't upload the link without the file extension, because |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3130 | // there is another file with this name |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3131 | free(lnkbuf); |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3132 | lnkbuf = NULL; |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3133 | } else { |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3134 | cxmutstr new_path = cx_strdup(cx_strsubsl(rpath, 0, rpath.length-4)); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3135 | res->local_path = res->path; |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3136 | res->path = new_path.ptr; // remove .lnk ext from resource path |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3137 | } |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3138 | free(new_file_path.ptr); |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3139 | #endif |
574
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3140 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3141 | if(lnkbuf) { |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3142 | // readlink successful |
576
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3143 | char *normalized = NULL; |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3144 | if(!util_path_isabsolut(lnkbuf)) { |
576
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3145 | char *link_parent = util_parent_path(res->path); |
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3146 | 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
|
3147 | 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
|
3148 | normalized = util_path_normalize(link); |
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3149 | free(abs_link_parent); |
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3150 | free(link_parent); |
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3151 | free(link); |
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3152 | } else { |
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3153 | normalized = util_path_normalize(lnkbuf); |
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3154 | } |
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3155 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3156 | char *dirpath = util_path_normalize(dir->path); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3157 | int isintern = util_path_isrelated(dirpath, normalized); |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3158 | |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3159 | |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3160 | if(SYNC_SYMLINK(dir) && isintern) { |
576
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3161 | // 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
|
3162 | 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
|
3163 | res->link_target = rel; |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3164 | } else { |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3165 | #ifndef SYS_LINK_EXT // if not windows |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3166 | SYS_STAT targetstat; |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3167 | if(!sys_stat(file_path, &targetstat)) { |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3168 | res->isdirectory = S_ISDIR(targetstat.st_mode); |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3169 | |
644
a38b15061848
refactore symlink config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
643
diff
changeset
|
3170 | int nofollowextern = (dir->symlink & SYNC_SYMLINK_IGNORE_EXTERN) == SYNC_SYMLINK_IGNORE_EXTERN; |
a38b15061848
refactore symlink config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
643
diff
changeset
|
3171 | int nofollowintern = (dir->symlink & SYNC_SYMLINK_IGNORE_INTERN) == SYNC_SYMLINK_IGNORE_INTERN; |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3172 | if(isintern && nofollowintern) { |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3173 | skip_file = TRUE; |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3174 | } else if(!isintern && nofollowextern) { |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3175 | skip_file = TRUE; |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3176 | } |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3177 | } else { |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3178 | // can't access target, therefore we skip this link |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3179 | skip_file = TRUE; |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3180 | } |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3181 | #endif |
576
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3182 | } |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3183 | free(dirpath); |
576
62cc92445234
store relative link in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
574
diff
changeset
|
3184 | free(normalized); |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3185 | free(lnkbuf); |
574
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3186 | } |
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3187 | } |
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3188 | |
643
5b8643cf0a2f
implement hash push strategy and add some tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
639
diff
changeset
|
3189 | if(!res->isdirectory && dir->push_strategy == PUSH_STRATEGY_HASH) { |
5b8643cf0a2f
implement hash push strategy and add some tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
639
diff
changeset
|
3190 | res->hash = util_file_hash(file_path); |
5b8643cf0a2f
implement hash push strategy and add some tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
639
diff
changeset
|
3191 | } |
5b8643cf0a2f
implement hash push strategy and add some tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
639
diff
changeset
|
3192 | |
574
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3193 | free(file_path); |
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3194 | |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3195 | if(skip_file) { |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3196 | local_resource_free(res); |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3197 | res = NULL; |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3198 | } |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3199 | |
574
c36eddf167a8
read link on LocalResource creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
573
diff
changeset
|
3200 | return res; |
53
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3201 | } |
ddc4efc9b0f8
added usage info and some options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
52
diff
changeset
|
3202 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3203 | char* local_resource_path(LocalResource *res) { |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3204 | return res->local_path ? res->local_path : res->path; |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3205 | } |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3206 | |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
3207 | 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
|
3208 | SyncDirectory *dir, |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
3209 | SyncDatabase *db, |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
3210 | LocalResource *res, |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3211 | CxMap *svrres, |
445
c525f049c8b7
renames dav-sync -D option to -R
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
444
diff
changeset
|
3212 | 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
|
3213 | DavBool restore_modified) |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
3214 | { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3215 | LocalResource *db_res = cxMapGet(db->resources, cx_hash_key_str(res->path)); |
366
5228b912c925
adds technical foundation to just push tag updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
363
diff
changeset
|
3216 | res->tags_updated = 0; |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3217 | if(db_res) { |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3218 | // copy some metadata from db_res, that localscan does not deliver |
366
5228b912c925
adds technical foundation to just push tag updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
363
diff
changeset
|
3219 | res->tags_updated = db_res->tags_updated; |
64
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3220 | if(db_res->etag) { |
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3221 | res->etag = strdup(db_res->etag); |
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3222 | } |
370
ab9c5afdc243
pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
369
diff
changeset
|
3223 | if(db_res->tags_hash) { |
ab9c5afdc243
pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
369
diff
changeset
|
3224 | res->tags_hash = strdup(db_res->tags_hash); |
ab9c5afdc243
pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
369
diff
changeset
|
3225 | } |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3226 | if(db_res->remote_tags_hash) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3227 | 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
|
3228 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3229 | if(db_res->xattr_hash) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3230 | 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
|
3231 | } |
638
b3077bdb3d77
fix hash based conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
633
diff
changeset
|
3232 | if(db_res->hash) { |
b3077bdb3d77
fix hash based conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
633
diff
changeset
|
3233 | res->prev_hash = strdup(db_res->hash); |
b3077bdb3d77
fix hash based conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
633
diff
changeset
|
3234 | } |
686
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3235 | if(db_res->link_target) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3236 | res->link_target_db = db_res->link_target; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3237 | } |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
3238 | res->versioncontrol = db_res->versioncontrol; |
64
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3239 | |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3240 | // if the resource is splitted, copy the part info to the new |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3241 | // LocalResource obj, because we need it later |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3242 | if(db_res->parts) { |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3243 | local_resource_copy_parts(db_res, res); |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3244 | } |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3245 | |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3246 | // check if the file must be restored on the server |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3247 | if(svrres) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3248 | DavResource *remote = cxMapGet(svrres, cx_hash_key_str(res->path)); |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3249 | if(restore_removed && !remote) { |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3250 | return 1; |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3251 | } |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3252 | if(!res->isdirectory && restore_modified && remote) { |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3253 | char *etag = dav_get_string_property(remote, "D:getetag"); |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3254 | if(!etag || (db_res->etag && strcmp(etag, db_res->etag))) { |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3255 | res->restore = TRUE; |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3256 | return 1; |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3257 | } |
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3258 | } |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3259 | } |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3260 | |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3261 | // check if metadata has changed |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3262 | // metadata are tags, mode, owner, xattr |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3263 | // set res->metadata_updated to 1 in case any metadata has changed |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3264 | |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3265 | // check if tags have changed |
668
6df5ebb00841
fix detection of changed tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
667
diff
changeset
|
3266 | if(db_res->tags_updated) { |
6df5ebb00841
fix detection of changed tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
667
diff
changeset
|
3267 | res->tags_updated = 1; |
6df5ebb00841
fix detection of changed tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
667
diff
changeset
|
3268 | res->metadata_updated = 1; |
6df5ebb00841
fix detection of changed tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
667
diff
changeset
|
3269 | } else if(dir->tagconfig && dir->tagconfig->detect_changes ) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3270 | CxBuffer *tags = sync_get_file_tag_data(dir, res); |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3271 | if(tags) { |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3272 | if(db_res->tags_hash) { |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3273 | 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
|
3274 | 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
|
3275 | res->tags_updated = 1; |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3276 | } |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3277 | free(hash); |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3278 | } else { |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3279 | res->tags_updated = 1; |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3280 | } |
370
ab9c5afdc243
pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
369
diff
changeset
|
3281 | } else if(db_res->tags_hash) { |
ab9c5afdc243
pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
369
diff
changeset
|
3282 | 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
|
3283 | } |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3284 | res->metadata_updated = res->tags_updated; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3285 | } |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3286 | |
662
ab34fc9ecf1d
fix mtime sync bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
661
diff
changeset
|
3287 | // check if mtime has changed |
ab34fc9ecf1d
fix mtime sync bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
661
diff
changeset
|
3288 | if((dir->metadata & FINFO_MTIME) == FINFO_MTIME) { |
ab34fc9ecf1d
fix mtime sync bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
661
diff
changeset
|
3289 | if(db_res->last_modified != res->last_modified) { |
ab34fc9ecf1d
fix mtime sync bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
661
diff
changeset
|
3290 | res->finfo_updated = 1; |
ab34fc9ecf1d
fix mtime sync bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
661
diff
changeset
|
3291 | res->metadata_updated = 1; |
ab34fc9ecf1d
fix mtime sync bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
661
diff
changeset
|
3292 | } |
ab34fc9ecf1d
fix mtime sync bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
661
diff
changeset
|
3293 | } |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3294 | // check if mode has changed |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
536
diff
changeset
|
3295 | 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
|
3296 | if(db_res->mode != res->mode) { |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3297 | res->finfo_updated = 1; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3298 | res->metadata_updated = 1; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3299 | } |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3300 | } |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3301 | // check if owner has changed |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
536
diff
changeset
|
3302 | 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
|
3303 | 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
|
3304 | res->finfo_updated = 1; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3305 | res->metadata_updated = 1; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3306 | } |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3307 | } |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3308 | |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3309 | // check if xattr have changed |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
536
diff
changeset
|
3310 | if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) { |
614
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3311 | char *path = create_local_path(dir, local_resource_path(db_res)); |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
3312 | XAttributes *xattr = file_get_attributes(path, (xattr_filter_func)xattr_filter, dir); |
524
d53fd1006485
store hash of remote xattr and tags in sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
523
diff
changeset
|
3313 | // 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
|
3314 | if((db_res->xattr_hash && !xattr) || |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3315 | (!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
|
3316 | (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
|
3317 | { |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3318 | res->metadata_updated = 1; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3319 | res->xattr_updated = 1; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3320 | res->xattr = xattr; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3321 | } else if(xattr) { |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3322 | xattributes_free(xattr); |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
3323 | } |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3324 | } |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3325 | |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3326 | // check if the content of the file was modified |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3327 | // in case of links, just check if the link target has changed |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3328 | // for normal files, check last modified and size |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3329 | // or compare content hashes |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
3330 | 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
|
3331 | res->link_updated = 1; |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3332 | } else { |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3333 | if(db_res->hash && res->hash) { |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3334 | // we already have hashes |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3335 | if(!strcmp(db_res->hash, res->hash)) { |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3336 | return 0; // hashes equal -> file content unchanged |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3337 | } |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3338 | } else if( |
615
ab669d21f82a
add missing isdirectory tag in db on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
3339 | db_res->last_modified == res->last_modified && |
ab669d21f82a
add missing isdirectory tag in db on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
3340 | db_res->size == res->size && |
ab669d21f82a
add missing isdirectory tag in db on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
614
diff
changeset
|
3341 | db_res->isdirectory == res->isdirectory) |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3342 | { |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3343 | // mtime and size unchanged, content also likely unchanged |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3344 | return 0; |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
3345 | } else if(SYNC_HASHING(dir)) { |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3346 | // res->hash missing (see above) |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3347 | char *local_path = util_concat_path(dir->path, local_resource_path(res)); |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3348 | res->hash = util_file_hash(local_path); |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3349 | free(local_path); |
650
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
3350 | |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
3351 | // check if the content has really changed |
14e7101d7604
fix some hash based conflict resolution bugs and add tests for it
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
649
diff
changeset
|
3352 | if(res->hash && db_res->hash && !strcmp(res->hash, db_res->hash)) { |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3353 | return 0; |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3354 | } |
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
3355 | } |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3356 | } |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3357 | } else { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3358 | res->tags_updated = 1; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3359 | res->finfo_updated = 1; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3360 | res->xattr_updated = 1; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3361 | res->metadata_updated = 1; |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
3362 | res->isnew = 1; |
64
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3363 | } |
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3364 | return 1; |
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3365 | } |
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3366 | |
220
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3367 | int remote_resource_is_changed( |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3368 | DavSession *sn, |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3369 | SyncDirectory *dir, |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3370 | SyncDatabase *db, |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3371 | DavResource *remote, |
639
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3372 | LocalResource *res, |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3373 | DavBool *equal) |
220
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3374 | { |
639
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3375 | if(equal) { |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3376 | *equal = FALSE; |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3377 | } |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3378 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3379 | DavPropName properties[] = { |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3380 | {"DAV:", "getetag"}, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3381 | {DAV_NS, "version-collection"}, |
541
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
3382 | {DAV_NS, "content-hash"}, |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
3383 | {DAV_NS, "split" }, |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
3384 | {DAV_PROPS_NS, "tags"}, |
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
3385 | {DAV_PROPS_NS, "link" } |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3386 | }; |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
3387 | 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
|
3388 | |
444
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
3389 | if(res->restore) { |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
3390 | return 0; |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
3391 | } |
761dc4867208
adds dav-sync options for restoring deleted or modified files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
417
diff
changeset
|
3392 | |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3393 | if(remote->iscollection && !res->parts) { |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3394 | return 1; |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3395 | } |
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3396 | |
686
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3397 | char *link = dav_get_string_property_ns(remote, DAV_PROPS_NS, "link"); |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3398 | |
220
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3399 | int ret = 0; |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3400 | if(err == 0) { |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
3401 | 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
|
3402 | char *hash = sync_get_content_hash(remote); |
639
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3403 | |
686
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3404 | if(res->link_target_db || link) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3405 | ret = nullstrcmp(res->link_target_db, link); |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3406 | if(ret && equal) { |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3407 | *equal = !nullstrcmp(res->link_target, link); |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3408 | } |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3409 | return ret; |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3410 | } |
ab159748055c
add more symlink tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
685
diff
changeset
|
3411 | |
639
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3412 | if(hash && res->hash && equal) { |
649
0f4c59ac8c74
implement hash based conflict resolution in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
648
diff
changeset
|
3413 | // if requested, check if the local and remote res are equal |
639
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3414 | if(!strcmp(hash, res->hash)) { |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3415 | *equal = TRUE; |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3416 | return 0; |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3417 | } |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3418 | } |
928a77ebe0b9
fix that file uploads are tried, when the content on the server is equal to the local file content (with enabled hashing)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
638
diff
changeset
|
3419 | |
638
b3077bdb3d77
fix hash based conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
633
diff
changeset
|
3420 | if(hash && res->prev_hash) { |
b3077bdb3d77
fix hash based conflict detection
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
633
diff
changeset
|
3421 | if(strcmp(hash, res->prev_hash)) { |
541
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
3422 | ret = 1; |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
3423 | } |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
3424 | } 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
|
3425 | // 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
|
3426 | 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
|
3427 | } else if(etag) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3428 | cxstring e = cx_str(etag); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3429 | if(cx_strprefix(e, CX_STR("W/"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3430 | e = cx_strsubs(e, 2); |
220
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3431 | } |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3432 | if(strcmp(e.ptr, res->etag)) { |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3433 | ret = 1; |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3434 | } |
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
|
3435 | } 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
|
3436 | // 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
|
3437 | 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
|
3438 | } |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3439 | } |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3440 | return ret; |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3441 | } |
f1b3873a6525
added conflict detection to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
219
diff
changeset
|
3442 | |
614
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3443 | int local_resource_load_metadata(SyncDirectory *dir, LocalResource *res) { |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3444 | // currently only xattr needed |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3445 | if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) { |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3446 | char *path = create_local_path(dir, local_resource_path(res)); |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
3447 | XAttributes *xattr = file_get_attributes(path, (xattr_filter_func)xattr_filter, dir); |
614
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3448 | res->xattr = xattr; |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3449 | free(path); |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3450 | } |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3451 | |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3452 | return 0; |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3453 | } |
e72d2b99b0f6
fix xattr not synced for new files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
613
diff
changeset
|
3454 | |
621
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3455 | void local_resource_set_etag(LocalResource *local, const char *etag) { |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3456 | // free old etag |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3457 | if(local->etag) { |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3458 | free(local->etag); |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3459 | } |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3460 | |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3461 | if(!etag) { |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3462 | local->etag = NULL; |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3463 | return; |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3464 | } |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3465 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3466 | cxstring e = cx_str(etag); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3467 | if(cx_strprefix(e, CX_STR("W/"))) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3468 | e = cx_strsubs(e, 2); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3469 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3470 | local->etag = cx_strdup(e).ptr; |
621
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3471 | } |
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
3472 | |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3473 | char* resource_local_path(DavResource *res) { |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
3474 | cxstring path = cx_str(res->path); |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
3475 | if(path.length > 0 && path.ptr[path.length-1] == '/') { |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
3476 | path.length--; |
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
3477 | } |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3478 | #ifdef SYS_LINK_EXT |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3479 | // on Windows, add .lnk extension to links |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3480 | if(dav_get_property_ns(res, DAV_PROPS_NS, "link")) { |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
3481 | return cx_asprintf("%.*s%s", (int)path.length, path.ptr, SYS_LINK_EXT).ptr; |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3482 | } else { |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3483 | // not a link |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
3484 | return cx_strdup(path).ptr; |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3485 | } |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3486 | #else |
812
5fe4453fc025
make sure a LocalResource path has never a trailing path separator, fixes multiple dav-sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
810
diff
changeset
|
3487 | return cx_strdup(path).ptr; |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3488 | #endif |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3489 | } |
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3490 | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3491 | 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
|
3492 | size_t local_blocksize = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3493 | if(local->blocksize < 0) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3494 | // file splitting disabled |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3495 | return 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3496 | } else if(local->blocksize > 0) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3497 | local_blocksize = (size_t)local->blocksize; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3498 | } else if(dir->splitconfig) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3499 | CxIterator i = cxListIterator(dir->splitconfig); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3500 | cx_foreach(SplitConfig *, sc, i) { |
648
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
3501 | if(sc->filter) { |
fefe4b6f1048
change split config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
646
diff
changeset
|
3502 | if(res_matches_filter(sc->filter, local->path)) { |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3503 | continue; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3504 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3505 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3506 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3507 | if(sc->minsize > 0) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3508 | if(filesize < sc->minsize) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3509 | continue; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3510 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3511 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3512 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3513 | local_blocksize = sc->blocksize; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3514 | break; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3515 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3516 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3517 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3518 | size_t svr_blocksize = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3519 | 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
|
3520 | if(svr_blocksize_str) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3521 | uint64_t i = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3522 | 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
|
3523 | svr_blocksize = (size_t)i; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3524 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3525 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3526 | |
681
3320429502cf
fix some split bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
3527 | if(local_blocksize > 0 && svr_blocksize > 0 && local_blocksize != svr_blocksize) { |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3528 | 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
|
3529 | return svr_blocksize; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3530 | } else if(local_blocksize > 0) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3531 | return local_blocksize; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3532 | } else if(svr_blocksize > 0) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3533 | return svr_blocksize; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3534 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3535 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3536 | return 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3537 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3538 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
3539 | |
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
|
3540 | 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
|
3541 | 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
|
3542 | 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
|
3543 | 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
|
3544 | 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
|
3545 | } 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
|
3546 | 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
|
3547 | } 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
|
3548 | 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
|
3549 | } |
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
|
3550 | } |
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
|
3551 | |
725
de3b2bb46492
fix outgoing list sort
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
3552 | int resource_path_cmp(LocalResource *res1, LocalResource *res2, void *n) { |
de3b2bb46492
fix outgoing list sort
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
3553 | return strcmp(res1->path, res2->path); |
de3b2bb46492
fix outgoing list sort
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
3554 | } |
de3b2bb46492
fix outgoing list sort
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
3555 | |
de3b2bb46492
fix outgoing list sort
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
724
diff
changeset
|
3556 | |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3557 | 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
|
3558 | 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
|
3559 | if(!vcol_href) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3560 | return NULL; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3561 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3562 | 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
|
3563 | if(!vcol) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3564 | return NULL; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3565 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3566 | |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3567 | |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3568 | if(dav_load_prop(vcol, defprops, numdefprops)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
3569 | log_resource_error(res->session, vcol->path); |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3570 | dav_resource_free(vcol); |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3571 | return NULL; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3572 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3573 | |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3574 | DavResource *ret = NULL; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3575 | DavResource *child = vcol->children; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3576 | while(child) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3577 | DavResource *next = child->next; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3578 | if(!strcmp(child->name, version)) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3579 | ret = child; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3580 | } else { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3581 | dav_resource_free(child); |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3582 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3583 | child = next; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3584 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3585 | dav_resource_free(vcol); |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3586 | |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3587 | return ret; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3588 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3589 | |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3590 | // 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
|
3591 | DavResource* versioning_deltav_find(DavResource *res, const char *version) { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
3592 | DavResource *list = dav_versiontree(res, "D:getetag,idav:status,idav:split,idavprops:link,idavprops:finfo,idavprops:xattributes,idavprops:tags"); |
533
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3593 | DavResource *ret = NULL; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3594 | while(list) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3595 | DavResource *next = list->next; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3596 | if(!ret) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3597 | 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
|
3598 | if(vname && !strcmp(vname, version)) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3599 | ret = list; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3600 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3601 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3602 | if(list != ret) { |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3603 | dav_resource_free(list); |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3604 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3605 | list = next; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3606 | } |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3607 | return ret; |
5b9f20aa88c2
adds option to restore previous file versions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
532
diff
changeset
|
3608 | } |
64
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
3609 | |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3610 | int sync_set_status(DavResource *res, char *status) { |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3611 | 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
|
3612 | 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
|
3613 | int ret = dav_store(resource); |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3614 | dav_resource_free(resource); |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3615 | return ret; |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3616 | } |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3617 | |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3618 | int sync_remove_status(DavResource *res) { |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3619 | 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
|
3620 | dav_remove_property(resource, "idav:status"); |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3621 | int ret = dav_store(resource); |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3622 | dav_resource_free(resource); |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3623 | return ret; |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3624 | } |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
3625 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3626 | 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
|
3627 | int ret = 0; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3628 | |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
3629 | DavXmlNode *fileinfo = dav_get_property_ns(res, DAV_PROPS_NS, "finfo"); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3630 | if(fileinfo) { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3631 | FileInfo f; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3632 | finfo_get_values(fileinfo, &f); |
646
37a8bfae995e
change metadata config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
644
diff
changeset
|
3633 | if((dir->metadata & FINFO_MTIME) == FINFO_MTIME && f.date_set) { |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3634 | // TODO: implement on windows |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3635 | #ifndef _WIN32 |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3636 | // set mtime |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3637 | struct utimbuf t; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3638 | t.actime = f.last_modified; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3639 | t.modtime = f.last_modified; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3640 | if(utime(path, &t)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
3641 | log_error("utime failed for file: %s : %s\n", path, strerror(errno)); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3642 | ret = 1; |
763
fc24d1d1d695
fix dav-sync pull not storing finfo metadata correctly in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
762
diff
changeset
|
3643 | } else { |
fc24d1d1d695
fix dav-sync pull not storing finfo metadata correctly in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
762
diff
changeset
|
3644 | local->last_modified = f.last_modified; |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3645 | } |
789
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3646 | #else |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3647 | local->last_modified = 0; |
378b5ab86f77
add new build system for windows
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
3648 | #endif |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3649 | } |
539
8deb52292c99
fixes more if statements and some warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
536
diff
changeset
|
3650 | 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
|
3651 | // set mode |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3652 | if(chmod(path, f.mode)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
3653 | log_error("chmod failed for file: %s : %s\n", path, strerror(errno)); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3654 | ret = 1; |
763
fc24d1d1d695
fix dav-sync pull not storing finfo metadata correctly in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
762
diff
changeset
|
3655 | } else { |
fc24d1d1d695
fix dav-sync pull not storing finfo metadata correctly in the database
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
762
diff
changeset
|
3656 | local->mode = f.mode; |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3657 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3658 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3659 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3660 | |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3661 | if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) { |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3662 | DavXmlNode *xattr_prop = dav_get_property_ns(res, DAV_PROPS_NS, "xattributes"); |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3663 | XAttributes *xattr = NULL; |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3664 | if(xattr_prop) { |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3665 | xattr = xml_get_attributes(xattr_prop); |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3666 | } |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3667 | if(!sync_store_xattr(dir, path, xattr)) { |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3668 | if(local->xattr_hash) { |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3669 | free(local->xattr_hash); |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3670 | } |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3671 | local->xattr_hash = xattr ? xattr->hash : NULL; |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3672 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3673 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3674 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3675 | 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
|
3676 | ret = 1; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3677 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3678 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3679 | return ret; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3680 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3681 | |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3682 | int sync_store_xattr(SyncDirectory *dir, const char *path, XAttributes *xattr) { |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3683 | // create a map of all currently available local attributes |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3684 | ssize_t nelm = 0; |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3685 | char **list = xattr_list(path, &nelm); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3686 | CxMap *current_xattr = NULL; |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3687 | if(nelm > 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3688 | current_xattr = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, nelm + 8); |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3689 | for(int i=0;i<nelm;i++) { |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3690 | // use the xattr name as key and store any value |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3691 | cxMapPut(current_xattr, cx_hash_key_str(list[i]), list[i]); |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3692 | } |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3693 | } |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3694 | if(list) { |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3695 | free(list); |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3696 | } |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3697 | |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3698 | // store extended attributes |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3699 | size_t nattr = xattr ? xattr->nattr : 0; |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3700 | for(int i=0;i<nattr;i++) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3701 | cxmutstr value = xattr->values[i]; |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3702 | if(xattr_set(path, xattr->names[i], value.ptr, value.length)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
3703 | log_error( |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3704 | "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
|
3705 | xattr->names[i], |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3706 | path); |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3707 | } |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3708 | |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3709 | if(current_xattr) { |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3710 | // to detect which xattributes are removed, we remove all new |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3711 | // attributes from the map and all remaining attributes must |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3712 | // be removed with xattr_remove |
852 | 3713 | char *removed_value = NULL; |
3714 | cxMapRemoveAndGet(current_xattr, cx_hash_key_str(xattr->names[i]), &removed_value); | |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
3715 | if(removed_value) { |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
3716 | free(removed_value); |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3717 | } |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3718 | } |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3719 | } |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3720 | |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3721 | if(current_xattr) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3722 | CxIterator i = cxMapIteratorValues(current_xattr); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3723 | cx_foreach(char *, value, i) { |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3724 | (void)xattr_remove(path, value); // don't print error |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3725 | free(value); |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3726 | } |
852 | 3727 | cxMapFree(current_xattr); |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3728 | } |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
3729 | |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3730 | return 0; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3731 | } |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3732 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3733 | 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
|
3734 | if(!dir->tagconfig) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3735 | return 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3736 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3737 | |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
3738 | char *remote_hash = NULL; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3739 | CxList *tags = NULL; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3740 | if(dir->tagconfig) { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
3741 | DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3742 | if(tagsprop) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3743 | tags = parse_dav_xml_taglist(tagsprop); |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
3744 | remote_hash = create_tags_hash(tags); |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3745 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3746 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3747 | |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3748 | DavBool store_tags = FALSE; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3749 | DavBool tags_changed = FALSE; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3750 | CxList *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
|
3751 | if(tags_changed) { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3752 | switch(dir->tagconfig->conflict) { |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3753 | case TAG_NO_CONFLICT: { |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3754 | store_tags = TRUE; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3755 | break; |
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3756 | } |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3757 | case TAG_KEEP_LOCAL: { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3758 | store_tags = FALSE; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3759 | break; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3760 | } |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3761 | case TAG_KEEP_REMOTE: { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3762 | store_tags = TRUE; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3763 | local->tags_updated = FALSE; |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
3764 | break; |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3765 | } |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3766 | case TAG_MERGE: { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3767 | CxList *new_tags = merge_tags(local_tags, tags); |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3768 | // TODO: free tags and local_tags |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3769 | tags = new_tags; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3770 | store_tags = TRUE; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3771 | // 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
|
3772 | local->tags_updated = TRUE; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3773 | break; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3774 | } |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3775 | } |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3776 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3777 | if(!compare_taglists(tags, local_tags)) { |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3778 | store_tags = TRUE; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3779 | } |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3780 | // TODO: free local_tags |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3781 | } |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3782 | |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3783 | if(!store_tags) { |
675
a8117c4feaad
fix sync_store_metadata
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
672
diff
changeset
|
3784 | nullfree(local->remote_tags_hash); |
a8117c4feaad
fix sync_store_metadata
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
672
diff
changeset
|
3785 | local->remote_tags_hash = remote_hash; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3786 | return 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3787 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3788 | |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3789 | int ret = sync_store_tags_local(dir, local, path, tags); |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
3790 | if(!ret) { |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
3791 | if(local->remote_tags_hash) { |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
3792 | free(local->remote_tags_hash); |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
3793 | } |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
3794 | local->remote_tags_hash = remote_hash; |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
3795 | } |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3796 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3797 | // TODO: free stuff |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3798 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3799 | return ret; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3800 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3801 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3802 | int sync_store_tags_local(SyncDirectory *dir, LocalResource *local, const char *path, CxList *tags) { |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3803 | int ret = 0; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3804 | if(dir->tagconfig->store == TAG_STORE_XATTR) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3805 | CxBuffer *data = NULL; |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3806 | if(tags) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3807 | switch(dir->tagconfig->local_format) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3808 | default: break; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3809 | case TAG_FORMAT_TEXT: { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3810 | data = create_text_taglist(tags); |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3811 | break; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3812 | } |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3813 | case TAG_FORMAT_CSV: { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3814 | data = create_csv_taglist(tags); |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3815 | break; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3816 | } |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3817 | case TAG_FORMAT_MACOS: { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3818 | data = create_macos_taglist(tags); |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3819 | break; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3820 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3821 | } |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3822 | |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3823 | if(data) { |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
3824 | 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
|
3825 | int update = 1; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3826 | if(local) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3827 | 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
|
3828 | //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
|
3829 | } else { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3830 | update = 0; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3831 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3832 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3833 | if(update) { |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
3834 | 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
|
3835 | if(local) { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3836 | if(local->tags_hash) { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3837 | free(local->tags_hash); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3838 | local->tags_hash = NULL; |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3839 | } |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3840 | local->tags_hash = data_hash; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3841 | } |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3842 | } else { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3843 | free(data_hash); |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
3844 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3845 | cxBufferFree(data); |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3846 | } else { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3847 | ret = -1; |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
3848 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3849 | } else { |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3850 | if(local) { |
526
e3c0440bd599
adds metadata support to dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
525
diff
changeset
|
3851 | //printf("update: %s\n", local->path); |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3852 | } |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
3853 | // ignore errors on remove |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
3854 | 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
|
3855 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3856 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3857 | |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
3858 | if(!ret && local) { |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
3859 | local->tags_updated = 0; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
3860 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
3861 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3862 | return ret; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3863 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3864 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3865 | CxBuffer* sync_get_file_tag_data(SyncDirectory *dir, LocalResource *res) { |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3866 | if(!dir->tagconfig) { |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3867 | return NULL; |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3868 | } |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
3869 | if(res->cached_tags) { |
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
3870 | return res->cached_tags; |
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
3871 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3872 | CxBuffer *buf = NULL; |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3873 | 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
|
3874 | ssize_t tag_length = 0; |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
3875 | char *local_path = create_local_path(dir, local_resource_path(res)); |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3876 | char* tag_data = xattr_get( |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3877 | local_path, |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3878 | dir->tagconfig->xattr_name, |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3879 | &tag_length); |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3880 | free(local_path); |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3881 | |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3882 | if(tag_length > 0) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3883 | buf = cxBufferCreate(tag_data, (size_t)tag_length, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS); |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3884 | 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
|
3885 | } |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3886 | } |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
3887 | res->cached_tags = buf; |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3888 | return buf; |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3889 | } |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3890 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3891 | CxList* 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
|
3892 | if(changed) *changed = FALSE; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3893 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3894 | CxList *tags = NULL; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3895 | |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3896 | if(!res) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3897 | return NULL; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3898 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
3899 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3900 | if(!dir->tagconfig) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3901 | return NULL; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3902 | } |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3903 | if(changed && res->tags_updated) { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3904 | *changed = TRUE; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
3905 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3906 | if(dir->tagconfig->store == TAG_STORE_XATTR) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
3907 | CxBuffer *tag_buf = res->cached_tags ? |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3908 | res->cached_tags : |
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3909 | 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
|
3910 | |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3911 | if(tag_buf) { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3912 | 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
|
3913 | if(res->tags_hash) { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3914 | 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
|
3915 | *changed = TRUE; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3916 | } |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3917 | free(res->tags_hash); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
3918 | res->tags_hash = NULL; |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3919 | } else { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3920 | if(changed) *changed = TRUE; |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3921 | } |
618
4b34d12cf211
exclude tag xattr from xattribute sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
617
diff
changeset
|
3922 | if(newhash) { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3923 | *newhash = new_hash; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3924 | } else { |
619
1d20a6cab2e5
fix free in sync_get_file_tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
618
diff
changeset
|
3925 | free(new_hash); |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3926 | } |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3927 | |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3928 | switch(dir->tagconfig->local_format) { |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3929 | default: break; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3930 | case TAG_FORMAT_TEXT: { |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3931 | 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
|
3932 | break; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3933 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3934 | case TAG_FORMAT_CSV: { |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3935 | 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
|
3936 | break; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3937 | } |
363
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
3938 | case TAG_FORMAT_MACOS: { |
367
4a6a59f89f9f
adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
366
diff
changeset
|
3939 | 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
|
3940 | break; |
e9ed8e130ccf
adds support for macos file tags
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
361
diff
changeset
|
3941 | } |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3942 | } |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
3943 | res->cached_tags = tag_buf; |
368
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3944 | } else if(res->tags_hash) { |
11797f33bc24
adds more tag config options
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
367
diff
changeset
|
3945 | if(changed) *changed = TRUE; |
361
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3946 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3947 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3948 | |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3949 | return tags; |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3950 | } |
b6f2462ee055
adds xattr lib and tag support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
347
diff
changeset
|
3951 | |
478
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
460
diff
changeset
|
3952 | 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
|
3953 | int ret = fseek(f, offset, origin); |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
460
diff
changeset
|
3954 | return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK; |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
460
diff
changeset
|
3955 | } |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
460
diff
changeset
|
3956 | |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
460
diff
changeset
|
3957 | 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
|
3958 | size_t ret = fread(ptr, size, nmemb, f); |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
460
diff
changeset
|
3959 | return ret; |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
460
diff
changeset
|
3960 | } |
baa63fef5c5c
fixes redirects
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
460
diff
changeset
|
3961 | |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3962 | 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
|
3963 | unsigned char name_prefix[8]; |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3964 | memset(name_prefix, 0, 8); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3965 | dav_rand_bytes(name_prefix, 8); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3966 | 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
|
3967 | 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
|
3968 | 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
|
3969 | free(pre); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3970 | return w >= len; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3971 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3972 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3973 | #define VBEGIN_ERROR_MKCOL 1 |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3974 | #define VBEGIN_ERROR_MOVE 2 |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3975 | #define VBEGIN_ERROR_PROPPATCH 3 |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3976 | #define VBEGIN_ERROR_CHECKOUT 4 |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
3977 | int versioning_begin(SyncDirectory *dir, DavResource *res, int *exists, int *versionized) { |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3978 | int ret = 0; |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
3979 | *versionized = 0; |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3980 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
3981 | 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
|
3982 | DavResource *history_collection = dav_resource_new( |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3983 | res->session, |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3984 | dir->versioning->collection); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3985 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3986 | // 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
|
3987 | // 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
|
3988 | // 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
|
3989 | // 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
|
3990 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3991 | char *history_href = NULL; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3992 | 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
|
3993 | if(!vcol_path) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3994 | DavResource *history_res = NULL; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3995 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3996 | // 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
|
3997 | // 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
|
3998 | while(!history_res) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
3999 | char history_res_name[128]; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4000 | 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
|
4001 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4002 | history_res = dav_resource_new_child( |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4003 | res->session, |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4004 | history_collection, |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4005 | history_res_name); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4006 | if(dav_exists(history_res)) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4007 | dav_resource_free(history_res); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4008 | history_res = NULL; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4009 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4010 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4011 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4012 | history_res->iscollection = TRUE; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4013 | if(dav_create(history_res)) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4014 | dav_resource_free(history_res); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4015 | dav_resource_free(history_collection); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4016 | return VBEGIN_ERROR_MKCOL; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4017 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4018 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4019 | history_href = strdup(history_res->href); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4020 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4021 | dav_resource_free(history_res); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4022 | } else { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4023 | history_href = vcol_path; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4024 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4025 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4026 | // 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
|
4027 | DavResource *version_res = NULL; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4028 | while(!version_res) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4029 | char version_name[128]; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4030 | gen_random_name(version_name, 128); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4031 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4032 | 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
|
4033 | 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
|
4034 | free(href); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4035 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4036 | 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
|
4037 | 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
|
4038 | free(dest); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4039 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4040 | if(err) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4041 | dav_resource_free(version_res); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4042 | version_res = NULL; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4043 | 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
|
4044 | ret = VBEGIN_ERROR_MOVE; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4045 | break; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4046 | } |
584
7fb81fd429b2
fix that knowledge about resource existence was fucked up by versioning_begin
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
583
diff
changeset
|
4047 | } else { |
7fb81fd429b2
fix that knowledge about resource existence was fucked up by versioning_begin
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
583
diff
changeset
|
4048 | // tell the caller the resource does not exist anymore at |
7fb81fd429b2
fix that knowledge about resource existence was fucked up by versioning_begin
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
583
diff
changeset
|
4049 | // the original location |
7fb81fd429b2
fix that knowledge about resource existence was fucked up by versioning_begin
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
583
diff
changeset
|
4050 | *exists = 0; |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4051 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4052 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4053 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4054 | if(!ret) { |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4055 | *versionized = 1; |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4056 | |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4057 | 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
|
4058 | if(dav_store(version_res)) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4059 | ret = VBEGIN_ERROR_PROPPATCH; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4060 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4061 | dav_resource_free(version_res); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4062 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4063 | // 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
|
4064 | // 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
|
4065 | dav_set_string_property_ns( |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4066 | res, |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4067 | DAV_NS, |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4068 | VERSION_PATH_PROPERTY, |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4069 | history_href); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4070 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4071 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4072 | if(vcol_path != history_href) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4073 | free(history_href); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4074 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4075 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4076 | dav_resource_free(history_collection); |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4077 | } else if(dir->versioning->type == VERSIONING_DELTAV && res->exists){ |
492
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4078 | // DeltaV is so much easier :) |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4079 | if(dav_checkout(res)) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4080 | ret = VBEGIN_ERROR_CHECKOUT; |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4081 | } else { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4082 | *versionized = 1; |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4083 | } |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4084 | } |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4085 | |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4086 | return ret; |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4087 | } |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4088 | |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4089 | int versioning_init(SyncDirectory *dir, LocalResource *local, DavResource *res) { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4090 | if(local->versioncontrol) { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4091 | return 0; |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4092 | } |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4093 | int ret = 0; |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4094 | if(dir->versioning->type == VERSIONING_DELTAV) { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4095 | if(dav_versioncontrol(res)) { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4096 | ret = 1; |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4097 | } else { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4098 | local->versioncontrol = 1; |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4099 | } |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4100 | } |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4101 | return ret; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4102 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4103 | |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4104 | 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
|
4105 | if(dir->versioning->type == VERSIONING_DELTAV) { |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4106 | return dav_checkin(res); |
504
bf3695fee719
fix missiong return in versioning_end()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
503
diff
changeset
|
4107 | } else { |
bf3695fee719
fix missiong return in versioning_end()
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
503
diff
changeset
|
4108 | return 0; |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4109 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4110 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4111 | |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4112 | int versioning_delete_begin(SyncDirectory *dir, DavResource *res, int *exists, int *versionized) { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4113 | *versionized = 0; |
492
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4114 | if(dir->versioning->type == VERSIONING_SIMPLE) { |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4115 | versioning_begin(dir, res, exists, versionized); |
679
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4116 | } else { |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4117 | // versioning delete with DeltaV currently not supported in dav-sync |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4118 | *exists = 1; |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4119 | } |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4120 | return 0; |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4121 | } |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4122 | |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4123 | int versioning_delete_end(SyncDirectory *dir, DavResource *res) { |
522
46f96dcd6eab
adds metadata config element for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
521
diff
changeset
|
4124 | return 0; |
492
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4125 | } |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4126 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4127 | static void update_metadata_hashes(LocalResource *local, MetadataHashes hashes) { |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4128 | if(hashes.update_tags) { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4129 | if(local->tags_hash) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4130 | free(local->tags_hash); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
4131 | local->tags_hash = NULL; |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4132 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4133 | local->tags_hash = hashes.tags; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4134 | } |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4135 | if(hashes.update_tags_remote) { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4136 | if(local->remote_tags_hash) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4137 | free(local->remote_tags_hash); |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4138 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4139 | 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
|
4140 | } |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4141 | if(hashes.update_xattr) { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4142 | if(local->xattr_hash) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4143 | free(local->xattr_hash); |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4144 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4145 | local->xattr_hash = hashes.xattr; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4146 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4147 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4148 | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4149 | // 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
|
4150 | #define LOG10 log10 |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4151 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4152 | static CxList* upload_parts( |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4153 | LocalResource *local, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4154 | DavResource *res, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4155 | FILE *in, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4156 | uint64_t filesize, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4157 | size_t blocksize, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4158 | uint64_t *blockcount, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4159 | int *err) |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4160 | { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4161 | // 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
|
4162 | // 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
|
4163 | if(res->exists) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4164 | if(!res->iscollection) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4165 | if(dav_delete(res)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4166 | log_resource_error(res->session, res->path); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4167 | *err = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4168 | return NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4169 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4170 | res->exists = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4171 | 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
|
4172 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4173 | } else { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4174 | res->iscollection = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4175 | if(dav_create(res)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4176 | log_resource_error(res->session, res->path); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4177 | *err = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4178 | return NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4179 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4180 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4181 | res->exists = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4182 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4183 | if(!res->href) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4184 | // this should never happen, but just make sure it doesn't crash |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4185 | log_error("href is NULL\n"); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4186 | *err = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4187 | return NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4188 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4189 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4190 | char *buffer = malloc(blocksize); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4191 | if(!buffer) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4192 | 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
|
4193 | *err = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4194 | return NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4195 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4196 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4197 | // 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
|
4198 | // 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
|
4199 | int nblocks = filesize / blocksize; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4200 | 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
|
4201 | if(digits > 127) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4202 | log_error("Too many parts\n"); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4203 | *err = 1; |
659
51206020cfbe
fix: leaking buffer in upload_parts(), when we error out due to too many parts
Mike Becker <universe@uap-core.de>
parents:
650
diff
changeset
|
4204 | free(buffer); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4205 | return NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4206 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4207 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4208 | CxMap *updated_parts_map = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, (nblocks/2)+64); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
4209 | cxDefineDestructor(updated_parts_map, filepart_free); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4210 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4211 | int blockindex = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4212 | int uploaded_parts = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4213 | size_t r; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4214 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4215 | // 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
|
4216 | // part names |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4217 | 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
|
4218 | 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
|
4219 | |
541
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4220 | DAV_SHA_CTX *sha = dav_hash_init(); |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4221 | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4222 | 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
|
4223 | dav_hash_update(sha, buffer, r); |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4224 | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4225 | int upload_block = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4226 | 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
|
4227 | if(blockindex >= local->numparts) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4228 | // 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
|
4229 | upload_block = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4230 | } else { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4231 | FilePart part = local->parts[blockindex]; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4232 | 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
|
4233 | // no change |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4234 | free(block_hash); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4235 | block_hash = NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4236 | } else { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4237 | // block has changed |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4238 | upload_block = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4239 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4240 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4241 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4242 | if(upload_block) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4243 | char name[128]; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4244 | 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
|
4245 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4246 | 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
|
4247 | 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
|
4248 | free(part_href); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4249 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4250 | // upload part |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4251 | 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
|
4252 | if(dav_store(part)) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4253 | *err = 1; |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4254 | log_resource_error(res->session, part->path); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4255 | } else { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4256 | // successfully uploaded part |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4257 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4258 | // 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
|
4259 | // 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
|
4260 | 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
|
4261 | f->block = blockindex; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4262 | f->hash = block_hash; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4263 | cxMapPut(updated_parts_map, cx_hash_key_str(name), f); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4264 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4265 | dav_resource_free(part); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4266 | uploaded_parts++; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4267 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4268 | if(*err) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4269 | break; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4270 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4271 | blockindex++; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4272 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4273 | *blockcount = blockindex; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4274 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4275 | // restore flags |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4276 | res->session->flags = session_flags; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4277 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4278 | free(buffer); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4279 | if(*err) { |
852 | 4280 | cxMapFree(updated_parts_map); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4281 | return NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4282 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4283 | |
541
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4284 | // set content-hash |
558
1a9e6a5c1e79
fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents:
557
diff
changeset
|
4285 | 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
|
4286 | 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
|
4287 | 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
|
4288 | 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
|
4289 | |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4290 | // get etags from uploaded resources |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4291 | // also delete everything, that is not part of the file |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4292 | CxList *updated_parts = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4293 | 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
|
4294 | if(!parts) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4295 | log_resource_error(res->session, parts->path); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4296 | *err = 1; |
852 | 4297 | cxMapFree(updated_parts_map); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4298 | return NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4299 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4300 | DavResource *part = parts->children; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4301 | while(part) { |
852 | 4302 | FilePart *fp = NULL; |
4303 | cxMapRemoveAndGet(updated_parts_map, cx_hash_key_str(part->name), &fp); | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4304 | // 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
|
4305 | // 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
|
4306 | if(fp) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4307 | 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
|
4308 | if(etag) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4309 | 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
|
4310 | etag = etag + 2; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4311 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4312 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4313 | fp->etag = strdup(etag); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4314 | cxListAdd(updated_parts, fp); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4315 | } // 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
|
4316 | } else { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4317 | uint64_t name_partnum = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4318 | char *res_name = part->name; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4319 | 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
|
4320 | res_name++; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4321 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4322 | DavBool delete_part = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4323 | if(strlen(part->name) != digits) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4324 | delete_part = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4325 | } 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
|
4326 | if(name_partnum >= blockindex) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4327 | delete_part = 1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4328 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4329 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4330 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4331 | if(delete_part) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4332 | if(dav_delete(part)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4333 | log_resource_error(part->session, part->path); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4334 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4335 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4336 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4337 | part = part->next; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4338 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4339 | dav_resource_free_all(parts); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4340 | |
852 | 4341 | cxMapFree(updated_parts_map); |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4342 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4343 | *err = 0; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4344 | return updated_parts; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4345 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4346 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4347 | void update_parts(LocalResource *local, CxList *updates, uint64_t numparts) { |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4348 | 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
|
4349 | if(old_num > numparts) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4350 | // free old parts |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4351 | 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
|
4352 | FilePart p = local->parts[i]; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4353 | if(p.etag) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4354 | free(p.etag); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4355 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4356 | if(p.hash) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4357 | free(p.hash); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4358 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4359 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4360 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4361 | if(numparts != local->numparts) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4362 | 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
|
4363 | local->numparts = numparts; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4364 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4365 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4366 | if(!updates) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4367 | return; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4368 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4369 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4370 | CxIterator i = cxListIterator(updates); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4371 | cx_foreach(FilePart *, p, i) { |
821
9b1e998eeac6
actually make sure some random things don't explode
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
816
diff
changeset
|
4372 | if(p->block >= numparts) { |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4373 | // 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
|
4374 | // is going on |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4375 | continue; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4376 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4377 | |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4378 | 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
|
4379 | if(p->block < old_num) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4380 | // cleanup existing part |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4381 | if(old->hash) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4382 | free(old->hash); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4383 | old->hash = NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4384 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4385 | if(old->etag) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4386 | free(old->etag); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4387 | old->etag = NULL; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4388 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4389 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4390 | old->block = p->block; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4391 | old->hash = p->hash; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4392 | old->etag = p->etag; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4393 | free(p); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4394 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4395 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4396 | |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4397 | int sync_put_resource( |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4398 | SyncDirectory *dir, |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4399 | DavResource *res, |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4400 | LocalResource *local, |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4401 | int *counter) |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4402 | { |
611
a7c48e0dca88
implement links on Windows (shelllink)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
608
diff
changeset
|
4403 | char *local_path = create_local_path(dir, local_resource_path(local)); |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4404 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
4405 | SYS_STAT s; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
4406 | if(sys_stat(local_path, &s)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4407 | log_error("Cannot stat file: %s: %s\n", local_path, strerror(errno)); |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4408 | free(local_path); |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4409 | return -1; |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4410 | } |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4411 | |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4412 | DavBool islink = local->link_target ? 1 : 0; |
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4413 | if(!local->link_target && local->link_updated) { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
4414 | dav_remove_property_ns(res, DAV_PROPS_NS, "link"); |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4415 | } |
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4416 | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4417 | 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
|
4418 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
4419 | 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
|
4420 | if(!in) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4421 | log_error("Cannot open file %s: %s\n", local_path, strerror(errno)); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4422 | free(local_path); |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4423 | return -1; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4424 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4425 | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4426 | 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
|
4427 | int split_err = 0; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4428 | CxList *parts = NULL; |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4429 | uint64_t blockcount = 0; |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4430 | |
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4431 | if(islink) { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
4432 | dav_set_string_property_ns(res, DAV_PROPS_NS, "link", local->link_target); |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4433 | } else if(issplit) { |
541
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4434 | // set split property |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4435 | char blocksize_str[32]; |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4436 | snprintf(blocksize_str, 32, "%zu", split_blocksize); |
e59a989d890d
adds content hash for splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
539
diff
changeset
|
4437 | 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
|
4438 | |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4439 | // splitted/partial upload |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4440 | parts = upload_parts( |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4441 | local, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4442 | res, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4443 | in, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4444 | s.st_size, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4445 | split_blocksize, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4446 | &blockcount, |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4447 | &split_err); |
577
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4448 | } else { |
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4449 | // regular file upload |
f49964cf7228
store link property on push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
576
diff
changeset
|
4450 | 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
|
4451 | 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
|
4452 | } |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4453 | if(split_err) { |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4454 | free(local_path); |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4455 | return -1; |
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4456 | } |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4457 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4458 | MetadataHashes hashes; |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4459 | hashes = sync_set_metadata_properties(dir, res->session, res, local, FALSE); |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4460 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4461 | // 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
|
4462 | // and sets res->exists |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4463 | int exists = res->exists; |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4464 | int vend_required = 0; |
536
877f7c4a203b
adds file splitting feature to dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
533
diff
changeset
|
4465 | if(dir->versioning && dir->versioning->always && !issplit) { |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4466 | // in case the file exists, we need to put the file under |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4467 | // versioncontrol (DeltaV only, does nothing with simple versioning) |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4468 | if(exists && versioning_init(dir, local, res)) { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4469 | // init failed |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4470 | log_error("Cannot activate versioncontrol for resource: %s\n", res->href); |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4471 | free(local_path); |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4472 | return -1; |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4473 | } else { |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4474 | int err = versioning_begin(dir, res, &exists, &vend_required); |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4475 | if(err) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4476 | log_error("Cannot store version for resource: %s\n", res->href); |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4477 | free(local_path); |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4478 | return -1; |
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4479 | } |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4480 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4481 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4482 | |
739
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
4483 | int ret = -2; |
bba6a6e221b4
use sys_* io functions in dav put
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
734
diff
changeset
|
4484 | dir->max_retry = 2; |
244
47791bdf1725
changed max-retry meaning and filter configuration in sync.xml
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
243
diff
changeset
|
4485 | 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
|
4486 | if(!exists && dav_create(res)) { |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4487 | continue; |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4488 | } |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4489 | exists = 1; |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4490 | if(dav_store(res)) { |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4491 | continue; |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4492 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4493 | ret = 0; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4494 | break; |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4495 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4496 | |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4497 | if(vend_required) { |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4498 | if(versioning_end(dir, res)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4499 | log_error("Cannot checkin resource\n"); |
491
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4500 | ret = 1; |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4501 | } |
fdc2fb090cc7
adds versioning support for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
4502 | } |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4503 | |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4504 | if(ret == 0) { |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4505 | (*counter)++; |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4506 | |
661
1baec7ff8931
add first metadata sync test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
659
diff
changeset
|
4507 | local->tags_updated = 0; |
1baec7ff8931
add first metadata sync test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
659
diff
changeset
|
4508 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4509 | 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
|
4510 | update_parts(local, parts, blockcount); |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4511 | |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4512 | // 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
|
4513 | 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
|
4514 | |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4515 | if(up_res) { |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4516 | // 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
|
4517 | if(up_res->contentlength < s.st_size && !issplit && !islink) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4518 | log_error("Incomplete Upload: %s\n", local_path); |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4519 | ret = -1; |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4520 | // try to set the resource status to 'broken' |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4521 | sync_set_status(res, "broken"); |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4522 | } else { |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4523 | // 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
|
4524 | char *etag = dav_get_string_property(up_res, "D:getetag"); |
621
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
4525 | local_resource_set_etag(local, etag); |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4526 | |
630
046b869a1c49
use hash to check if a file content was really modified
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
629
diff
changeset
|
4527 | if(!issplit && SYNC_STORE_HASH(dir)) { |
550
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
4528 | if(local->hash) { |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
4529 | free(local->hash); |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
4530 | } |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
4531 | // TODO: calculate hash on upload |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
4532 | local->hash = util_file_hash(local_path); |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
4533 | } |
8c700eae3eb8
add copy/move detection to push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
548
diff
changeset
|
4534 | |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
4535 | 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
|
4536 | sync_remove_status(up_res); |
bf485439222a
fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
4537 | } |
bf485439222a
fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
4538 | |
bf485439222a
fixed locking in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
225
diff
changeset
|
4539 | dav_resource_free(up_res); |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4540 | } |
64
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
4541 | } |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4542 | } else { |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4543 | ret = -1; |
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4544 | sync_set_status(res, "broken"); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4545 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4546 | |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4547 | fclose(in); |
144
c2c02c9b3be4
dav-sync detects broken uploads
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
135
diff
changeset
|
4548 | free(local_path); |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4549 | |
64
112dbf7ba8b0
changed sync behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
61
diff
changeset
|
4550 | return ret; |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4551 | } |
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4552 | |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4553 | 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
|
4554 | res->iscollection = 1; |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4555 | 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
|
4556 | 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
|
4557 | if(dav_create(res)) { |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4558 | continue; |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4559 | } |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4560 | ret = 0; |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4561 | break; |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4562 | } |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4563 | return ret; |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4564 | } |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4565 | |
552
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4566 | int sync_move_remote_resource( |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4567 | SyncDirectory *dir, |
569
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
4568 | SyncDatabase *db, |
552
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4569 | DavResource *origin, |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4570 | LocalResource *local, |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4571 | DavBool copy, |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4572 | int *counter) |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4573 | { |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4574 | 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
|
4575 | |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4576 | SYS_STAT s; |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4577 | if(sys_stat(local_path, &s)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4578 | log_error("Cannot stat file: %s: %s\n", local_path, strerror(errno)); |
552
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4579 | free(local_path); |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4580 | return -1; |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4581 | } |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4582 | free(local_path); |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4583 | |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4584 | int result = 0; |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4585 | if(copy) { |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4586 | 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
|
4587 | } else { |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4588 | 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
|
4589 | } |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4590 | |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4591 | if(result != 0) { |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4592 | return result; |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4593 | } |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4594 | |
569
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
4595 | LocalResource *local_origin = local->origin; |
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
4596 | if(!copy) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4597 | cxMapRemove(db->resources, cx_hash_key_str(local_origin->path)); |
569
cafdc13b6820
remove dead db entry when files are moved
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
568
diff
changeset
|
4598 | } |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4599 | |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4600 | // set resource metadata |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4601 | DavResource *up_res = dav_resource_new(origin->session, local->path); |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4602 | if(!up_res) { |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4603 | return 1; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4604 | } |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4605 | |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4606 | sync_set_metadata_from_stat(local, &s); |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4607 | MetadataHashes hashes; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4608 | hashes = sync_set_metadata_properties(dir, up_res->session, up_res, local, TRUE); |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4609 | if(dav_store(up_res)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4610 | log_error("Error: cannot store resource metadata\n"); |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4611 | } |
552
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4612 | |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4613 | // get new etag |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4614 | DavPropName p; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4615 | p.ns = "DAV:"; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4616 | p.name = "getetag"; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4617 | if(!dav_load_prop(up_res, &p, 1)) { |
552
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4618 | (*counter)++; |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4619 | |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4620 | // 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
|
4621 | char *etag = dav_get_string_property(up_res, "D:getetag"); |
621
06f9fddc82a1
don't store weak etag in LocalResource
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
619
diff
changeset
|
4622 | local_resource_set_etag(local, etag); |
552
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4623 | |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4624 | local->last_modified = s.st_mtime; |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4625 | } else { |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4626 | result = 1; |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4627 | } |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4628 | |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4629 | dav_resource_free(up_res); |
552
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4630 | return result; |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4631 | } |
e1a12762bf0a
improve copy/move stability and db update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
551
diff
changeset
|
4632 | |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4633 | int sync_delete_remote_resource( |
492
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4634 | SyncDirectory *dir, |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4635 | DavSession *sn, |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4636 | 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
|
4637 | int *counter, |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4638 | CxList *cols) |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4639 | { |
570
00b7b8e86c48
fix deletion of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
569
diff
changeset
|
4640 | 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
|
4641 | if(!res) { |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4642 | 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
|
4643 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4644 | |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4645 | 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
|
4646 | 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
|
4647 | if(res->iscollection) { |
570
00b7b8e86c48
fix deletion of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
569
diff
changeset
|
4648 | 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
|
4649 | if(cols) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4650 | cxListAdd(cols, local_res); |
570
00b7b8e86c48
fix deletion of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
569
diff
changeset
|
4651 | } else if(split || !res->children) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
4652 | log_printf("delete: %s\n", res->path); |
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
|
4653 | 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
|
4654 | ret = 1; |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4655 | log_error("Cannot delete collection %s\n", res->path); |
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
|
4656 | } 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
|
4657 | (*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
|
4658 | } |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4659 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4660 | } else { |
331
9ca1e4706acc
adds initial support for xml properties in libidav
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
318
diff
changeset
|
4661 | 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
|
4662 | if(etag) { |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4663 | 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
|
4664 | etag = etag + 2; |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4665 | } |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4666 | } |
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4667 | |
565
26898e00ddff
fix dav-sync push not deleting files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
564
diff
changeset
|
4668 | 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
|
4669 | // 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
|
4670 | // resource can be deleted |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
4671 | log_printf("delete: %s\n", res->path); |
679
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4672 | int exists = 1; |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4673 | int vend_required = 0; |
492
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4674 | if(dir->versioning && dir->versioning->always) { |
692
56b66fe2b4f5
fix dav-sync deltav versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
687
diff
changeset
|
4675 | if(versioning_delete_begin(dir, res, &exists, &vend_required)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4676 | log_error("Cannot save resource version before deletion\n"); |
492
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4677 | ret = 1; |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4678 | } |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4679 | } |
7bde663719dc
Adds dav-sync option for enabling versioning
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
491
diff
changeset
|
4680 | |
679
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4681 | if(!ret && dav_delete(res) && exists) { |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4682 | if(sn->error != DAV_NOT_FOUND) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4683 | log_error("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
|
4684 | ret = 1; |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4685 | } |
192
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4686 | } else { |
d10194a51304
dav-sync prints a small report after successful sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
4687 | (*counter)++; |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4688 | } |
679
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4689 | |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4690 | if(vend_required) { |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4691 | versioning_delete_end(dir, res); |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
4692 | } |
190
a76e43d89f55
dav-sync can create and delete empty directories now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
4693 | } |
565
26898e00ddff
fix dav-sync push not deleting files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
564
diff
changeset
|
4694 | // 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
|
4695 | // the server and delete was skipped? |
65
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4696 | } |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4697 | |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4698 | // cleanup |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4699 | dav_resource_free(res); |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4700 | |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4701 | return ret; |
d4077e8175f3
added optional trash for deleted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
64
diff
changeset
|
4702 | } |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
4703 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4704 | MetadataHashes sync_set_metadata_properties( |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4705 | SyncDirectory *dir, |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4706 | DavSession *sn, |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4707 | DavResource *res, |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4708 | LocalResource *local, |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4709 | DavBool force) |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4710 | { |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4711 | if(force) { |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4712 | local->tags_updated = 1; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4713 | local->finfo_updated = 1; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4714 | local->xattr_updated = 1; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4715 | } |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4716 | |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4717 | MetadataHashes hashes = {NULL, NULL, NULL, 0, 0, 0}; |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4718 | if(dir->tagconfig) { |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4719 | // get local tags |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4720 | DavBool changed = 0; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4721 | char *tags_hash = NULL; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4722 | CxList *tags = sync_get_file_tags(dir, local, &changed, &tags_hash); |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4723 | char *new_remote_hash = nullstrdup(tags_hash); |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4724 | if(changed || local->tags_updated) { |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4725 | DavBool store_tags = TRUE; |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4726 | |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4727 | // get remote tags |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4728 | DavPropName p; |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4729 | p.ns = DAV_PROPS_NS; |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4730 | p.name = "tags"; |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4731 | if(dav_load_prop(res, &p, 1) && sn->error != DAV_NOT_FOUND) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4732 | log_resource_error(sn, res->path); |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4733 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4734 | CxList *remote_tags = NULL; |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
4735 | DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4736 | if(tagsprop) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4737 | 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
|
4738 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4739 | char *remote_hash = create_tags_hash(remote_tags); |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4740 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4741 | 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
|
4742 | // the tags have changed on the server |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4743 | int conflict_resolution = force ? TAG_NO_CONFLICT : dir->tagconfig->conflict; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4744 | switch(conflict_resolution) { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4745 | case TAG_NO_CONFLICT: break; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4746 | case TAG_KEEP_LOCAL: break; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4747 | case TAG_KEEP_REMOTE: { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4748 | store_tags = FALSE; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4749 | local->tags_updated = FALSE; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4750 | break; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4751 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4752 | case TAG_MERGE: { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4753 | CxList *new_tags = merge_tags(tags, remote_tags); |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4754 | free_taglist(tags); |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4755 | tags = new_tags; |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4756 | |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4757 | nullfree(tags_hash); |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4758 | nullfree(new_remote_hash); |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4759 | tags_hash = create_tags_hash(tags); |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4760 | new_remote_hash = nullstrdup(tags_hash); |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4761 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4762 | break; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4763 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4764 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4765 | } |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4766 | nullfree(remote_hash); |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4767 | |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4768 | 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
|
4769 | // 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
|
4770 | // 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
|
4771 | add_tag_colors(tags, remote_tags); |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4772 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4773 | |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4774 | if(store_tags) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4775 | if(tags) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4776 | DavXmlNode *tagprop = create_xml_taglist(tags); |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
4777 | dav_set_property_ns(res, DAV_PROPS_NS, "tags", tagprop); |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4778 | } else { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
4779 | dav_remove_property_ns(res, DAV_PROPS_NS, "tags"); |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4780 | } |
667
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4781 | |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4782 | hashes.tags = tags_hash; |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4783 | hashes.update_tags = 1; |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4784 | hashes.tags_remote = new_remote_hash; |
6cdcd3e4e368
finish basic metadata sync tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
663
diff
changeset
|
4785 | hashes.update_tags_remote = 1; |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4786 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4787 | |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4788 | free_taglist(remote_tags); |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4789 | } else { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4790 | if(tags_hash) { |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4791 | free(tags_hash); |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4792 | } |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4793 | } |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4794 | free_taglist(tags); |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
4795 | } |
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
4796 | |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4797 | if(local->finfo_updated) { |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4798 | struct stat s; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4799 | s.st_mode = local->mode; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4800 | s.st_mtime = local->last_modified; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4801 | s.st_uid = local->uid; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4802 | s.st_gid = local->gid; |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4803 | 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
|
4804 | } |
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
4805 | |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4806 | if(local->xattr_updated) { |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4807 | if(local->xattr) { |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4808 | resource_set_xattr(res, local->xattr); |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4809 | hashes.xattr = local->xattr ? strdup(local->xattr->hash) : NULL; |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4810 | hashes.update_xattr = 1; |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4811 | } else { |
607
5dc7fe41e8f8
move some properties to new namespace
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
603
diff
changeset
|
4812 | dav_remove_property(res, "idavprops:xattributes"); |
663
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4813 | if(local->xattr_hash) { |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4814 | free(local->xattr_hash); |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4815 | local->xattr_hash = NULL; |
888aa263c0f1
fix some xattr sync bugs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
662
diff
changeset
|
4816 | } |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4817 | } |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4818 | } |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4819 | |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4820 | local->tags_updated = 0; |
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4821 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4822 | return hashes; |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4823 | } |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4824 | |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4825 | int sync_update_metadata( |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4826 | SyncDirectory *dir, |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4827 | DavSession *sn, |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4828 | DavResource *res, |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4829 | LocalResource *local) |
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4830 | { |
672
4bfe452a2665
fix dav-sync copy with enabled metadata sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
669
diff
changeset
|
4831 | MetadataHashes hashes = sync_set_metadata_properties(dir, sn, res, local, FALSE); |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4832 | |
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4833 | int err = 0; |
370
ab9c5afdc243
pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
369
diff
changeset
|
4834 | if(dav_store(res)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4835 | log_resource_error(sn, local->path); |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4836 | err = 1; |
370
ab9c5afdc243
pushing tags should work now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
369
diff
changeset
|
4837 | } else { |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4838 | update_metadata_hashes(local, hashes); |
661
1baec7ff8931
add first metadata sync test
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
659
diff
changeset
|
4839 | local->tags_updated = 0; |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
4840 | } |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
4841 | |
523
923a4528a2ae
adds support for pushing metadata updates
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
522
diff
changeset
|
4842 | return err; |
369
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
4843 | } |
4322b8953bd5
adds tag conflict detection for dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
368
diff
changeset
|
4844 | |
218
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4845 | void remove_deleted_conflicts(SyncDirectory *dir, SyncDatabase *db) { |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
4846 | char **dc = calloc(sizeof(void*), cxMapSize(db->conflict)); |
218
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4847 | int numdc = 0; |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4848 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4849 | CxIterator i = cxMapIteratorValues(db->conflict); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4850 | cx_foreach(LocalResource *, res, i) { |
544
9e85e1ec1155
adds semi functional download of splitted files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
4851 | 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
|
4852 | SYS_STAT s; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
4853 | 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
|
4854 | if(errno == ENOENT) { |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4855 | dc[numdc] = res->path; |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4856 | numdc++; |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4857 | } else { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4858 | log_error("Cannot stat file: %s: %s\n", path, strerror(errno)); |
218
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4859 | } |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4860 | } |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4861 | free(path); |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4862 | } |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4863 | |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4864 | for(int i=0;i<numdc;i++) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4865 | cxMapRemove(db->conflict, cx_hash_key_str(dc[i])); |
218
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4866 | } |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4867 | |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4868 | free(dc); |
218
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4869 | } |
5f1f7602cf77
automatically remove deleted conflict files from the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
217
diff
changeset
|
4870 | |
257
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4871 | static void resolve_skipped(SyncDatabase *db) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4872 | CxIterator i = cxMapIteratorValues(db->resources); |
257
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4873 | int skipped = 0; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4874 | cx_foreach(LocalResource *, res, i) { |
257
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4875 | if(res->skipped) { |
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4876 | skipped++; |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4877 | log_error("skipped from push: %s\n", res->path); |
257
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4878 | } |
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4879 | } |
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4880 | if(skipped > 0) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4881 | log_error( |
257
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4882 | " 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
|
4883 | " 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
|
4884 | } |
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4885 | } |
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4886 | |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4887 | int cmd_resolve_conflicts(CmdArgs *a) { |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4888 | if(a->argc != 1) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4889 | log_error("Too %s arguments\n", a->argc < 1 ? "few" : "many"); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4890 | return -1; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4891 | } |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4892 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4893 | 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
|
4894 | if(!dir) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4895 | log_error("Unknown sync dir: %s\n", a->argv[0]); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4896 | return -1; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4897 | } |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
4898 | if(scfg_check_dir(dir)) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
4899 | return -1; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
4900 | } |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
4901 | if(logfile_open(dir)) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
4902 | return -1; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
4903 | } |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4904 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4905 | SyncDatabase *db = load_db(dir->database); |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4906 | if(!db) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4907 | log_error("Cannot load database file: %s\n", dir->database); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4908 | return -1; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4909 | } |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4910 | |
257
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4911 | resolve_skipped(db); |
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4912 | |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4913 | int ret = 0; |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4914 | |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4915 | // remove conflicts |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
4916 | size_t num_conflict = cxMapSize(db->conflict); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4917 | //ucx_map_free_content(db->conflict, (ucx_destructor)local_resource_free); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4918 | cxMapClear(db->conflict); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4919 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4920 | // store db |
521
c5bbae4b3cca
extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
516
diff
changeset
|
4921 | if(store_db(db, dir->database, dir->db_settings)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4922 | log_error("Cannot store sync db\n"); |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4923 | log_error("Abort\n"); |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
4924 | ret = -2; |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4925 | } |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
4926 | |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
4927 | // cleanup |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4928 | destroy_db(db); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4929 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4930 | // Report |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
4931 | if(ret != -2) { |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4932 | char *str_conflict = num_conflict == 1 ? "conflict" : "conflicts"; |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
4933 | log_printf("Result: %zu %s resolved\n", num_conflict, str_conflict); |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4934 | } |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4935 | |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4936 | return ret; |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4937 | } |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4938 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4939 | int cmd_delete_conflicts(CmdArgs *a) { |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4940 | if(a->argc != 1) { |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4941 | 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
|
4942 | return -1; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4943 | } |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4944 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4945 | 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
|
4946 | if(!dir) { |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4947 | 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
|
4948 | return -1; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4949 | } |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
4950 | if(scfg_check_dir(dir)) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
4951 | return -1; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
4952 | } |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
4953 | if(logfile_open(dir)) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
4954 | return -1; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
4955 | } |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4956 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4957 | SyncDatabase *db = load_db(dir->database); |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4958 | if(!db) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4959 | log_error("Cannot load database file: %s\n", dir->database); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4960 | return -1; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4961 | } |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4962 | |
257
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4963 | resolve_skipped(db); |
49f3c58cc06c
fixes conflict detection in push command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
4964 | |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4965 | int num_del = 0; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4966 | int num_err = 0; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4967 | |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4968 | int ret = 0; |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4969 | |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4970 | // delete all conflict files |
762
098b2e3ab240
fix iterator misuse in dav-sync delete-conflict
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
760
diff
changeset
|
4971 | CxIterator i = cxMapIteratorValues(db->conflict); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4972 | cx_foreach(LocalResource*, res, i) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
4973 | log_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
|
4974 | char *path = create_local_path(dir, res->path); |
412
dc74f736aea1
adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
411
diff
changeset
|
4975 | if(sys_unlink(path)) { |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4976 | if(errno != ENOENT) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4977 | log_error("unlink: %s", strerror(errno)); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4978 | num_err++; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4979 | } |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4980 | } else { |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4981 | num_del++; |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4982 | } |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4983 | free(path); |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4984 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4985 | //ucx_map_free_content(db->conflict, (ucx_destructor)local_resource_free); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
4986 | cxMapClear(db->conflict); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4987 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4988 | // store db |
521
c5bbae4b3cca
extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
516
diff
changeset
|
4989 | if(store_db(db, dir->database, dir->db_settings)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4990 | log_error("Cannot store sync db\n"); |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
4991 | log_error("Abort\n"); |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4992 | ret = -1; |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4993 | } |
224
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
4994 | |
4b55f05f4e00
added more cleanup code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
223
diff
changeset
|
4995 | // cleanup |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4996 | destroy_db(db); |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4997 | |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
4998 | // Report |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
4999 | if(ret == 0) { |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
5000 | 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
|
5001 | char *str_error = num_err == 1 ? "error" : "errors"; |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5002 | log_printf("Result: %d conflict %s deleted, %d %s\n", |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
5003 | num_del, str_delete, |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
5004 | num_err, str_error); |
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
5005 | } |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
5006 | |
222
7b73058d782e
fixed some memory leaks in dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
221
diff
changeset
|
5007 | return ret; |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
5008 | } |
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
5009 | |
563
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5010 | int cmd_list_conflicts(CmdArgs *a) { |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5011 | if(a->argc != 1) { |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5012 | 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
|
5013 | return -1; |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5014 | } |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5015 | |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5016 | 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
|
5017 | if(!dir) { |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5018 | 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
|
5019 | return -1; |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5020 | } |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5021 | if(scfg_check_dir(dir)) { |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5022 | return -1; |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5023 | } |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5024 | |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5025 | SyncDatabase *db = load_db(dir->database); |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5026 | if(!db) { |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5027 | 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
|
5028 | return -1; |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5029 | } |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5030 | |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5031 | remove_deleted_conflicts(dir, db); |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5032 | |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5033 | // get all conflict sources |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5034 | CxIterator i = cxMapIteratorValues(db->conflict); |
816
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
5035 | CxList* conflict_sources = cxLinkedListCreate( |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
5036 | cxDefaultAllocator, |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
5037 | (cx_compare_func) strcmp, |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
5038 | CX_STORE_POINTERS |
839fefbdedc7
compatibility with UCX 3.1 plus several minor code fixes
Mike Becker <universe@uap-core.de>
parents:
812
diff
changeset
|
5039 | ); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5040 | cx_foreach(LocalResource *, res, i) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5041 | cxListAdd(conflict_sources, res->conflict_source); |
563
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5042 | } |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5043 | |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5044 | // print unique conflict sources |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5045 | cxListSort(conflict_sources); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5046 | i = cxListIterator(conflict_sources); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5047 | char *prev = ""; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5048 | cx_foreach(char *, path, i) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5049 | // TODO: implement verbose print if(cmd_getoption(a, "verbose")) |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5050 | // log_printf("%s (%d)\n", path, confl_count); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5051 | if(!strcmp(path, prev)) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5052 | continue; |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5053 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5054 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5055 | log_printf("%s\n", path); |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5056 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5057 | prev = path; |
563
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5058 | } |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5059 | |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5060 | // cleanup |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5061 | destroy_db(db); |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5062 | |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5063 | return 0; |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5064 | } |
3dffe58a573f
adds list-conflicts command to dav-sync
Mike Becker <universe@uap-core.de>
parents:
561
diff
changeset
|
5065 | |
217
12bad63cf5a8
added resolve-conflicts and delete-conflicts commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
216
diff
changeset
|
5066 | |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5067 | // 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
|
5068 | 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
|
5069 | char *str = malloc(16); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5070 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5071 | if(size < 0x400) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5072 | snprintf(str, 16, "%" PRIu64 " bytes", size); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5073 | } else if(size < 0x100000) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5074 | float s = (float)size/0x400; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5075 | 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
|
5076 | if(diff > 90) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5077 | diff = 0; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5078 | s += 0.10f; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5079 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5080 | if(size < 0x2800 && diff != 0) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5081 | // size < 10 KiB |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5082 | snprintf(str, 16, "%.1f KiB", s); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5083 | } else { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5084 | snprintf(str, 16, "%.0f KiB", s); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5085 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5086 | } else if(size < 0x40000000) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5087 | float s = (float)size/0x100000; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5088 | 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
|
5089 | if(diff > 90) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5090 | diff = 0; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5091 | s += 0.10f; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5092 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5093 | if(size < 0xa00000 && diff != 0) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5094 | // size < 10 MiB |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5095 | snprintf(str, 16, "%.1f MiB", s); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5096 | } else { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5097 | size /= 0x100000; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5098 | snprintf(str, 16, "%.0f MiB", s); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5099 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5100 | } else if(size < 0x1000000000ULL) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5101 | float s = (float)size/0x40000000; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5102 | 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
|
5103 | if(diff > 90) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5104 | diff = 0; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5105 | s += 0.10f; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5106 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5107 | if(size < 0x280000000 && diff != 0) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5108 | // size < 10 GiB |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5109 | snprintf(str, 16, "%.1f GiB", s); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5110 | } else { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5111 | size /= 0x40000000; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5112 | snprintf(str, 16, "%.0f GiB", s); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5113 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5114 | } else { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5115 | size /= 1024; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5116 | float s = (float)size/0x40000000; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5117 | 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
|
5118 | if(diff > 90) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5119 | diff = 0; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5120 | s += 0.10f; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5121 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5122 | if(size < 0x280000000 && diff != 0) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5123 | // size < 10 TiB |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5124 | snprintf(str, 16, "%.1f TiB", s); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5125 | } else { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5126 | size /= 0x40000000; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5127 | snprintf(str, 16, "%.0f TiB", s); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5128 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5129 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5130 | return str; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5131 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5132 | |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5133 | 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
|
5134 | time_t now = res->lastmodified; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5135 | struct tm *date = gmtime(&now); |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5136 | char str[32]; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5137 | putenv("LC_TIME=C"); |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5138 | 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
|
5139 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5140 | log_printf("name: %s\n", name); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5141 | log_printf("lastmodified: %s\n", str); |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5142 | 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
|
5143 | char *url = util_concat_path(server, res->href); |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5144 | log_printf("url: %s\n", url); |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5145 | free(server); |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5146 | free(url); |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5147 | } |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5148 | |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5149 | int cmd_list_versions(CmdArgs *a) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5150 | if(a->argc != 1) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5151 | 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
|
5152 | return -1; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5153 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5154 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5155 | SyncFile file; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5156 | int ret = 0; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5157 | char *path = a->argv[0]; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5158 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5159 | int err = sync_get_file(a, path, &file, TRUE); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5160 | if(err) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5161 | sync_print_get_file_err(path, err); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5162 | return 1; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5163 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5164 | SyncDirectory *dir = file.dir; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5165 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5166 | if(!dir->versioning) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5167 | 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
|
5168 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5169 | |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
5170 | DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(dir->repository)); |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5171 | if(!repo) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5172 | fprintf(stderr, "Unknown repository %s\n", dir->repository); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5173 | return -1; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5174 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5175 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5176 | SyncDatabase *db = load_db(dir->database); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5177 | if(!db) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5178 | 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
|
5179 | return -1; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5180 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5181 | remove_deleted_conflicts(dir, db); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5182 | |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
5183 | DavSession *sn = create_session(a, ctx, repo, dir->collection); |
775 | 5184 | cxMempoolRegister(sn->mp, db, (cx_destructor_func)destroy_db); |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5185 | if (cmd_getoption(a, "verbose")) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5186 | curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5187 | curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5188 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5189 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5190 | DavResource *res = dav_resource_new(sn, file.path); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5191 | if(dir->versioning->type == VERSIONING_SIMPLE) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5192 | do { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5193 | DavPropName p; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5194 | p.ns = DAV_NS; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5195 | p.name = VERSION_PATH_PROPERTY; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5196 | if(dav_load_prop(res, &p, 1)) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5197 | print_resource_error(sn, file.path); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5198 | ret = 1; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5199 | break; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5200 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5201 | 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
|
5202 | if(!vcol_href) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5203 | ret = 1; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5204 | break; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5205 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5206 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5207 | DavResource *vcol = dav_resource_new_href(sn, vcol_href); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5208 | if(!vcol) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5209 | ret = 1; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5210 | break; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5211 | } |
530
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5212 | |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5213 | if(dav_load_prop(vcol, NULL, 0)) { |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5214 | print_resource_error(sn, vcol->path); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5215 | ret = 1; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5216 | break; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5217 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5218 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5219 | DavResource *child = vcol->children; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5220 | CxList *children = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)strcmp, CX_STORE_POINTERS); |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5221 | while(child) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5222 | cxListAdd(children, child); |
530
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5223 | child = child->next; |
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5224 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5225 | cxListSort(children); |
530
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5226 | |
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5227 | DavBool first = 1; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5228 | CxIterator i = cxListIterator(children); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5229 | cx_foreach(DavResource *, c, i) { |
530
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5230 | if(!first) { |
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5231 | putchar('\n'); |
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5232 | } |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5233 | print_resource_version(c, c->name); |
530
29e660161b73
changes list-versions output
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
529
diff
changeset
|
5234 | first = 0; |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5235 | } |
852 | 5236 | cxListFree(children); |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5237 | } while(0); |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5238 | } else if(dir->versioning->type == VERSIONING_DELTAV) { |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5239 | DavResource *versions = dav_versiontree(res, NULL); |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5240 | DavResource *v = versions; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5241 | DavBool first = 1; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5242 | while(v) { |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5243 | if(!first) { |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5244 | putchar('\n'); |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5245 | } |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5246 | 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
|
5247 | print_resource_version(v, vname); |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5248 | first = 0; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5249 | v = v->next; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5250 | } |
529
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5251 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5252 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5253 | free(file.path); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5254 | dav_session_destroy(sn); |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5255 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5256 | return ret; |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5257 | } |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5258 | |
dc3f82b04733
adds list-versions command
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
528
diff
changeset
|
5259 | |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5260 | int cmd_trash_info(CmdArgs *a) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5261 | if(a->argc != 1) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5262 | 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
|
5263 | return -1; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5264 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5265 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5266 | 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
|
5267 | if(!syncdir) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5268 | 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
|
5269 | return -1; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5270 | } |
233
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
5271 | if(scfg_check_dir(syncdir)) { |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
5272 | return -1; |
d8042cede66c
improved dav-sync error handling on startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
228
diff
changeset
|
5273 | } |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5274 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5275 | if(!syncdir->trash) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5276 | log_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
|
5277 | return 0; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5278 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5279 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5280 | 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
|
5281 | if(!dir) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5282 | 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
|
5283 | perror("opendir"); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5284 | return -1; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5285 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5286 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5287 | uint64_t trashsize = 0; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5288 | int count = 0; |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5289 | SysDirEnt *ent; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5290 | while((ent = sys_readdir(dir)) != NULL) { |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5291 | 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
|
5292 | continue; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5293 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5294 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5295 | 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
|
5296 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5297 | SYS_STAT s; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5298 | if(sys_stat(path, &s)) { |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5299 | perror("stat"); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5300 | } else { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5301 | trashsize += s.st_size; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5302 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5303 | count++; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5304 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5305 | free(path); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5306 | } |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5307 | sys_closedir(dir); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5308 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5309 | log_printf("path: %s\n", syncdir->trash); |
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5310 | log_printf("%d %s\n", count, count == 1 ? "file" : "files"); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5311 | char *sizestr = size_str(trashsize); |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5312 | log_printf("%s\n", sizestr); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5313 | free(sizestr); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5314 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5315 | return 0; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5316 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5317 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5318 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5319 | int cmd_empty_trash(CmdArgs *a) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5320 | if(a->argc != 1) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5321 | 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
|
5322 | return -1; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5323 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5324 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5325 | 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
|
5326 | if(!syncdir) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5327 | 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
|
5328 | return -1; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5329 | } |
782
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
5330 | if(logfile_open(syncdir)) { |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
5331 | return -1; |
3cfe65695a8c
open logfile in relevant dav-sync commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
781
diff
changeset
|
5332 | } |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5333 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5334 | if(!syncdir->trash) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5335 | log_error("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
|
5336 | return -1; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5337 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5338 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5339 | 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
|
5340 | if(!dir) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5341 | log_error("cannot open trash directory: %s\n", syncdir->trash); |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5342 | log_error("opendir: %s\n", strerror(errno)); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5343 | return -1; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5344 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5345 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5346 | SysDirEnt *ent; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5347 | while((ent = sys_readdir(dir)) != NULL) { |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5348 | 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
|
5349 | continue; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5350 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5351 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5352 | char *path = util_concat_path(syncdir->trash, ent->name); |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5353 | log_printf("delete: %s\n", path); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5354 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5355 | SYS_STAT s; |
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5356 | if(sys_stat(path, &s)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5357 | log_error("stat: %s\n", strerror(errno)); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5358 | free(path); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5359 | continue; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5360 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5361 | if(S_ISDIR(s.st_mode)) { |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5362 | if(rmdir(path)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5363 | log_error("rmdir: %s\n", strerror(errno)); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5364 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5365 | } else { |
412
dc74f736aea1
adds more fs abstraction
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
411
diff
changeset
|
5366 | if(sys_unlink(path)) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5367 | log_error("unlink: %s\n", strerror(errno)); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5368 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5369 | } |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5370 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5371 | free(path); |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5372 | } |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5373 | sys_closedir(dir); |
204
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5374 | |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5375 | return 0; |
4f0207044837
added trash-info and empty-trash commands
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
200
diff
changeset
|
5376 | } |
47
fbbbeed4ba8f
added push command for dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
5377 | |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5378 | #define CMD_TAG_ADD 0 |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5379 | #define CMD_TAG_REMOVE 1 |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
5380 | #define CMD_TAG_SET 2 |
377
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5381 | #define CMD_TAG_LIST 3 |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5382 | int cmd_add_tag(CmdArgs *args) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5383 | if(args->argc != 2) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5384 | 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
|
5385 | return -1; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5386 | } |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
5387 | 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
|
5388 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5389 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5390 | int cmd_remove_tag(CmdArgs *args) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5391 | if(args->argc != 2) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5392 | 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
|
5393 | return -1; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5394 | } |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
5395 | 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
|
5396 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5397 | |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
5398 | 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
|
5399 | 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
|
5400 | 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
|
5401 | return -1; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5402 | } |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
5403 | 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
|
5404 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5405 | |
377
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5406 | int cmd_list_tags(CmdArgs *args) { |
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5407 | if(args->argc != 1) { |
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5408 | 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
|
5409 | return -1; |
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5410 | } |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
5411 | 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
|
5412 | } |
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5413 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
5414 | 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
|
5415 | SyncFile file; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5416 | int ret = 0; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5417 | char *path = args->argv[0]; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5418 | |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5419 | 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
|
5420 | if(err) { |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5421 | 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
|
5422 | return -1; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5423 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5424 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5425 | if(!file.dir->tagconfig) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5426 | 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
|
5427 | return -1; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5428 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5429 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5430 | 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
|
5431 | if(!db) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5432 | 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
|
5433 | return -1; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5434 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5435 | |
669
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5436 | LocalResource *newres = NULL; |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5437 | LocalResource *localres = cxMapGet(db->resources, cx_hash_key_str(file.path)); |
669
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5438 | if(!localres) { |
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5439 | newres = calloc(1, sizeof(LocalResource)); |
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5440 | newres->path = strdup(file.path); |
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5441 | localres = newres; |
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5442 | } |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5443 | CxList *tags = NULL; |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5444 | DavBool store_tags = FALSE; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5445 | |
380
8a0c727aa409
adds tag filter for dav-sync pull
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
5446 | if(cmd != CMD_TAG_SET) { |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5447 | char *tag = args->argv[1]; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5448 | char *tagcolor = NULL; // TODO: get color |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5449 | |
525
26a1d5b9d9d2
improves metadata support in dav-sync push
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
524
diff
changeset
|
5450 | tags = sync_get_file_tags(file.dir, localres, NULL, NULL); |
766
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5451 | CxIterator i = cxListIterator(tags ? tags : cxEmptyList); |
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5452 | int x = -1; |
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5453 | cx_foreach(DavTag *, t, i) { |
377
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5454 | if(cmd == CMD_TAG_LIST) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5455 | log_printf("%s\n", t->name); |
377
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5456 | } else if(!strcmp(t->name, tag)) { |
766
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5457 | x = i.index; |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5458 | break; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5459 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5460 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5461 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5462 | if(cmd == CMD_TAG_ADD) { |
766
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5463 | if(x < 0) { |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5464 | DavTag *newtag = malloc(sizeof(DavTag)); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5465 | newtag->name = tag; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5466 | newtag->color = tagcolor; |
766
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5467 | if(!tags) { |
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5468 | tags = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5469 | } |
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5470 | cxListAdd(tags, newtag); |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5471 | store_tags = TRUE; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5472 | } |
377
d6d7c16dd066
adds list-tags command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
5473 | } else if(cmd == CMD_TAG_REMOVE) { |
766
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5474 | if(x >= 0) { |
c4993f0991e4
port cmd_tagop() to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
5475 | cxListRemove(tags, x); |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5476 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5477 | store_tags = TRUE; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5478 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5479 | } else { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5480 | if(args->argc == 2) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5481 | char *tags_str = args->argv[1]; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5482 | 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
|
5483 | store_tags = TRUE; |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5484 | // 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
|
5485 | } else if (args->argc == 1) { |
17ccf828a2f2
fixes dav-sync set-tags without tag string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
380
diff
changeset
|
5486 | store_tags = TRUE; |
17ccf828a2f2
fixes dav-sync set-tags without tag string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
380
diff
changeset
|
5487 | } else { |
17ccf828a2f2
fixes dav-sync set-tags without tag string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
380
diff
changeset
|
5488 | 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
|
5489 | ret = -1; |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5490 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5491 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5492 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5493 | if(store_tags) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5494 | 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
|
5495 | fprintf(stderr, "Cannot store tags\n"); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5496 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5497 | if(localres) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5498 | localres->tags_updated = TRUE; |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
5499 | if(!tags) { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
5500 | if(localres->tags_hash) { |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
5501 | free(localres->tags_hash); |
629
bc2cdbf5e68f
handle symlinks according to config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
626
diff
changeset
|
5502 | localres->tags_hash = NULL; |
379
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
5503 | } |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
5504 | localres->tags_hash = NULL; |
cdaf5a3d3a50
fixes tag syncing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
5505 | } |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5506 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5507 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5508 | |
669
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5509 | if(newres) { |
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5510 | local_resource_free(newres); |
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5511 | } |
152101df336d
fix dav-sync add-tag in case a file is not in the db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
668
diff
changeset
|
5512 | |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5513 | // store db |
521
c5bbae4b3cca
extends sync db
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
516
diff
changeset
|
5514 | 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
|
5515 | 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
|
5516 | ret = -2; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5517 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5518 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5519 | free(file.path); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5520 | return ret; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5521 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5522 | |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5523 | 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
|
5524 | char *fullpath; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5525 | 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
|
5526 | 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
|
5527 | char *wd = malloc(wdlen); |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5528 | while(!getcwd(wd, wdlen)) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5529 | if(errno == ERANGE) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5530 | 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
|
5531 | 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
|
5532 | if (newbuf) { |
99193580aa9d
fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents:
381
diff
changeset
|
5533 | wd = newbuf; |
99193580aa9d
fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents:
381
diff
changeset
|
5534 | } else { |
99193580aa9d
fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents:
381
diff
changeset
|
5535 | free(wd); |
99193580aa9d
fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents:
381
diff
changeset
|
5536 | return 0; |
99193580aa9d
fixes realloc problem and memory leak in isfileindir() in sync.c
Mike Becker <universe@uap-core.de>
parents:
381
diff
changeset
|
5537 | } |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5538 | } else { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5539 | free(wd); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5540 | return 0; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5541 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5542 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5543 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5544 | 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
|
5545 | free(wd); |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5546 | } else { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5547 | fullpath = strdup(path); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5548 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5549 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5550 | // TODO: normalize path |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5551 | DavBool not_in_dir = 0; |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5552 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5553 | cxstring fp = cx_str(fullpath); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5554 | cxstring dp = cx_str(dir->path); |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5555 | if(fp.length == dp.length) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5556 | if(cx_strcmp(fp, dp)) { |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5557 | not_in_dir = 1; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5558 | } |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5559 | } else if(fp.length < dp.length) { |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5560 | not_in_dir = 1; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5561 | } else { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5562 | if(!cx_strprefix(fp, dp)) { |
531
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5563 | not_in_dir = 1; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5564 | } else { |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5565 | if(dp.ptr[dp.length-1] == '/') { |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5566 | dp.length--; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5567 | } |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5568 | if(fp.ptr[dp.length] != '/') { |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5569 | not_in_dir = 1; |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5570 | } |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5571 | } |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5572 | } |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5573 | |
fa54e3a1250a
implements list-versions for deltav syncdirs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
530
diff
changeset
|
5574 | if(not_in_dir) { |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5575 | free(fullpath); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5576 | return 0; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5577 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5578 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5579 | // TODO: check filter |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5580 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5581 | f->dir = dir; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5582 | 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
|
5583 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5584 | free(fullpath); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5585 | return 1; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5586 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5587 | |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5588 | 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
|
5589 | if(dostat) { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5590 | SYS_STAT s; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5591 | if(sys_stat(path, &s)) { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5592 | switch(errno) { |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5593 | case EACCES: return 2; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5594 | case ENOENT: return 1; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5595 | default: return 3; |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5596 | } |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5597 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5598 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5599 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5600 | char *sdir = cmd_getoption(args, "syncdir"); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5601 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5602 | if(sdir) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5603 | SyncDirectory *dir = scfg_get_dir(sdir); |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5604 | if(!dir) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5605 | return 6; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5606 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5607 | if(!isfileindir(dir, path, f)) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5608 | return 4; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5609 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5610 | } else { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5611 | SyncDirectory *target = NULL; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5612 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5613 | CxIterator i = scfg_directory_iterator(); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5614 | cx_foreach(SyncDirectory *, dir, i) { |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5615 | if(isfileindir(dir, path, f)) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5616 | if(target) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5617 | return 5; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5618 | } else { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5619 | target = dir; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5620 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5621 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5622 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5623 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5624 | if(!target) { |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5625 | return 4; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5626 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5627 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5628 | |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5629 | return 0; |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5630 | } |
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5631 | |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5632 | 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
|
5633 | switch(err) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5634 | case 1: log_error("File %s: not found\n", path); break; |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5635 | case 2: log_error("File %s: permission denied\n", path); break; |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5636 | case 3: log_error("File %s: stat failed: %s\n", path, strerror(errno)); break; |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5637 | case 4: log_error("File %s is not in any syncdir\n", path); break; |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5638 | case 5: log_error("File %s is in multiple syncdirs\n", path); break; |
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5639 | case 6: log_error("Syncdir not found\n"); break; |
527
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5640 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5641 | } |
d0e37224eba1
adds possibility to restore specific files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
526
diff
changeset
|
5642 | |
372
2e15ff88a0ab
adds tag management commands to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
370
diff
changeset
|
5643 | |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5644 | int cmd_add_directory(CmdArgs *args) { |
799
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5645 | DavConfig *davconfig = get_config(); |
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5646 | |
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5647 | if(!davconfig->repositories) { |
294
dd5c0ebdf54f
fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
5648 | 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
|
5649 | fprintf(stderr, "Abort\n"); |
dd5c0ebdf54f
fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
5650 | return -1; |
dd5c0ebdf54f
fixes dav startup without .dav dir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
288
diff
changeset
|
5651 | } |
799
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5652 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5653 | log_printf("Each sync directory must have an unique name.\n"); |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5654 | char *name = assistant_getcfg("name"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5655 | if(!name) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5656 | fprintf(stderr, "Abort\n"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5657 | return -1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5658 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5659 | if(scfg_get_dir(name)) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5660 | 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
|
5661 | return -1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5662 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5663 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5664 | log_printf("Enter local directory path.\n"); |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5665 | char *path = assistant_getcfg("path"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5666 | if(!path) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5667 | fprintf(stderr, "Abort\n"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5668 | return -1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5669 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5670 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5671 | log_printf("Specify webdav repository.\n"); |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5672 | int i = 0; |
799
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5673 | for (DavCfgRepository *r = davconfig->repositories; r != NULL; r = r->next) { |
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5674 | log_printf("%d) %s\n", i, r->name.value.ptr); |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5675 | i++; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5676 | } |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5677 | 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
|
5678 | char *reponame = NULL; |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5679 | if(!repository) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5680 | fprintf(stderr, "Abort\n"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5681 | return -1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5682 | } |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5683 | int64_t reponum = 0; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5684 | if(util_strtoint(repository, &reponum)) { |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5685 | if(reponum < 0) { |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5686 | 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
|
5687 | return -1; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5688 | } |
799
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5689 | DavCfgRepository *r = cx_linked_list_at(davconfig->repositories, 0, |
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5690 | offsetof(DavCfgRepository, next), |
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5691 | reponum); |
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5692 | if(r != NULL) { |
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5693 | reponame = r->name.value.ptr; |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5694 | } else { |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5695 | 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
|
5696 | return -1; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5697 | } |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5698 | } else { |
799
d479b5e25b6e
fix missing cmd_add_directory() implementation after ucx upgrade
Mike Becker <universe@uap-core.de>
parents:
795
diff
changeset
|
5699 | if(dav_config_get_repository(davconfig, cx_str(repository))) { |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5700 | reponame = repository; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5701 | } else { |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5702 | 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
|
5703 | return -1; |
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5704 | } |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5705 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5706 | |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5707 | log_printf("Enter collection relative to the repository base url.\n"); |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5708 | char *collection = assistant_getdefcfg("collection", "/"); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5709 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5710 | char *db = generate_db_name(name); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5711 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5712 | SyncDirectory dir; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5713 | memset(&dir, 0, sizeof(SyncDirectory)); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5714 | dir.name = name; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5715 | dir.path = path; |
215
781aee172901
dav-sync add-directory shows list of repositories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
5716 | dir.repository = reponame; |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5717 | dir.collection = collection; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5718 | dir.trash = ".trash"; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5719 | dir.database = db; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5720 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5721 | int ret = 0; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5722 | if(add_directory(&dir)) { |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5723 | 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
|
5724 | ret = -1; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5725 | } else { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5726 | log_printf("\nAdded directory: %s (%s)\n", name, path); |
200
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5727 | } |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5728 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5729 | free(name); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5730 | free(path); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5731 | free(repository); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5732 | free(collection); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5733 | free(db); |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5734 | |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5735 | return ret; |
cc474cf2c2f5
added add-directory command to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
199
diff
changeset
|
5736 | } |
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
|
5737 | |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5738 | int cmd_list_dirs() { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5739 | CxIterator iter = scfg_directory_iterator(); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5740 | cx_foreach(SyncDirectory *, dir, iter) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5741 | log_printf("%s\n", dir->name); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5742 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5743 | return 0; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5744 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5745 | |
734
b2cd82149116
add support for the secret store to dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
725
diff
changeset
|
5746 | int cmd_check_repositories(CmdArgs *a) { |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5747 | int ret = EXIT_SUCCESS; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5748 | |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5749 | CxList *reponames = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5750 | { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5751 | CxIterator iter = scfg_directory_iterator(); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5752 | cx_foreach(SyncDirectory *, dir, iter) { |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5753 | cxListAdd(reponames, dir->repository); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5754 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5755 | } |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5756 | |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5757 | CxIterator iter = cxListIterator(reponames); |
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5758 | cx_foreach(char *, reponame, iter) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5759 | log_printf("Checking %s... ", reponame); |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
5760 | DavCfgRepository *repo = dav_config_get_repository(get_config(), cx_str(reponame)); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5761 | if (!repo) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5762 | log_printf(" not found in config.xml!\n"); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5763 | ret = EXIT_FAILURE; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5764 | } else { |
795
05647e862a17
add new config parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
789
diff
changeset
|
5765 | DavSession *sn = create_session(a, ctx, repo, repo->url.value.ptr); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5766 | if (sn) { |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5767 | DavResource *res = dav_query(sn, |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5768 | "select - from / with depth = 0"); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5769 | if (res) { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5770 | log_printf("OK.\n"); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5771 | dav_resource_free(res); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5772 | } else { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5773 | log_printf("unavailable!\n"); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5774 | ret = EXIT_FAILURE; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5775 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5776 | dav_session_destroy(sn); |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5777 | } else { |
781
08d887af3971
replace printf with log_printf in sync.c
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
780
diff
changeset
|
5778 | log_printf("cannot create session!\n"); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5779 | ret = EXIT_FAILURE; |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5780 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5781 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5782 | } |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5783 | |
852 | 5784 | cxListFree(reponames); |
256
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5785 | |
54433cb371df
implements check-repositories command for dav-sync
Mike Becker <universe@uap-core.de>
parents:
254
diff
changeset
|
5786 | 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
|
5787 | } |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
5788 | |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
5789 | char* create_locktoken_file(const char *syncdirname, const char *locktoken) { |
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
739
diff
changeset
|
5790 | cxmutstr fname = cx_asprintf("locktoken-%s.txt", syncdirname); |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
5791 | 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
|
5792 | free(fname.ptr); |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
5793 | |
411
a182e503617b
using new io abstraction in dav-sync
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
405
diff
changeset
|
5794 | 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
|
5795 | if(file) { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5796 | log_error("%s\n", locktoken); |
313
d721250984d0
fixes possible UAF for locktocken paths, if file could not be opened
Mike Becker <universe@uap-core.de>
parents:
302
diff
changeset
|
5797 | 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
|
5798 | 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
|
5799 | } else { |
783
36a7f2ea7d12
add error logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
782
diff
changeset
|
5800 | log_error("Cannot create locktoken file: %s", strerror(errno)); |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
5801 | 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
|
5802 | return NULL; |
296
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
5803 | } |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
5804 | } |
bb49953b1cf8
dav-sync writes the locktoken to a file now
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
294
diff
changeset
|
5805 | |
542
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5806 | 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
|
5807 | 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
|
5808 | 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
|
5809 | 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
|
5810 | 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
|
5811 | if(enc_hash && keyname) { |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5812 | 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
|
5813 | if(!key) { |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5814 | return NULL; |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5815 | } |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5816 | |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5817 | size_t len = 0; |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5818 | 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
|
5819 | if(!dec_hash) { |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5820 | return NULL; |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5821 | } |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5822 | |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5823 | 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
|
5824 | free(dec_hash); |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5825 | return hex_hash; |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5826 | } |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5827 | } else { |
679
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
5828 | char *hash = dav_get_string_property_ns(res, DAV_NS, "content-hash"); |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
5829 | if(hash) { |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
5830 | return strdup(hash); |
0d352b79363a
fix some versioning related bugs and add tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
675
diff
changeset
|
5831 | } |
542
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5832 | } |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5833 | return NULL; |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5834 | } |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5835 | |
558
1a9e6a5c1e79
fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents:
557
diff
changeset
|
5836 | 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
|
5837 | 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
|
5838 | 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
|
5839 | if(res->session->key) { |
558
1a9e6a5c1e79
fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents:
557
diff
changeset
|
5840 | 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
|
5841 | if(enc_hash) { |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5842 | 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
|
5843 | free(enc_hash); |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5844 | } |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5845 | } |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5846 | } else { |
558
1a9e6a5c1e79
fixes several signedness issues
Mike Becker <universe@uap-core.de>
parents:
557
diff
changeset
|
5847 | 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
|
5848 | 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
|
5849 | free(hex_hash); |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5850 | } |
060a8cda7f62
adds wrapper functions for setting/getting the content hash
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
5851 | } |