132 |
132 |
133 if(!ls->children) { |
133 if(!ls->children) { |
134 // TODO: free |
134 // TODO: free |
135 return 0; // empty repository |
135 return 0; // empty repository |
136 } |
136 } |
137 |
137 |
|
138 UcxMap *svrres = ucx_map_new(db->resources->count); |
|
139 |
138 UcxList *stack = ucx_list_prepend(NULL, ls->children); |
140 UcxList *stack = ucx_list_prepend(NULL, ls->children); |
139 while(stack) { |
141 while(stack) { |
140 DavResource *res = stack->data; |
142 DavResource *res = stack->data; |
141 stack = ucx_list_remove(stack, stack); |
143 stack = ucx_list_remove(stack, stack); |
142 |
144 |
143 while(res) { |
145 while(res) { |
|
146 // download the resource |
144 if(sync_get_resource(dir, res, db)) { |
147 if(sync_get_resource(dir, res, db)) { |
145 fprintf(stderr, "sync_get_resource failed for resource: %s\n", res->path); |
148 fprintf(stderr, "sync_get_resource failed for resource: %s\n", res->path); |
146 } |
149 } |
|
150 |
|
151 LocalResource *local = ucx_map_cstr_get(db->resources, res->path); |
|
152 ucx_map_cstr_put(svrres, res->path, local); |
|
153 ucx_map_cstr_remove(db->resources, res->path); |
147 |
154 |
148 if(res->children) { |
155 if(res->children) { |
149 stack = ucx_list_prepend(stack, res->children); |
156 stack = ucx_list_prepend(stack, res->children); |
150 } |
157 } |
151 res = res->next; |
158 res = res->next; |
152 } |
159 } |
153 } |
160 } |
|
161 |
|
162 UcxMapIterator i = ucx_map_iterator(db->resources); |
|
163 LocalResource *local; |
|
164 UCX_MAP_FOREACH(key, local, i) { |
|
165 sync_remove_resource(dir, local); |
|
166 } |
|
167 ucx_map_free(db->resources); |
|
168 db->resources = svrres; |
154 |
169 |
155 // TODO: cleanup |
170 // TODO: cleanup |
156 |
171 |
157 // store db |
172 // store db |
158 if(store_db(db, dir->database)) { |
173 if(store_db(db, dir->database)) { |
235 } |
250 } |
236 } |
251 } |
237 |
252 |
238 free(local_path); |
253 free(local_path); |
239 return ret; |
254 return ret; |
|
255 } |
|
256 |
|
257 void sync_remove_resource(SyncDirectory *dir, LocalResource *res) { |
|
258 char *local_path = util_concat_path(dir->path, res->path); |
|
259 struct stat s; |
|
260 if(stat(local_path, &s)) { |
|
261 free(local_path); |
|
262 return; |
|
263 } |
|
264 |
|
265 if(s.st_mtim.tv_sec != res->last_modified) { |
|
266 free(local_path); |
|
267 return; |
|
268 } |
|
269 |
|
270 printf("delete: %s\n", res->path); |
|
271 if(unlink(local_path)) { |
|
272 fprintf(stderr, "Cannot remove file %s\n", local_path); |
|
273 } |
|
274 free(local_path); |
240 } |
275 } |
241 |
276 |
242 int cmd_push(CmdArgs *a) { |
277 int cmd_push(CmdArgs *a) { |
243 if(a->argc != 1) { |
278 if(a->argc != 1) { |
244 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many"); |
279 fprintf(stderr, "Too %s arguments\n", a->argc < 1 ? "few" : "many"); |