300 int sync_delete = 0; |
300 int sync_delete = 0; |
301 int sync_error = 0; |
301 int sync_error = 0; |
302 |
302 |
303 UcxMap *svrres = ucx_map_new(db->resources->count); |
303 UcxMap *svrres = ucx_map_new(db->resources->count); |
304 |
304 |
|
305 UcxList *statls = NULL; |
|
306 |
305 UcxList *stack = ucx_list_prepend(NULL, ls->children); |
307 UcxList *stack = ucx_list_prepend(NULL, ls->children); |
306 while(stack) { |
308 while(stack) { |
307 DavResource *res = stack->data; |
309 DavResource *res = stack->data; |
308 stack = ucx_list_remove(stack, stack); |
310 stack = ucx_list_remove(stack, stack); |
309 |
311 |
330 // server |
332 // server |
331 LocalResource *local = ucx_map_cstr_get(db->resources, res->path); |
333 LocalResource *local = ucx_map_cstr_get(db->resources, res->path); |
332 ucx_map_cstr_put(svrres, res->path, local); |
334 ucx_map_cstr_put(svrres, res->path, local); |
333 ucx_map_cstr_remove(db->resources, res->path); |
335 ucx_map_cstr_remove(db->resources, res->path); |
334 |
336 |
|
337 if(local->last_modified == 0) { |
|
338 // stat this file later (directory) |
|
339 statls = ucx_list_prepend(statls, local); |
|
340 } |
|
341 |
335 if(res->children) { |
342 if(res->children) { |
336 stack = ucx_list_prepend(stack, res->children); |
343 stack = ucx_list_prepend(stack, res->children); |
337 } |
344 } |
338 res = res->next; |
345 res = res->next; |
339 } |
346 } |
340 } |
347 } |
|
348 |
|
349 // stat all files with unknown lastmodified date |
|
350 UCX_FOREACH(elm, statls) { |
|
351 LocalResource *l = elm->data; |
|
352 char *local_path = util_concat_path(dir->path, l->path); |
|
353 struct stat s; |
|
354 if(!stat(local_path, &s)) { |
|
355 l->last_modified = s.st_mtime; |
|
356 } |
|
357 free(local_path); |
|
358 } |
|
359 ucx_list_free(statls); |
341 |
360 |
342 // delete every remotely removed resource |
361 // delete every remotely removed resource |
343 UcxMapIterator i = ucx_map_iterator(db->resources); |
362 UcxMapIterator i = ucx_map_iterator(db->resources); |
344 LocalResource *local; |
363 LocalResource *local; |
345 UcxList *rmdirs = NULL; |
364 UcxList *rmdirs = NULL; |
406 LocalResource *local = ucx_map_cstr_get(db->resources, res->path); |
425 LocalResource *local = ucx_map_cstr_get(db->resources, res->path); |
407 char *local_path = util_concat_path(dir->path, res->path); |
426 char *local_path = util_concat_path(dir->path, res->path); |
408 |
427 |
409 char *etag = dav_get_property(res, "D:getetag"); |
428 char *etag = dav_get_property(res, "D:getetag"); |
410 struct stat s; |
429 struct stat s; |
|
430 memset(&s, 0, sizeof(struct stat)); |
411 if(local && !res->iscollection) { |
431 if(local && !res->iscollection) { |
412 int exists = 1; |
432 int exists = 1; |
413 if(stat(local_path, &s)) { |
433 if(stat(local_path, &s)) { |
414 // Ignore the fact, that the file is locally removed. If the |
434 // Ignore the fact, that the file is locally removed. If the |
415 // server has an updated version, we read the file or the |
435 // server has an updated version, we read the file or the |
463 if(ret == 0) { |
483 if(ret == 0) { |
464 if(!local) { |
484 if(!local) { |
465 // new local resource |
485 // new local resource |
466 local = calloc(1, sizeof(LocalResource)); |
486 local = calloc(1, sizeof(LocalResource)); |
467 local->path = util_concat_path(res->path, "/"); |
487 local->path = util_concat_path(res->path, "/"); |
468 local->last_modified = s.st_mtime; |
488 local->last_modified = 0; |
469 ucx_map_cstr_put(db->resources, local->path, local); |
489 ucx_map_cstr_put(db->resources, local->path, local); |
470 } |
490 } |
471 } |
491 } |
472 } else { |
492 } else { |
473 if(!tmp_path) { |
493 if(!tmp_path) { |