177 |
177 |
178 return 0; |
178 return 0; |
179 } |
179 } |
180 |
180 |
181 int sync_get_resource(SyncDirectory *dir, DavResource *res, SyncDatabase *db) { |
181 int sync_get_resource(SyncDirectory *dir, DavResource *res, SyncDatabase *db) { |
|
182 LocalResource *removed = ucx_map_cstr_get(db->remove, res->path); |
|
183 if(removed) { |
|
184 return 0; |
|
185 } |
|
186 |
182 LocalResource *local = ucx_map_cstr_get(db->resources, res->path); |
187 LocalResource *local = ucx_map_cstr_get(db->resources, res->path); |
183 char *local_path = util_concat_path(dir->path, res->path); |
188 char *local_path = util_concat_path(dir->path, res->path); |
184 |
189 |
185 char *etag = dav_get_property(res, "D:getetag"); |
190 char *etag = dav_get_property(res, "D:getetag"); |
186 struct stat s; |
191 struct stat s; |
304 repo->user, |
309 repo->user, |
305 repo->password); |
310 repo->password); |
306 dav_session_set_flags(sn, get_repository_flags(repo)); |
311 dav_session_set_flags(sn, get_repository_flags(repo)); |
307 sn->key = dav_context_get_key(ctx, repo->default_key); |
312 sn->key = dav_context_get_key(ctx, repo->default_key); |
308 |
313 |
|
314 // upload all changed files |
309 UcxList *resources = local_scan(dir, db); |
315 UcxList *resources = local_scan(dir, db); |
310 UCX_FOREACH(elm, resources) { |
316 UCX_FOREACH(elm, resources) { |
311 char *path = elm->data; |
317 char *path = elm->data; |
312 printf("put: %s\n", path); |
318 printf("put: %s\n", path); |
313 DavResource *res = dav_resource_new(sn, path); |
319 DavResource *res = dav_resource_new(sn, path); |
314 sync_put_resource(dir, res, db); |
320 sync_put_resource(dir, res, db); |
315 dav_resource_free(res); |
321 dav_resource_free(res); |
316 free(path); |
322 free(path); |
317 } |
323 } |
318 ucx_list_free(resources); |
324 ucx_list_free(resources); |
|
325 |
|
326 // delete all removed files |
|
327 UcxMapIterator i = ucx_map_iterator(db->remove); |
|
328 LocalResource *local; |
|
329 UCX_MAP_FOREACH(key, local, i) { |
|
330 DavResource *res = dav_resource_new(sn, local->path); |
|
331 printf("delete: %s\n", res->path); |
|
332 if(dav_delete(res)) { |
|
333 if(sn->error != DAV_NOT_FOUND) { |
|
334 fprintf(stderr, "Cannot delete resource %s\n", res->path); |
|
335 } |
|
336 } |
|
337 dav_resource_free(res); |
|
338 // TODO: free local resource |
|
339 ucx_map_remove(db->remove, key); |
|
340 } |
|
341 |
|
342 // TODO: free res |
319 |
343 |
320 // store db |
344 // store db |
321 if(store_db(db, dir->database)) { |
345 if(store_db(db, dir->database)) { |
322 fprintf(stderr, "Cannot store sync db\n"); |
346 fprintf(stderr, "Cannot store sync db\n"); |
323 return -1; |
347 return -1; |