dav/sync.c

changeset 54
fc34bd28a22a
parent 53
ddc4efc9b0f8
child 55
4cb389452a44
equal deleted inserted replaced
53:ddc4efc9b0f8 54:fc34bd28a22a
71 71
72 xmlGenericErrorFunc fnc = xmlerrorfnc; 72 xmlGenericErrorFunc fnc = xmlerrorfnc;
73 initGenericErrorDefaultFunc(&fnc); 73 initGenericErrorDefaultFunc(&fnc);
74 ctx = dav_context_new(); 74 ctx = dav_context_new();
75 load_config(ctx); 75 load_config(ctx);
76
77 // copy proxy config
78 memcpy(ctx->http_proxy, get_http_proxy(), sizeof(Proxy));
79 memcpy(ctx->https_proxy, get_https_proxy(), sizeof(Proxy));
80
76 if(load_sync_config()) { 81 if(load_sync_config()) {
77 return EXIT_FAILURE; 82 return EXIT_FAILURE;
78 } 83 }
79 84
80 int ret = EXIT_FAILURE; 85 int ret = EXIT_FAILURE;
225 // resource is already up-to-date on the client 230 // resource is already up-to-date on the client
226 return 0; 231 return 0;
227 } 232 }
228 } 233 }
229 234
230 if(cdt && s.st_mtim.tv_sec != local->last_modified) { 235 if(cdt && s.st_mtime != local->last_modified) {
231 // file modified on the server and on the client 236 // file modified on the server and on the client
232 rename_local_file(dir, db, local->path); 237 rename_local_file(dir, db, local->path);
233 } 238 }
234 } else { 239 } else {
235 if(stat(local_path, &s)) { 240 if(stat(local_path, &s)) {
276 if(local->etag) { 281 if(local->etag) {
277 free(local->etag); 282 free(local->etag);
278 } 283 }
279 // set metadata from stat 284 // set metadata from stat
280 local->etag = etag; 285 local->etag = etag;
281 local->last_modified = s.st_mtim.tv_sec; 286 local->last_modified = s.st_mtime;
282 local->size = s.st_size; 287 local->size = s.st_size;
283 } 288 }
284 } 289 }
285 290
286 free(local_path); 291 free(local_path);
293 if(stat(local_path, &s)) { 298 if(stat(local_path, &s)) {
294 free(local_path); 299 free(local_path);
295 return; 300 return;
296 } 301 }
297 302
298 if(s.st_mtim.tv_sec != res->last_modified) { 303 if(s.st_mtime != res->last_modified) {
299 free(local_path); 304 free(local_path);
300 return; 305 return;
301 } 306 }
302 307
303 printf("delete: %s\n", res->path); 308 printf("delete: %s\n", res->path);
434 DIR *local_dir = opendir(local_path); 439 DIR *local_dir = opendir(local_path);
435 440
436 if(!local_dir) { 441 if(!local_dir) {
437 fprintf(stderr, "Cannot open directory %s\n", local_path); 442 fprintf(stderr, "Cannot open directory %s\n", local_path);
438 } else { 443 } else {
444 #ifdef _WIN32
445 long namemax = 255;
446 #else
439 long namemax = namemax = pathconf(path, _PC_NAME_MAX); 447 long namemax = namemax = pathconf(path, _PC_NAME_MAX);
448 #endif
440 if(namemax == 0) { 449 if(namemax == 0) {
441 namemax = 255; 450 namemax = 255;
442 } 451 }
443 struct dirent *ent = malloc(sizeof(struct dirent) + namemax + 1); 452 struct dirent *ent = malloc(sizeof(struct dirent) + namemax + 1);
444 struct dirent *res = NULL; 453 struct dirent *res = NULL;
538 LocalResource *res = ucx_map_cstr_get(db->resources, path); 547 LocalResource *res = ucx_map_cstr_get(db->resources, path);
539 if(res) { 548 if(res) {
540 // the file is already in the database 549 // the file is already in the database
541 // compare length and lastmodified date 550 // compare length and lastmodified date
542 551
543 if(res->last_modified == s.st_mtim.tv_sec 552 if(res->last_modified == s.st_mtime
544 && res->size == s.st_size) 553 && res->size == s.st_size)
545 { 554 {
546 // file unchanged 555 // file unchanged
547 return NULL; 556 return NULL;
548 } else { 557 } else {
549 // update db entries 558 // update db entries
550 res->size = s.st_size; 559 res->size = s.st_size;
551 res->last_modified = s.st_mtim.tv_sec; 560 res->last_modified = s.st_mtime;
552 561
553 return res; 562 return res;
554 } 563 }
555 } else { 564 } else {
556 LocalResource *res = calloc(1, sizeof(LocalResource)); 565 LocalResource *res = calloc(1, sizeof(LocalResource));
557 res->path = strdup(path); 566 res->path = strdup(path);
558 res->etag = NULL; 567 res->etag = NULL;
559 res->last_modified = s.st_mtim.tv_sec; 568 res->last_modified = s.st_mtime;
560 res->size = s.st_size; 569 res->size = s.st_size;
561 ucx_map_cstr_put(db->resources, res->path, res); 570 ucx_map_cstr_put(db->resources, res->path, res);
562 return res; 571 return res;
563 } 572 }
564 } else { 573 } else {

mercurial