Changeset 2347

Show
Ignore:
Timestamp:
07/22/07 14:38:45 (1 year ago)
Author:
dgollub
Message:

Reverted to r2254 file_sync.{c,h} ... current configurable storage
<objformat> implementation is just broken.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/file-sync/src/file_sync.c

    r2310 r2347  
    5050} 
    5151 
    52 static osync_bool osync_filesync_parse_directory(OSyncFileEnv *env, OSyncPluginInfo *info, xmlNode *cur, OSyncError **error) 
     52static osync_bool osync_filesync_parse_directory(OSyncFileEnv *env, xmlNode *cur, OSyncError **error) 
    5353{ 
    5454        osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, env, cur, error); 
    55  
    56         OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); 
    5755 
    5856        OSyncFileDir *dir = osync_try_malloc0(sizeof(OSyncFileDir), error); 
     
    6866                        } else if (!xmlStrcmp(cur->name, (const xmlChar *)"objtype")) { 
    6967                                dir->objtype = g_strdup(str); 
    70                         } else if (!xmlStrcmp(cur->name, (const xmlChar *)"objformat")) { 
    71                                 dir->objformat = osync_format_env_find_objformat(formatenv, str); 
    7268                        } else if (!xmlStrcmp(cur->name, (const xmlChar *)"recursive")) { 
    7369                                dir->recursive = (g_ascii_strcasecmp(str, "TRUE") == 0); 
     
    9894 
    9995/*Load the state from a xml file and return it in the conn struct*/ 
    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); 
     96static 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); 
    10399        xmlDoc *doc = NULL; 
    104100        xmlNode *cur = NULL; 
    105  
    106         const char *data = osync_plugin_info_get_config(info); 
    107101 
    108102        doc = xmlParseMemory(data, strlen(data) + 1); 
     
    130124                if (str) { 
    131125                        if (!xmlStrcmp(cur->name, (const xmlChar *)"directory")) { 
    132                                 if (!osync_filesync_parse_directory(env, info, cur->xmlChildrenNode, error)) 
     126                                if (!osync_filesync_parse_directory(env, cur->xmlChildrenNode, error)) 
    133127                                        goto error_free_doc; 
    134128                        } 
     
    221215        OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); 
    222216        OSyncFileDir *dir = osync_objtype_sink_get_userdata(sink); 
     217        OSyncFileEnv *env = (OSyncFileEnv *)data; 
    223218        OSyncError *error = NULL; 
    224         OSyncData *odata = NULL; 
    225219         
    226220        char *filename = g_strdup_printf("%s/%s", dir->path, osync_change_get_uid(change)); 
    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         
    276241        osync_data_set_objtype(odata, osync_objtype_sink_get_name(sink)); 
    277242        osync_change_set_data(change, odata); 
     
    285250        return TRUE; 
    286251 
     252error_free_data: 
     253        g_free(file->data); 
     254error_free_file: 
     255        g_free(file->path); 
     256        g_free(file); 
    287257error: 
    288258        g_free(filename); 
     
    324294                        osync_data_get_data(odata, &buffer, &size); 
    325295                        g_assert(buffer); 
    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; 
    339302                        break; 
    340303                default: 
     
    438401                        g_free(hash); 
    439402                         
     403                        OSyncFileFormat *file = osync_try_malloc0(sizeof(OSyncFileFormat), &error); 
     404                        if (!file) { 
     405                                osync_change_unref(change); 
     406                                osync_context_report_osyncwarning(ctx, error); 
     407                                osync_error_unref(&error); 
     408                                g_free(filename); 
     409                                g_free(relative_filename); 
     410                                continue; 
     411                        } 
     412                        file->path = g_strdup(relative_filename); 
     413                         
    440414                        OSyncError *error = NULL; 
    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; 
    490429                        } 
    491430                         
     
    515454        OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); 
    516455        OSyncFileDir *dir = osync_objtype_sink_get_userdata(sink); 
     456        OSyncFileEnv *env = (OSyncFileEnv *)data; 
    517457        int i = 0; 
    518458        OSyncError *error = NULL; 
     
    540480                osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); 
    541481                 
    542                 OSyncData *odata = osync_data_new(NULL, 0, dir->objformat, &error); 
     482                OSyncData *odata = osync_data_new(NULL, 0, env->objformat, &error); 
    543483                if (!odata) { 
    544484                        g_free(uids[i]); 
     
    627567         
    628568        OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); 
    629          
    630         if (!osync_filesync_parse_settings(env, info, error)) 
     569        env->objformat = osync_format_env_find_objformat(formatenv, "file"); 
     570         
     571        if (!osync_filesync_parse_settings(env, osync_plugin_info_get_config(info), error)) 
    631572                goto error_free_env; 
    632573         
     
    644585                dir->sink = sink; 
    645586                 
    646                 /* Use the configured object format. By default object format "file" is used. */ 
    647                 if (dir->objformat) { 
    648                         osync_objtype_sink_add_objformat(sink, osync_objformat_get_name(dir->objformat)); 
    649                 } else { 
    650                         osync_objtype_sink_add_objformat(sink, "file"); 
    651                         dir->objformat = osync_format_env_find_objformat(formatenv, "file"); 
    652                 } 
    653  
     587                /* The file format is the only one we understand */ 
     588                osync_objtype_sink_add_objformat(sink, "file"); 
     589                 
    654590                /* All sinks have the same functions of course */ 
    655591                OSyncObjTypeSinkFunctions functions; 
  • plugins/file-sync/src/file_sync.h

    r2287 r2347  
    4040typedef struct OSyncFileEnv { 
    4141        GList *directories; 
     42        OSyncObjFormat *objformat; 
    4243} OSyncFileEnv; 
    4344 
     
    5051        osync_bool recursive; 
    5152        OSyncFileEnv *env; 
    52         OSyncObjFormat *objformat; 
    5353} OSyncFileDir; 
    5454