| 100 | | static osync_bool osync_filesync_parse_settings(OSyncFileEnv *env, OSyncPluginInfo *info, OSyncError **error) |
|---|
| 101 | | { |
|---|
| 102 | | osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, env, info, error); |
|---|
| | 96 | static osync_bool osync_filesync_parse_settings(OSyncFileEnv *env, const char *data, OSyncError **error) |
|---|
| | 97 | { |
|---|
| | 98 | osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, env, data, error); |
|---|
| 227 | | |
|---|
| 228 | | // Object format "file" |
|---|
| 229 | | if (!strcmp("file", osync_objformat_get_name(dir->objformat))) { |
|---|
| 230 | | OSyncFileFormat *file = osync_try_malloc0(sizeof(OSyncFileFormat), &error); |
|---|
| 231 | | if (!file) |
|---|
| 232 | | goto error; |
|---|
| 233 | | file->path = g_strdup(osync_change_get_uid(change)); |
|---|
| 234 | | |
|---|
| 235 | | struct stat filestats; |
|---|
| 236 | | stat(filename, &filestats); |
|---|
| 237 | | file->userid = filestats.st_uid; |
|---|
| 238 | | file->groupid = filestats.st_gid; |
|---|
| 239 | | file->mode = filestats.st_mode; |
|---|
| 240 | | file->last_mod = filestats.st_mtime; |
|---|
| 241 | | |
|---|
| 242 | | if (!osync_file_read(filename, &(file->data), &(file->size), &error)) { |
|---|
| 243 | | g_free(file->path); |
|---|
| 244 | | g_free(file); |
|---|
| 245 | | goto error; |
|---|
| 246 | | } |
|---|
| 247 | | |
|---|
| 248 | | odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), dir->objformat, &error); |
|---|
| 249 | | if (!odata) { |
|---|
| 250 | | g_free(file->data); |
|---|
| 251 | | g_free(file->path); |
|---|
| 252 | | g_free(file); |
|---|
| 253 | | goto error; |
|---|
| 254 | | } |
|---|
| 255 | | |
|---|
| 256 | | // Any other object format |
|---|
| 257 | | } else { |
|---|
| 258 | | |
|---|
| 259 | | char *buf; |
|---|
| 260 | | unsigned int size; |
|---|
| 261 | | if (!osync_file_read(filename, &buf, &size, &error)) { |
|---|
| 262 | | osync_change_unref(change); |
|---|
| 263 | | osync_context_report_osyncwarning(ctx, error); |
|---|
| 264 | | osync_error_unref(&error); |
|---|
| 265 | | g_free(filename); |
|---|
| 266 | | } |
|---|
| 267 | | |
|---|
| 268 | | odata = osync_data_new(buf, size, dir->objformat, &error); |
|---|
| 269 | | if (!odata) { |
|---|
| 270 | | osync_change_unref(change); |
|---|
| 271 | | osync_context_report_osyncwarning(ctx, error); |
|---|
| 272 | | osync_error_unref(&error); |
|---|
| 273 | | } |
|---|
| 274 | | } |
|---|
| 275 | | |
|---|
| | 221 | |
|---|
| | 222 | OSyncFileFormat *file = osync_try_malloc0(sizeof(OSyncFileFormat), &error); |
|---|
| | 223 | if (!file) |
|---|
| | 224 | goto error; |
|---|
| | 225 | file->path = g_strdup(osync_change_get_uid(change)); |
|---|
| | 226 | |
|---|
| | 227 | struct stat filestats; |
|---|
| | 228 | stat(filename, &filestats); |
|---|
| | 229 | file->userid = filestats.st_uid; |
|---|
| | 230 | file->groupid = filestats.st_gid; |
|---|
| | 231 | file->mode = filestats.st_mode; |
|---|
| | 232 | file->last_mod = filestats.st_mtime; |
|---|
| | 233 | |
|---|
| | 234 | if (!osync_file_read(filename, &(file->data), &(file->size), &error)) |
|---|
| | 235 | goto error_free_file; |
|---|
| | 236 | |
|---|
| | 237 | OSyncData *odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), env->objformat, &error); |
|---|
| | 238 | if (!odata) |
|---|
| | 239 | goto error_free_data; |
|---|
| | 240 | |
|---|
| 326 | | |
|---|
| 327 | | if (!strcmp(osync_objformat_get_name(osync_data_get_objformat(odata)), "file")) { |
|---|
| 328 | | g_assert(size == sizeof(OSyncFileFormat)); |
|---|
| 329 | | |
|---|
| 330 | | OSyncFileFormat *file = (OSyncFileFormat *)buffer; |
|---|
| 331 | | |
|---|
| 332 | | if (!osync_file_write(filename, file->data, file->size, file->mode, &error)) |
|---|
| 333 | | goto error; |
|---|
| 334 | | } else { |
|---|
| 335 | | if (!osync_file_write(filename, buffer, size, 0, &error)) |
|---|
| 336 | | goto error; |
|---|
| 337 | | } |
|---|
| 338 | | |
|---|
| | 296 | g_assert(size == sizeof(OSyncFileFormat)); |
|---|
| | 297 | |
|---|
| | 298 | OSyncFileFormat *file = (OSyncFileFormat *)buffer; |
|---|
| | 299 | |
|---|
| | 300 | if (!osync_file_write(filename, file->data, file->size, file->mode, &error)) |
|---|
| | 301 | goto error; |
|---|
| 441 | | OSyncData *odata = NULL; |
|---|
| 442 | | |
|---|
| 443 | | // Objformat "file" |
|---|
| 444 | | if (!strcmp("file", osync_objformat_get_name(directory->objformat))) { |
|---|
| 445 | | OSyncFileFormat *file = osync_try_malloc0(sizeof(OSyncFileFormat), &error); |
|---|
| 446 | | if (!file) { |
|---|
| 447 | | osync_change_unref(change); |
|---|
| 448 | | osync_context_report_osyncwarning(ctx, error); |
|---|
| 449 | | osync_error_unref(&error); |
|---|
| 450 | | g_free(filename); |
|---|
| 451 | | g_free(relative_filename); |
|---|
| 452 | | continue; |
|---|
| 453 | | } |
|---|
| 454 | | file->path = g_strdup(relative_filename); |
|---|
| 455 | | |
|---|
| 456 | | if (!osync_file_read(filename, &(file->data), &(file->size), &error)) { |
|---|
| 457 | | osync_change_unref(change); |
|---|
| 458 | | osync_context_report_osyncwarning(ctx, error); |
|---|
| 459 | | osync_error_unref(&error); |
|---|
| 460 | | g_free(filename); |
|---|
| 461 | | continue; |
|---|
| 462 | | } |
|---|
| 463 | | |
|---|
| 464 | | odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), directory->objformat, &error); |
|---|
| 465 | | if (!odata) { |
|---|
| 466 | | osync_change_unref(change); |
|---|
| 467 | | osync_context_report_osyncwarning(ctx, error); |
|---|
| 468 | | osync_error_unref(&error); |
|---|
| 469 | | continue; |
|---|
| 470 | | } |
|---|
| 471 | | // Any other specifc object format. |
|---|
| 472 | | } else { |
|---|
| 473 | | char *buf; |
|---|
| 474 | | unsigned int size; |
|---|
| 475 | | if (!osync_file_read(filename, &buf, &size, &error)) { |
|---|
| 476 | | osync_change_unref(change); |
|---|
| 477 | | osync_context_report_osyncwarning(ctx, error); |
|---|
| 478 | | osync_error_unref(&error); |
|---|
| 479 | | g_free(filename); |
|---|
| 480 | | continue; |
|---|
| 481 | | } |
|---|
| 482 | | |
|---|
| 483 | | odata = osync_data_new(buf, size, directory->objformat, &error); |
|---|
| 484 | | if (!odata) { |
|---|
| 485 | | osync_change_unref(change); |
|---|
| 486 | | osync_context_report_osyncwarning(ctx, error); |
|---|
| 487 | | osync_error_unref(&error); |
|---|
| 488 | | continue; |
|---|
| 489 | | } |
|---|
| | 415 | if (!osync_file_read(filename, &(file->data), &(file->size), &error)) { |
|---|
| | 416 | osync_change_unref(change); |
|---|
| | 417 | osync_context_report_osyncwarning(ctx, error); |
|---|
| | 418 | osync_error_unref(&error); |
|---|
| | 419 | g_free(filename); |
|---|
| | 420 | continue; |
|---|
| | 421 | } |
|---|
| | 422 | |
|---|
| | 423 | OSyncData *odata = osync_data_new((char *)file, sizeof(OSyncFileFormat), directory->env->objformat, &error); |
|---|
| | 424 | if (!odata) { |
|---|
| | 425 | osync_change_unref(change); |
|---|
| | 426 | osync_context_report_osyncwarning(ctx, error); |
|---|
| | 427 | osync_error_unref(&error); |
|---|
| | 428 | continue; |
|---|