1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <opensync/opensync.h>
#include <glib.h>
#include <string.h>
#include "sync_item.h"
#include "sync_group.h"
#include "sync_file_item.h"
#define FILE_PLUGIN "file-sync"
#define FILE_CONFIG "<config>" \
"<path>%s</path>" \
"<recursive>FALSE</recursive>" \
"</config>"
static OSyncMember *
sync_file_item_get_member (SyncItem *item, SyncGroup *group)
{
OSyncMember *member;
OSyncError *error = NULL;
OSyncConfigurationTypes type = NO_CONFIGURATION;
member = osync_member_new (sync_group_get_osync_group (group));
if (!osync_member_instance_plugin (member, FILE_PLUGIN, &error)) {
g_warning ("Error instancing file plug-in: %s",
osync_error_print (&error));
osync_error_free (&error);
return NULL;
}
if (!osync_member_need_config (member, &type, &error)) {
g_warning ("Error reading plug-in config requirements: %s",
osync_error_print (&error));
osync_error_free (&error);
return NULL;
}
if (type == NO_CONFIGURATION) {
g_warning (
"File sync plug-in reports no need for configuration");
} else {
const gchar *file_path;
gchar *file_config;
file_path = sync_item_get_adr (item);
if (g_mkdir_with_parents (file_path, 0755) == -1) {
g_warning ("Couldn't create directory '%s'", file_path);
return NULL;
}
file_config = g_strdup_printf (FILE_CONFIG, file_path);
osync_member_set_config (
member, file_config, strlen (file_config));
g_free (file_config);
}
return member;
}
SyncItem *
sync_file_item_new (const gchar *name, const gchar *adr)
{
return sync_item_new (name, adr, sync_file_item_get_member);
}
|