dav/sync.c

changeset 367
4a6a59f89f9f
parent 366
5228b912c925
child 368
11797f33bc24
equal deleted inserted replaced
366:5228b912c925 367:4a6a59f89f9f
40 #include <ucx/properties.h> 40 #include <ucx/properties.h>
41 #include <dirent.h> 41 #include <dirent.h>
42 42
43 #include <libidav/webdav.h> 43 #include <libidav/webdav.h>
44 #include <libidav/utils.h> 44 #include <libidav/utils.h>
45 #include <libidav/crypto.h>
45 46
46 #include "config.h" 47 #include "config.h"
47 #include "scfg.h" 48 #include "scfg.h"
48 #include "sopt.h" 49 #include "sopt.h"
49 #include "db.h" 50 #include "db.h"
1245 res->tags_updated = db_res->tags_updated; 1246 res->tags_updated = db_res->tags_updated;
1246 if(db_res->etag) { 1247 if(db_res->etag) {
1247 res->etag = strdup(db_res->etag); 1248 res->etag = strdup(db_res->etag);
1248 } 1249 }
1249 1250
1251 if(dir->tagconfig && dir->tagconfig->scan && !res->tags_updated) {
1252 UcxBuffer *tags = sync_get_file_tag_data(dir, res);
1253 if(tags) {
1254 if(db_res->tags_hash) {
1255 char *hash = dav_create_hash(tags->space, tags->size);
1256 if(strcmp(hash, db_res->tags_hash)) {
1257 res->tags_updated = 1;
1258 }
1259 free(hash);
1260 } else {
1261 res->tags_updated = 1;
1262 }
1263 }
1264 }
1265
1250 if(db_res->last_modified == res->last_modified && db_res->size == res->size) { 1266 if(db_res->last_modified == res->last_modified && db_res->size == res->size) {
1251 return 0; 1267 return 0;
1252 } 1268 }
1253 } 1269 }
1254 return 1; 1270 return 1;
1348 // TODO: free stuff 1364 // TODO: free stuff
1349 1365
1350 return ret; 1366 return ret;
1351 } 1367 }
1352 1368
1353 UcxList* sync_get_file_tags(SyncDirectory *dir, LocalResource *res) { 1369 UcxBuffer* sync_get_file_tag_data(SyncDirectory *dir, LocalResource *res) {
1354 UcxList *tags = NULL;
1355
1356 if(!dir->tagconfig) { 1370 if(!dir->tagconfig) {
1357 return NULL; 1371 return NULL;
1358 } 1372 }
1373 UcxBuffer *buf = NULL;
1359 if(dir->tagconfig->store == TAG_STORE_XATTR) { 1374 if(dir->tagconfig->store == TAG_STORE_XATTR) {
1360 ssize_t tag_length = 0; 1375 ssize_t tag_length = 0;
1361 char *local_path = util_concat_path(dir->path, res->path); 1376 char *local_path = util_concat_path(dir->path, res->path);
1362 char* tag_data = xattr_get(local_path, "tags", &tag_length); 1377 char* tag_data = xattr_get(
1378 local_path,
1379 dir->tagconfig->local_format == TAG_FORMAT_MACOS ? MACOS_TAG_XATTR : "tags",
1380 &tag_length);
1363 free(local_path); 1381 free(local_path);
1364 1382
1365 if(tag_length > 0) { 1383 if(tag_length > 0) {
1384 buf = ucx_buffer_new(tag_data, (size_t)tag_length, UCX_BUFFER_AUTOFREE);
1385 buf->size = (size_t)tag_length;
1386 }
1387 }
1388 return buf;
1389 }
1390
1391 UcxList* sync_get_file_tags(SyncDirectory *dir, LocalResource *res) {
1392 UcxList *tags = NULL;
1393
1394 if(!dir->tagconfig) {
1395 return NULL;
1396 }
1397 if(dir->tagconfig->store == TAG_STORE_XATTR) {
1398 UcxBuffer *tag_buf = res->cached_tags ?
1399 res->cached_tags :
1400 sync_get_file_tag_data(dir, res);
1401
1402 if(tag_buf) {
1403 res->tags_hash = dav_create_hash(tag_buf->space, tag_buf->size);
1404
1366 switch(dir->tagconfig->local_format) { 1405 switch(dir->tagconfig->local_format) {
1367 default: break; 1406 default: break;
1368 case TAG_FORMAT_TEXT: { 1407 case TAG_FORMAT_TEXT: {
1369 tags = parse_text_taglist(tag_data, tag_length); 1408 tags = parse_text_taglist(tag_buf->space, tag_buf->size);
1370 break; 1409 break;
1371 } 1410 }
1372 case TAG_FORMAT_CSV: { 1411 case TAG_FORMAT_CSV: {
1373 tags = parse_csv_taglist(tag_data, tag_length); 1412 tags = parse_csv_taglist(tag_buf->space, tag_buf->size);
1374 break; 1413 break;
1375 } 1414 }
1376 case TAG_FORMAT_MACOS: { 1415 case TAG_FORMAT_MACOS: {
1377 tags = parse_macos_taglist(tag_data, tag_length); 1416 tags = parse_macos_taglist(tag_buf->space, tag_buf->size);
1378 break; 1417 break;
1379 } 1418 }
1419 }
1420 if(!res->cached_tags) {
1421 // we created the buffer therefore we destroy it
1422 ucx_buffer_free(tag_buf);
1380 } 1423 }
1381 } 1424 }
1382 } 1425 }
1383 1426
1384 return tags; 1427 return tags;

mercurial