forked from haiwen/seafile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone-mgr.h
165 lines (141 loc) · 5.07 KB
/
clone-mgr.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef CLONE_MGR_H
#define CLONE_MGR_H
#include <glib.h>
#include "db.h"
struct _SeafileSession;
typedef struct _CloneTask CloneTask;
typedef struct _SeafCloneManager SeafCloneManager;
enum {
CLONE_STATE_INIT,
CLONE_STATE_CHECK_HTTP,
CLONE_STATE_CONNECT,
CLONE_STATE_CHECK_PROTOCOL,
CLONE_STATE_INDEX,
CLONE_STATE_FETCH,
CLONE_STATE_CHECKOUT,
CLONE_STATE_MERGE,
CLONE_STATE_DONE,
CLONE_STATE_ERROR,
CLONE_STATE_CANCEL_PENDING,
CLONE_STATE_CANCELED,
N_CLONE_STATES,
};
enum {
CLONE_OK,
CLONE_ERROR_CONNECT,
CLONE_ERROR_INDEX,
CLONE_ERROR_FETCH,
CLONE_ERROR_PASSWD,
CLONE_ERROR_CHECKOUT,
CLONE_ERROR_MERGE,
CLONE_ERROR_INTERNAL,
N_CLONE_ERRORS,
};
struct _CloneTask {
SeafCloneManager *manager;
int state;
int error;
char repo_id[37];
int repo_version;
char peer_id[41];
char *peer_addr;
char *peer_port;
char *token;
char *email;
char *repo_name; /* For better display. */
char *tx_id;
char *worktree;
uid_t uid;
gid_t gid;
char *passwd;
int enc_version;
char *random_key;
char root_id[41];
gboolean is_readonly;
/* Http sync fields */
char *server_url;
char *effective_url;
gboolean use_fileserver_port;
int http_protocol_version;
gboolean http_sync;
char server_head_id[41];
gboolean server_side_merge;
};
const char *
clone_task_state_to_str (int state);
const char *
clone_task_error_to_str (int error);
struct _SeafCloneManager {
struct _SeafileSession *seaf;
sqlite3 *db;
GHashTable *tasks;
struct CcnetTimer *check_timer;
};
SeafCloneManager *
seaf_clone_manager_new (struct _SeafileSession *session);
int
seaf_clone_manager_init (SeafCloneManager *mgr);
int
seaf_clone_manager_start (SeafCloneManager *mgr);
char *
seaf_clone_manager_gen_default_worktree (SeafCloneManager *mgr,
const char *worktree_parent,
const char *repo_name);
char *
seaf_clone_manager_add_task (SeafCloneManager *mgr,
const char *repo_id,
int repo_version,
const char *peer_id,
const char *repo_name,
const char *token,
const char *passwd,
const char *magic,
int enc_version,
const char *random_key,
const char *worktree,
uid_t uid,
gid_t gid,
const char *peer_addr,
const char *peer_port,
const char *email,
const char *more_info,
GError **error);
/*
* Similar to seaf_clone_manager_add_task.
* But create a new dir for worktree under @wt_parent.
* The semantics is to "download" the repo into @wt_parent.
*/
char *
seaf_clone_manager_add_download_task (SeafCloneManager *mgr,
const char *repo_id,
int repo_version,
const char *peer_id,
const char *repo_name,
const char *token,
const char *passwd,
const char *magic,
int enc_version,
const char *random_key,
const char *wt_parent,
uid_t uid,
gid_t gid,
const char *peer_addr,
const char *peer_port,
const char *email,
const char *more_info,
GError **error);
int
seaf_clone_manager_cancel_task (SeafCloneManager *mgr,
const char *repo_id);
int
seaf_clone_manager_remove_task (SeafCloneManager *mgr,
const char *repo_id);
CloneTask *
seaf_clone_manager_get_task (SeafCloneManager *mgr,
const char *repo_id);
GList *
seaf_clone_manager_get_tasks (SeafCloneManager *mgr);
gboolean
seaf_clone_manager_check_worktree_path (SeafCloneManager *mgr, const char *path, GError **error);
#endif