Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[client] Fix conflict handling bug in clone.
A conflict file cannot be produced.
  • Loading branch information
killing committed Apr 2, 2015
1 parent 37bf2a3 commit 9838f69
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 12 deletions.
26 changes: 21 additions & 5 deletions common/fs-mgr.c
Expand Up @@ -234,7 +234,8 @@ seaf_fs_manager_checkout_file (SeafFSManager *mgr,
const char *in_repo_path,
const char *conflict_head_id,
gboolean force_conflict,
gboolean *conflicted)
gboolean *conflicted,
const char *email)
{
Seafile *seafile;
char *blk_id;
Expand Down Expand Up @@ -273,11 +274,26 @@ seaf_fs_manager_checkout_file (SeafFSManager *mgr,
if (force_conflict || seaf_util_rename (tmp_path, file_path) < 0) {
*conflicted = TRUE;

SeafRepo *repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id);
if (!repo)
goto bad;
/* XXX
* In new syncing protocol and http sync, files are checked out before
* the repo is created. So we can't get user email from repo at this point.
* So a email parameter is needed.
* For old syncing protocol, repo always exists when files are checked out.
* This is a quick and dirty hack. A cleaner solution should modifiy the
* code of old syncing protocol to pass in email too. But I don't want to
* spend more time on the nearly obsoleted code.
*/
const char *suffix = NULL;
if (email) {
suffix = email;
} else {
SeafRepo *repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id);
if (!repo)
goto bad;
suffix = email;
}

conflict_path = gen_conflict_path (file_path, repo->email, (gint64)time(NULL));
conflict_path = gen_conflict_path (file_path, suffix, (gint64)time(NULL));

seaf_warning ("Cannot update %s, creating conflict file %s.\n",
file_path, conflict_path);
Expand Down
3 changes: 2 additions & 1 deletion common/fs-mgr.h
Expand Up @@ -179,7 +179,8 @@ seaf_fs_manager_checkout_file (SeafFSManager *mgr,
const char *in_repo_path,
const char *conflict_head_id,
gboolean force_conflict,
gboolean *conflicted);
gboolean *conflicted,
const char *email);

#endif /* not SEAFILE_SERVER */

Expand Down
2 changes: 2 additions & 0 deletions daemon/clone-mgr.c
Expand Up @@ -782,6 +782,7 @@ add_transfer_task (CloneTask *task, GError **error)
task->server_side_merge,
task->passwd,
task->worktree,
task->email,
error);
if (!task->tx_id)
return -1;
Expand All @@ -796,6 +797,7 @@ add_transfer_task (CloneTask *task, GError **error)
task->passwd,
task->worktree,
task->http_protocol_version,
task->email,
error);
if (ret < 0)
return -1;
Expand Down
5 changes: 4 additions & 1 deletion daemon/http-tx-mgr.c
Expand Up @@ -108,6 +108,7 @@ http_tx_task_free (HttpTxTask *task)
g_free (task->token);
g_free (task->passwd);
g_free (task->worktree);
g_free (task->email);
g_free (task);
}

