dav/sync.c

changeset 573
b8f798d240ab
parent 570
00b7b8e86c48
child 574
c36eddf167a8
equal deleted inserted replaced
572:1eac93fcef77 573:b8f798d240ab
2330 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) { 2330 if(!strcmp(ent->name, ".") || !strcmp(ent->name, "..")) {
2331 continue; 2331 continue;
2332 } 2332 }
2333 2333
2334 char *new_path = util_concat_path(p, ent->name); 2334 char *new_path = util_concat_path(p, ent->name);
2335 int isdir = 0; 2335 LocalResource *res = local_resource_new(dir, db, new_path);
2336 LocalResource *res = local_resource_new(dir, db, new_path, &isdir); 2336 if(res->isdirectory) {
2337 if(isdir) {
2338 resources = ucx_list_append(resources, res); 2337 resources = ucx_list_append(resources, res);
2339 stack = ucx_list_prepend(stack, new_path); 2338 stack = ucx_list_prepend(stack, new_path);
2340 } else if(res) { 2339 } else if(res) {
2341 resources = ucx_list_append(resources, res); 2340 resources = ucx_list_append(resources, res);
2342 free(new_path); 2341 free(new_path);
2381 value.length -= 2; 2380 value.length -= 2;
2382 } 2381 }
2383 value = sstrdup(value); 2382 value = sstrdup(value);
2384 2383
2385 if(!sstrcmp(name, S("put"))) { 2384 if(!sstrcmp(name, S("put"))) {
2386 int isdir; 2385 LocalResource *res = local_resource_new(dir, db, value.ptr);
2387 LocalResource *res = local_resource_new(dir, db, value.ptr, &isdir);
2388 if(res) { 2386 if(res) {
2389 resources = ucx_list_append(resources, res); 2387 resources = ucx_list_append(resources, res);
2390 } 2388 }
2391 } else if(!sstrcmp(name, S("remove"))) { 2389 } else if(!sstrcmp(name, S("remove"))) {
2392 ucx_map_sstr_remove(db->resources, value); 2390 ucx_map_sstr_remove(db->resources, value);
2398 ucx_properties_free(parser); 2396 ucx_properties_free(parser);
2399 2397
2400 return resources; 2398 return resources;
2401 } 2399 }
2402 2400
2403 LocalResource* local_resource_new(SyncDirectory *dir, SyncDatabase *db, char *path, int *isdir) { 2401 LocalResource* local_resource_new(SyncDirectory *dir, SyncDatabase *db, char *path) {
2404 char *file_path = create_local_path(dir, path); 2402 char *file_path = create_local_path(dir, path);
2405 SYS_STAT s; 2403 SYS_STAT s;
2406 if(sys_stat(file_path, &s)) { 2404 if(sys_stat(file_path, &s)) {
2407 fprintf(stderr, "Cannot stat file %s\n", file_path); 2405 fprintf(stderr, "Cannot stat file %s\n", file_path);
2408 free(file_path); 2406 free(file_path);
2409 return NULL; 2407 return NULL;
2410 } 2408 }
2411 free(file_path); 2409 free(file_path);
2412 2410
2413 if(!S_ISDIR(s.st_mode)) { 2411 if(!S_ISDIR(s.st_mode)) {
2414 *isdir = 0;
2415 LocalResource *res = calloc(1, sizeof(LocalResource)); 2412 LocalResource *res = calloc(1, sizeof(LocalResource));
2416 res->path = strdup(path); 2413 res->path = strdup(path);
2417 res->etag = NULL; 2414 res->etag = NULL;
2418 res->last_modified = s.st_mtime; 2415 res->last_modified = s.st_mtime;
2419 res->size = s.st_size; 2416 res->size = s.st_size;
2420 res->mode = s.st_mode & 07777; 2417 res->mode = s.st_mode & 07777;
2421 res->uid = s.st_uid; 2418 res->uid = s.st_uid;
2422 res->gid = s.st_gid; 2419 res->gid = s.st_gid;
2423 return res; 2420 return res;
2424 } else { 2421 } else {
2425 *isdir = 1;
2426 LocalResource *res = calloc(1, sizeof(LocalResource)); 2422 LocalResource *res = calloc(1, sizeof(LocalResource));
2427 res->path = util_concat_path(path, "/"); 2423 res->path = util_concat_path(path, "/");
2428 res->last_modified = s.st_mtime; 2424 res->last_modified = s.st_mtime;
2429 res->mode = s.st_mode & 07777; 2425 res->mode = s.st_mode & 07777;
2430 res->uid = s.st_uid; 2426 res->uid = s.st_uid;

mercurial