diff --git a/daemon/repo-mgr.c b/daemon/repo-mgr.c index aa269d5b6..9385248c0 100644 --- a/daemon/repo-mgr.c +++ b/daemon/repo-mgr.c @@ -865,13 +865,13 @@ static int scan_worktree_for_changes (struct index_state *istate, SeafRepo *repo, SeafileCrypt *crypt, GList *ignore_list) { + remove_deleted (istate, repo->worktree, "", ignore_list, NULL); + if (add_recursive (repo->id, repo->version, repo->email, istate, repo->worktree, "", crypt, FALSE, ignore_list, NULL, NULL, NULL) < 0) return -1; - remove_deleted (istate, repo->worktree, "", ignore_list, NULL); - return 0; } @@ -1406,7 +1406,7 @@ handle_unmerged_index_entries (SeafRepo *repo, struct index_state *istate, static int index_add (SeafRepo *repo, struct index_state *istate, - gboolean is_initial_commit, gboolean handle_unmerged) + gboolean is_force_commit, gboolean handle_unmerged) { SeafileCrypt *crypt = NULL; GList *ignore_list = NULL; @@ -1418,8 +1418,13 @@ index_add (SeafRepo *repo, struct index_state *istate, ignore_list = seaf_repo_load_ignore_files (repo->worktree); - if (apply_worktree_changes_to_index (repo, istate, crypt, ignore_list) < 0) { - seaf_warning ("Failed to apply worktree changes to index.\n"); + if (!is_force_commit) { + if (apply_worktree_changes_to_index (repo, istate, crypt, ignore_list) < 0) { + seaf_warning ("Failed to apply worktree changes to index.\n"); + ret = -1; + } + } else if (scan_worktree_for_changes (istate, repo, crypt, ignore_list) < 0) { + seaf_warning ("Failed to scan worktree for changes.\n"); ret = -1; } @@ -1755,7 +1760,7 @@ print_index (struct index_state *istate) } char * -seaf_repo_index_commit (SeafRepo *repo, const char *desc, gboolean is_initial_commit, +seaf_repo_index_commit (SeafRepo *repo, const char *desc, gboolean is_force_commit, GError **error) { SeafRepoManager *mgr = repo->manager; @@ -1779,7 +1784,7 @@ seaf_repo_index_commit (SeafRepo *repo, const char *desc, gboolean is_initial_co if (need_handle_unmerged_index (repo, &istate)) unmerged = TRUE; - if (index_add (repo, &istate, is_initial_commit, unmerged) < 0) { + if (index_add (repo, &istate, is_force_commit, unmerged) < 0) { g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Failed to add"); goto error; } diff --git a/daemon/sync-mgr.c b/daemon/sync-mgr.c index 410e4e711..ac49679d0 100644 --- a/daemon/sync-mgr.c +++ b/daemon/sync-mgr.c @@ -90,6 +90,9 @@ has_old_commits_to_upload (SeafRepo *repo); static int sync_repo_v2 (SeafSyncManager *manager, SeafRepo *repo, gboolean is_manual_sync); +static gboolean +check_http_protocol (SeafSyncManager *mgr, SeafRepo *repo, gboolean *is_checking); + SeafSyncManager* seaf_sync_manager_new (SeafileSession *seaf) { @@ -393,6 +396,19 @@ seaf_sync_manager_add_sync_task (SeafSyncManager *mgr, return -1; } + SyncInfo *info = get_sync_info (mgr, repo->id); + + if (info->in_sync) + return 0; + + gboolean is_checking_http = FALSE; + if (seaf->enable_http_sync && repo->version > 0) { + if (check_http_protocol (mgr, repo, &is_checking_http)) { + sync_repo_v2 (mgr, repo, TRUE); + return 0; + } + } + /* If relay is not ready or protocol version is not determined, * need to wait. */ @@ -402,11 +418,6 @@ seaf_sync_manager_add_sync_task (SeafSyncManager *mgr, return 0; } - SyncInfo *info = get_sync_info (mgr, repo->id); - - if (info->in_sync) - return 0; - ServerState *state = g_hash_table_lookup (mgr->server_states, repo->relay_id); @@ -1515,7 +1526,7 @@ commit_job (void *vtask) res->changed = TRUE; res->success = TRUE; - char *commit_id = seaf_repo_index_commit (repo, "", task->is_initial_commit, + char *commit_id = seaf_repo_index_commit (repo, "", task->is_manual_sync, &error); if (commit_id == NULL && error != NULL) { seaf_warning ("[Sync mgr] Failed to commit to repo %s(%.8s).\n", @@ -1842,6 +1853,10 @@ sync_repo_v2 (SeafSyncManager *manager, SeafRepo *repo, gboolean is_manual_sync) * but it's before 30-second schedule. */ goto out; + } else if (is_manual_sync) { + task = create_sync_task_v2 (manager, repo, is_manual_sync, FALSE); + commit_repo (task); + goto out; } else if (create_commit_from_event_queue (manager, repo, is_manual_sync)) goto out; }