Expand Down Expand Up @@ -2464,12 +2465,13 @@ http_tx_manager_add_download (HttpTxManager *manager,
const char *passwd,
const char *worktree,
int protocol_version,
const char *email,
GError **error)
{
HttpTxTask *task;
SeafRepo *repo;

if (!repo_id || !token || !host || !server_head_id) {
if (!repo_id || !token || !host || !server_head_id || !email) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Empty argument(s)");
return -1;
}
Expand All @@ -2490,6 +2492,7 @@ http_tx_manager_add_download (HttpTxManager *manager,

memcpy (task->head, server_head_id, 40);
task->protocol_version = protocol_version;
task->email = g_strdup(email);

task->state = TASK_STATE_NORMAL;

Expand Down
2 changes: 2 additions & 0 deletions daemon/http-tx-mgr.h
Expand Up @@ -68,6 +68,7 @@ struct _HttpTxTask {
int type;
char *host;
gboolean is_clone;
char *email;

char head[41];

Expand Down Expand Up @@ -107,6 +108,7 @@ http_tx_manager_add_download (HttpTxManager *manager,
const char *passwd,
const char *worktree,
int protocol_version,
const char *email,
GError **error);

int
Expand Down
3 changes: 2 additions & 1 deletion daemon/merge-recursive.c
Expand Up @@ -590,7 +590,8 @@ static int update_file_flags(struct merge_options *o,
o->remote_head,
path,
FALSE,
&conflicted) < 0) {
&conflicted,
NULL) < 0) {
g_warning("Failed to checkout file %s.\n", file_id);
refresh = 0;
goto update_cache;
Expand Down
3 changes: 2 additions & 1 deletion daemon/repo-mgr.c
Expand Up @@ -3069,7 +3069,8 @@ checkout_file (const char *repo_id,
name,
conflict_head_id,
force_conflict,
&conflicted) < 0) {
&conflicted,
is_http ? http_task->email : task->email) < 0) {
seaf_warning ("Failed to checkout file %s.\n", path);
g_free (path);
return FETCH_CHECKOUT_FAILED;
Expand Down
5 changes: 4 additions & 1 deletion daemon/sync-mgr.c
Expand Up @@ -729,6 +729,7 @@ start_fetch_if_necessary (SyncTask *task, const char *remote_head)
task->server_side_merge,
NULL,
NULL,
repo->email,
&error);

if (error != NULL) {
Expand All @@ -748,6 +749,7 @@ start_fetch_if_necessary (SyncTask *task, const char *remote_head)
FALSE,
NULL, NULL,
task->http_version,
repo->email,
&error) < 0) {
seaf_warning ("Failed to start http download: %s.\n", error->message);
seaf_sync_manager_set_task_error (task, SYNC_ERROR_START_FETCH);
Expand Down Expand Up @@ -2172,7 +2174,8 @@ handle_locked_file_update (SeafRepo *repo, struct index_state *istate,
path,
master->commit_id,
force_conflict,
&conflicted) < 0) {
&conflicted,
repo->email) < 0) {
seaf_warning ("Failed to checkout previously locked file %s in repo "
"%s(%.8s).\n",
path, repo->name, repo->id);
Expand Down
5 changes: 4 additions & 1 deletion daemon/transfer-mgr.c
Expand Up @@ -242,6 +242,7 @@ seaf_transfer_task_free (TransferTask *task)
g_free (task->from_branch);
g_free (task->to_branch);
g_free (task->token);
g_free (task->email);

if (task->fs_roots)
object_list_free (task->fs_roots);
Expand Down Expand Up @@ -585,11 +586,12 @@ seaf_transfer_manager_add_download (SeafTransferManager *manager,
gboolean server_side_merge,
const char *passwd,
const char *worktree,
const char *email,
GError **error)
{
TransferTask *task;

if (!repo_id || !from_branch || !to_branch || !token) {
if (!repo_id || !from_branch || !to_branch || !token || !email) {
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_BAD_ARGS, "Empty argument(s)");
return NULL;
}
Expand All @@ -605,6 +607,7 @@ seaf_transfer_manager_add_download (SeafTransferManager *manager,
TASK_TYPE_DOWNLOAD);
task->state = TASK_STATE_NORMAL;
task->repo_version = repo_version;
task->email = g_strdup(email);

task->server_side_merge = server_side_merge;

Expand Down
2 changes: 2 additions & 0 deletions daemon/transfer-mgr.h
Expand Up @@ -141,6 +141,7 @@ struct _TransferTask {
int last_runtime_state;
int type;
gboolean is_clone; /* TRUE when fetching a new repo. */
char *email;
int error;

char *dest_id;
Expand Down Expand Up @@ -231,6 +232,7 @@ seaf_transfer_manager_add_download (SeafTransferManager *manager,
gboolean server_side_merge,
const char *passwd,
const char *worktree,
const char *email,
GError **error);

char *
Expand Down
3 changes: 2 additions & 1 deletion daemon/vc-utils.c
Expand Up @@ -795,7 +795,8 @@ checkout_entry (struct cache_entry *ce,
ce->name,
conflict_head_id,
force_conflict,
&conflicted) < 0) {
&conflicted,
NULL) < 0) {
g_warning ("Failed to checkout file %s.\n", path);
g_free (path);
return -1;
Expand Down

0 comments on commit 9838f69

Please sign in to comment.