Changeset 2352
- Timestamp:
- 07/22/07 20:57:55 (1 year ago)
- Files:
-
- plugins/file-sync/src/file_sync.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/file-sync/src/file_sync.c
r2348 r2352 212 212 213 213 214 static osync_bool osync_filesync_read(void * data, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change)215 { 216 osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, data, info, ctx, change);214 static osync_bool osync_filesync_read(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change) 215 { 216 osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, userdata, info, ctx, change); 217 217 OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); 218 OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); 218 219 OSyncFileDir *dir = osync_objtype_sink_get_userdata(sink); 219 OSyncFileEnv *env = (OSyncFileEnv *) data;220 OSyncFileEnv *env = (OSyncFileEnv *)userdata; 220 221 OSyncError *error = NULL; 221 222 222 223 char *filename = g_strdup_printf("%s/%s", dir->path, osync_change_get_uid(change)); 223 224 224 OSyncFileFormat *file = osync_try_malloc0(sizeof(OSyncFileFormat), &error); 225 if (!file) 225 char *data; 226 unsigned int size; 227 228 if (!osync_file_read(filename, &data, &size, &error)) { 229 osync_change_unref(change); 230 osync_context_report_osyncwarning(ctx, error); 231 osync_error_unref(&error); 226 232 goto error; 227 file->path = g_strdup(osync_change_get_uid(change)); 228 229 struct stat filestats; 230 stat(filename, &filestats); 231 file->userid = filestats.st_uid; 232 file->groupid = filestats.st_gid; 233 file->mode = filestats.st_mode; 234 file->last_mod = filestats.st_mtime; 235 236 if (!osync_file_read(filename, &(file->data), &(file->size), &error)) 237 goto error_free_file; 238 239 OSyncData *odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), env->objformat, &error); 240 if (!odata) 241 goto error_free_data; 242 233 } 234 235 OSyncData *odata = NULL; 236 237 if (strcmp("file", dir->objformat)) { 238 239 OSyncObjFormat *objformat = osync_format_env_find_objformat(formatenv, dir->objformat); 240 odata = osync_data_new(data, size, objformat, &error); 241 if (!odata) { 242 osync_change_unref(change); 243 osync_context_report_osyncwarning(ctx, error); 244 osync_error_unref(&error); 245 goto error_free_data; 246 } 247 248 } else { 249 250 OSyncFileFormat *file = osync_try_malloc0(sizeof(OSyncFileFormat), &error); 251 if (!file) { 252 osync_change_unref(change); 253 osync_context_report_osyncwarning(ctx, error); 254 osync_error_unref(&error); 255 goto error_free_data; 256 } 257 258 259 struct stat filestats; 260 stat(filename, &filestats); 261 file->userid = filestats.st_uid; 262 file->groupid = filestats.st_gid; 263 file->mode = filestats.st_mode; 264 file->last_mod = filestats.st_mtime; 265 266 file->data = data; 267 file->size = size; 268 file->path = g_strdup(osync_change_get_uid(change)); 269 270 odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), env->objformat, &error); 271 if (!odata) { 272 osync_change_unref(change); 273 osync_context_report_osyncwarning(ctx, error); 274 osync_error_unref(&error); 275 g_free(file->path); 276 g_free(file); 277 goto error_free_data; 278 } 279 } 280 243 281 osync_data_set_objtype(odata, osync_objtype_sink_get_name(sink)); 244 282 osync_change_set_data(change, odata); … … 253 291 254 292 error_free_data: 255 g_free(file->data); 256 error_free_file: 257 g_free(file->path); 258 g_free(file); 293 g_free(data); 259 294 error: 260 295 g_free(filename); … … 380 415 * 381 416 */ 382 static void osync_filesync_report_dir(OSyncFileDir *directory, const char *subdir, OSyncContext *ctx)417 static void osync_filesync_report_dir(OSyncFileDir *directory, OSyncPluginInfo *info, const char *subdir, OSyncContext *ctx) 383 418 { 384 419 GError *gerror = NULL; … … 390 425 osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, directory, subdir, ctx); 391 426 427 OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); 428 392 429 path = g_build_filename(directory->path, subdir, NULL); 393 430 osync_trace(TRACE_INTERNAL, "path %s", path); … … 419 456 /* Recurse into subdirectories */ 420 457 if (directory->recursive) 421 osync_filesync_report_dir(directory, relative_filename, ctx);458 osync_filesync_report_dir(directory, info, relative_filename, ctx); 422 459 } else if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { 423 460 … … 426 463 char *hash = osync_filesync_generate_hash(&buf); 427 464 465 428 466 OSyncChangeType type = osync_hashtable_get_changetype(directory->hashtable, relative_filename, hash); 429 467 if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { … … 434 472 } 435 473 osync_hashtable_update_hash(directory->hashtable, type, relative_filename, hash); 436 474 437 475 /* Report normal files */ 438 476 OSyncChange *change = osync_change_new(&error); … … 452 490 g_free(hash); 453 491 454 OSyncFileFormat *file = osync_try_malloc0(sizeof(OSyncFileFormat), &error); 455 if (!file) { 456 osync_change_unref(change); 457 osync_context_report_osyncwarning(ctx, error); 458 osync_error_unref(&error); 459 g_free(filename); 460 g_free(relative_filename); 461 continue; 462 } 463 file->path = g_strdup(relative_filename); 464 492 493 char *data; 494 unsigned int size; 465 495 OSyncError *error = NULL; 466 if (!osync_file_read(filename, & (file->data), &(file->size), &error)) {496 if (!osync_file_read(filename, &data, &size, &error)) { 467 497 osync_change_unref(change); 468 498 osync_context_report_osyncwarning(ctx, error); … … 471 501 continue; 472 502 } 473 474 OSyncData *odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), directory->env->objformat, &error); 475 if (!odata) { 476 osync_change_unref(change); 477 osync_context_report_osyncwarning(ctx, error); 478 osync_error_unref(&error); 479 continue; 503 504 OSyncData *odata = NULL; 505 506 if (strcmp("file", directory->objformat)) { 507 508 OSyncObjFormat *objformat = osync_format_env_find_objformat(formatenv, directory->objformat); 509 odata = osync_data_new(data, size, objformat, &error); 510 if (!odata) { 511 osync_change_unref(change); 512 osync_context_report_osyncwarning(ctx, error); 513 osync_error_unref(&error); 514 g_free(data); 515 continue; 516 } 517 518 } else { 519 520 OSyncFileFormat *file = osync_try_malloc0(sizeof(OSyncFileFormat), &error); 521 if (!file) { 522 osync_change_unref(change); 523 osync_context_report_osyncwarning(ctx, error); 524 osync_error_unref(&error); 525 g_free(filename); 526 g_free(relative_filename); 527 continue; 528 } 529 530 file->data = data; 531 file->size = size; 532 file->path = g_strdup(relative_filename); 533 534 odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), directory->env->objformat, &error); 535 if (!odata) { 536 osync_change_unref(change); 537 osync_context_report_osyncwarning(ctx, error); 538 osync_error_unref(&error); 539 g_free(data); 540 continue; 541 } 480 542 } 481 543 482 544 osync_data_set_objtype(odata, osync_objtype_sink_get_name(directory->sink)); 483 545 osync_change_set_data(change, odata); … … 516 578 osync_trace(TRACE_INTERNAL, "get_changes for %s", osync_objtype_sink_get_name(sink)); 517 579 518 osync_filesync_report_dir(dir, NULL, ctx);580 osync_filesync_report_dir(dir, info, NULL, ctx); 519 581 520 582 char **uids = osync_hashtable_get_deleted(dir->hashtable);
