pstatus namespace and cleanup
This commit is contained in:
parent
5c088cb260
commit
e48fda52a0
|
|
@ -346,7 +346,7 @@ static psock_t *get_connected_socket() {
|
|||
psync_free(auth);
|
||||
psync_free(user);
|
||||
psync_free(pass);
|
||||
psync_wait_status(PSTATUS_TYPE_RUN, PSTATUS_RUN_RUN | PSTATUS_RUN_PAUSE);
|
||||
pstatus_wait(PSTATUS_TYPE_RUN, PSTATUS_RUN_RUN | PSTATUS_RUN_PAUSE);
|
||||
|
||||
auth = psync_sql_cellstr("SELECT value FROM setting WHERE id='auth'");
|
||||
user = psync_sql_cellstr("SELECT value FROM setting WHERE id='user'");
|
||||
|
|
@ -382,18 +382,18 @@ static psock_t *get_connected_socket() {
|
|||
debug(D_WARNING, "tfa sleep");
|
||||
continue;
|
||||
}
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_REQUIRED);
|
||||
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_REQUIRED);
|
||||
pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
continue;
|
||||
}
|
||||
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
saveauth = psync_setting_get_bool(_PS(saveauth));
|
||||
|
||||
sock = papi_connect(apiserver, psync_setting_get_bool(_PS(usessl)));
|
||||
|
||||
if (unlikely_log(!sock)) {
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_OFFLINE);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_OFFLINE);
|
||||
psys_sleep_milliseconds(PSYNC_SLEEP_BEFORE_RECONNECT);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -450,7 +450,7 @@ static psock_t *get_connected_socket() {
|
|||
|
||||
if (unlikely_log(!res)) {
|
||||
psock_close(sock);
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_OFFLINE);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_OFFLINE);
|
||||
psys_sleep_milliseconds(PSYNC_SLEEP_BEFORE_RECONNECT);
|
||||
papi_conn_fail_inc();
|
||||
continue;
|
||||
|
|
@ -472,8 +472,8 @@ static psock_t *get_connected_socket() {
|
|||
psync_my_2fa_type = papi_find_result2(res, "tfatype", PARAM_NUM)->num;
|
||||
psync_my_2fa_code_type = 0;
|
||||
psync_my_2fa_code[0] = 0;
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_TFAREQ);
|
||||
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_TFAREQ);
|
||||
pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
psock_close(sock);
|
||||
psync_free(res);
|
||||
continue;
|
||||
|
|
@ -483,8 +483,8 @@ static psock_t *get_connected_socket() {
|
|||
psync_free(psync_my_verify_token);
|
||||
psync_my_verify_token =
|
||||
psync_strdup(papi_find_result2(res, "verifytoken", PARAM_STR)->str);
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_VERIFYREQ);
|
||||
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_VERIFYREQ);
|
||||
pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
psock_close(sock);
|
||||
psync_free(res);
|
||||
continue;
|
||||
|
|
@ -507,8 +507,8 @@ static psock_t *get_connected_socket() {
|
|||
|
||||
if (result == 2330) {
|
||||
psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT);
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_RELOCATING);
|
||||
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_RELOCATING);
|
||||
pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
psock_close(sock);
|
||||
psync_free(res);
|
||||
continue;
|
||||
|
|
@ -523,7 +523,7 @@ static psock_t *get_connected_socket() {
|
|||
psync_my_2fa_code[0] = 0;
|
||||
if (result == 2012 || result == 2064 || result == 2074 ||
|
||||
result == 2092)
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADCODE);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADCODE);
|
||||
else if (user && pass) {
|
||||
// Ugly fix, sorry :(
|
||||
if (!strcmp(user, "pass") && !strcmp(pass, "dummy")) {
|
||||
|
|
@ -533,21 +533,21 @@ static psock_t *get_connected_socket() {
|
|||
psys_sleep_milliseconds(1000);
|
||||
continue;
|
||||
} else {
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADLOGIN);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADLOGIN);
|
||||
psync_free(psync_my_pass);
|
||||
psync_my_pass = NULL;
|
||||
}
|
||||
} else {
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADTOKEN);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADTOKEN);
|
||||
psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT);
|
||||
}
|
||||
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
} else if (result == 4000)
|
||||
psys_sleep_milliseconds(5 * 60 * 1000);
|
||||
else if (result == 2205 || result == 2229) {
|
||||
psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT);
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_EXPIRED);
|
||||
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_EXPIRED);
|
||||
pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
} else if (result == 2237) {
|
||||
digest = 0;
|
||||
continue;
|
||||
|
|
@ -576,16 +576,16 @@ static psock_t *get_connected_socket() {
|
|||
if (unlikely_log(luserid != userid)) {
|
||||
if (check_user_relocated(luserid, sock)) {
|
||||
debug(D_NOTICE, "setting PSTATUS_AUTH_RELOCATED");
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_RELOCATED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_RELOCATED);
|
||||
} else {
|
||||
debug(D_NOTICE, "user mistmatch, db userid=%lu, connected userid=%lu",
|
||||
(unsigned long)luserid, (unsigned long)userid);
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_MISMATCH);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_MISMATCH);
|
||||
}
|
||||
psync_sql_rollback_transaction();
|
||||
psock_close(sock);
|
||||
psync_free(res);
|
||||
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
continue;
|
||||
}
|
||||
if (saveauth) {
|
||||
|
|
@ -671,11 +671,11 @@ static psock_t *get_connected_socket() {
|
|||
}
|
||||
psync_sql_free_result(q);
|
||||
}
|
||||
if (psync_status_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED) {
|
||||
if (pstatus_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED) {
|
||||
psync_sql_rollback_transaction();
|
||||
psock_close(sock);
|
||||
psync_free(res);
|
||||
psync_wait_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_wait(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
continue;
|
||||
}
|
||||
debug(D_NOTICE, "userid %lu", (unsigned long)userid);
|
||||
|
|
@ -1637,8 +1637,8 @@ static void process_deletefile(const binresult *entry) {
|
|||
static void start_download() {
|
||||
if (needdownload) {
|
||||
pdownload_wake();
|
||||
psync_status_recalc_to_download();
|
||||
psync_send_status_update();
|
||||
pstatus_download_recalc();
|
||||
pstatus_send_status_update();
|
||||
needdownload = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -2479,7 +2479,7 @@ static uint64_t process_entries(const binresult *entries, uint64_t newdiffid) {
|
|||
oused_quota = used_quota;
|
||||
needdownload = 0;
|
||||
pdiff_lock();
|
||||
if (psync_status_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED) {
|
||||
if (pstatus_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED) {
|
||||
pdiff_unlock();
|
||||
return psync_sql_cellint("SELECT value FROM setting WHERE id='diffid'", 0);
|
||||
}
|
||||
|
|
@ -2508,8 +2508,8 @@ static uint64_t process_entries(const binresult *entries, uint64_t newdiffid) {
|
|||
pdiff_unlock();
|
||||
if (needdownload) {
|
||||
pdownload_wake();
|
||||
psync_status_recalc_to_download();
|
||||
psync_send_status_update();
|
||||
pstatus_download_recalc();
|
||||
pstatus_send_status_update();
|
||||
needdownload = 0;
|
||||
}
|
||||
used_quota =
|
||||
|
|
@ -2525,9 +2525,9 @@ static void check_overquota() {
|
|||
if (isover != lisover) {
|
||||
lisover = isover;
|
||||
if (isover) {
|
||||
psync_set_status(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_OVERQUOTA);
|
||||
pstatus_set(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_OVERQUOTA);
|
||||
} else
|
||||
psync_set_status(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_QUOTAOK);
|
||||
pstatus_set(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_QUOTAOK);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2635,12 +2635,12 @@ static void handle_exception(psock_t **sock, subscribed_ids *ids,
|
|||
debug(D_NOTICE, "got a pdiff_wake() but no diff events in one "
|
||||
"second, closing socket");
|
||||
psock_close(*sock);
|
||||
if (psync_status_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED)
|
||||
if (pstatus_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED)
|
||||
ids->notificationid = 0;
|
||||
debug(D_NOTICE, "waiting for new socket");
|
||||
*sock = get_connected_socket();
|
||||
debug(D_NOTICE, "got new socket");
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
psync_syncer_check_delayed_syncs();
|
||||
ids->diffid =
|
||||
psync_sql_cellint("SELECT value FROM setting WHERE id='diffid'", 0);
|
||||
|
|
@ -2649,16 +2649,16 @@ static void handle_exception(psock_t **sock, subscribed_ids *ids,
|
|||
return;
|
||||
}
|
||||
debug(D_NOTICE, "exception handler %c", ex);
|
||||
if (ex == 'r' || psync_status_get(PSTATUS_TYPE_RUN) == PSTATUS_RUN_STOP ||
|
||||
psync_status_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED ||
|
||||
if (ex == 'r' || pstatus_get(PSTATUS_TYPE_RUN) == PSTATUS_RUN_STOP ||
|
||||
pstatus_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED ||
|
||||
psync_setting_get_bool(_PS(usessl)) != psock_is_ssl(*sock)) {
|
||||
psock_close(*sock);
|
||||
if (psync_status_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED)
|
||||
if (pstatus_get(PSTATUS_TYPE_AUTH) != PSTATUS_AUTH_PROVIDED)
|
||||
ids->notificationid = 0;
|
||||
debug(D_NOTICE, "waiting for new socket");
|
||||
*sock = get_connected_socket();
|
||||
debug(D_NOTICE, "got new socket");
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
psync_syncer_check_delayed_syncs();
|
||||
ids->diffid =
|
||||
psync_sql_cellint("SELECT value FROM setting WHERE id='diffid'", 0);
|
||||
|
|
@ -2673,7 +2673,7 @@ static void handle_exception(psock_t **sock, subscribed_ids *ids,
|
|||
psock_close_bad(*sock);
|
||||
pcache_clean_oneof(prefixes, ARRAY_SIZE(prefixes));
|
||||
*sock = get_connected_socket();
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
psync_syncer_check_delayed_syncs();
|
||||
send_diff_command(*sock, *ids);
|
||||
} else {
|
||||
|
|
@ -2877,14 +2877,14 @@ static void psync_diff_thread() {
|
|||
char *err = NULL;
|
||||
int should_free_res = 0;
|
||||
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
psync_send_status_update();
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
pstatus_send_status_update();
|
||||
|
||||
restart:
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
sock = get_connected_socket();
|
||||
debug(D_NOTICE, "connected");
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_SCANNING);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_SCANNING);
|
||||
ids.diffid =
|
||||
psync_sql_cellint("SELECT value FROM setting WHERE id='diffid'", 0);
|
||||
if (ids.diffid == 0) {
|
||||
|
|
@ -2937,7 +2937,7 @@ restart:
|
|||
goto restart;
|
||||
}
|
||||
check_overquota();
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
initialdownload = 0;
|
||||
psync_run_analyze_if_needed();
|
||||
psync_syncer_check_delayed_syncs();
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ static int task_mkdir(const char *path) {
|
|||
} else
|
||||
return -1;
|
||||
}
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ static int task_renamedir(const char *oldpath, const char *newpath) {
|
|||
} else
|
||||
return -1;
|
||||
}
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -601,7 +601,7 @@ static int task_download_file(download_task_t *dt) {
|
|||
psync_status.bytestodownloadcurrent += serversize;
|
||||
pthread_mutex_unlock(¤t_downloads_mutex);
|
||||
dt->size = serversize;
|
||||
psync_status_send_update();
|
||||
pstatus_send_update();
|
||||
}
|
||||
|
||||
sql = psync_sql_query_rdlock(
|
||||
|
|
@ -774,9 +774,9 @@ static int task_download_file(download_task_t *dt) {
|
|||
PSYNC_START_NEW_DOWNLOADS_TRESHOLD)
|
||||
pthread_cond_signal(¤t_downloads_cond);
|
||||
pthread_mutex_unlock(¤t_downloads_mutex);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
dt->downloadedsize += rd;
|
||||
if (unlikely(!psync_statuses_ok_array(requiredstatuses,
|
||||
if (unlikely(!pstatus_ok_status_arr(requiredstatuses,
|
||||
ARRAY_SIZE(requiredstatuses))))
|
||||
goto err2;
|
||||
}
|
||||
|
|
@ -802,7 +802,7 @@ static int task_download_file(download_task_t *dt) {
|
|||
rd = pfile_read(ifd, buff, rd);
|
||||
if (unlikely_log(rd <= 0) ||
|
||||
unlikely_log(psync_file_writeall_checkoverquota(fd, buff, rd)) ||
|
||||
unlikely(!psync_statuses_ok_array(requiredstatuses,
|
||||
unlikely(!pstatus_ok_status_arr(requiredstatuses,
|
||||
ARRAY_SIZE(requiredstatuses)))) {
|
||||
pfile_close(ifd);
|
||||
goto err2;
|
||||
|
|
@ -816,7 +816,7 @@ static int task_download_file(download_task_t *dt) {
|
|||
PSYNC_START_NEW_DOWNLOADS_TRESHOLD)
|
||||
pthread_cond_signal(¤t_downloads_cond);
|
||||
pthread_mutex_unlock(¤t_downloads_mutex);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
dt->downloadedsize += rd;
|
||||
}
|
||||
pfile_close(ifd);
|
||||
|
|
@ -1045,7 +1045,7 @@ static void free_task_timer_thread(void *ptr) {
|
|||
download_task_t *dt = (download_task_t *)ptr;
|
||||
set_task_inprogress(dt->taskid, 0);
|
||||
free_download_task(dt);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
pdownload_wake();
|
||||
}
|
||||
|
||||
|
|
@ -1066,13 +1066,13 @@ static void handle_async_error(download_task_t *dt, psync_async_result_t *res) {
|
|||
psync_sql_run_free(sres);
|
||||
set_task_inprogress(dt->taskid, 0);
|
||||
free_download_task(dt);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
pdownload_wake();
|
||||
} else if ((res->errorflags & PSYNC_ASYNC_ERR_FLAG_PERM) ||
|
||||
!(res->errorflags & PSYNC_ASYNC_ERR_FLAG_RETRY_AS_IS)) {
|
||||
delete_task(dt->taskid);
|
||||
free_download_task(dt);
|
||||
psync_status_recalc_to_download_async();
|
||||
pstatus_download_recalc_async();
|
||||
} else
|
||||
psync_timer_register(free_task_timer, 1, dt);
|
||||
}
|
||||
|
|
@ -1095,7 +1095,7 @@ static void finish_async_download(void *ptr, psync_async_result_t *res) {
|
|||
psync_path_status_sync_folder_task_completed(dt->dwllist.syncid,
|
||||
dt->localfolderid);
|
||||
free_download_task(dt);
|
||||
psync_status_recalc_to_download_async();
|
||||
pstatus_download_recalc_async();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1114,7 +1114,7 @@ static void finish_async_download_existing_not_mod(download_task_t *dt,
|
|||
psync_path_status_sync_folder_task_completed(dt->dwllist.syncid,
|
||||
dt->localfolderid);
|
||||
free_download_task(dt);
|
||||
psync_status_recalc_to_download_async();
|
||||
pstatus_download_recalc_async();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1139,7 +1139,7 @@ static void task_run_download_file_thread(void *ptr) {
|
|||
dt->localfolderid);
|
||||
}
|
||||
free_download_task(dt);
|
||||
psync_status_recalc_to_download_async();
|
||||
pstatus_download_recalc_async();
|
||||
}
|
||||
|
||||
static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid,
|
||||
|
|
@ -1238,7 +1238,7 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid,
|
|||
free_download_task(dt);
|
||||
return -1;
|
||||
}
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
if (hastargetchecksum &&
|
||||
psync_get_local_file_checksum(tmpname, dt->checksum, &csize) ==
|
||||
PSYNC_NET_OK &&
|
||||
|
|
@ -1473,7 +1473,7 @@ static void download_thread() {
|
|||
uint64_t taskid;
|
||||
uint32_t type;
|
||||
while (psync_do_run) {
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
|
||||
row = psync_sql_row(
|
||||
"SELECT id, type, syncid, itemid, localitemid, newitemid, name, "
|
||||
|
|
@ -1490,7 +1490,7 @@ static void download_thread() {
|
|||
psync_get_number_or_null(row[7]))) {
|
||||
delete_task(taskid);
|
||||
if (type == PSYNC_DOWNLOAD_FILE) {
|
||||
psync_status_recalc_to_download_async();
|
||||
pstatus_download_recalc_async();
|
||||
psync_path_status_sync_folder_task_completed(
|
||||
psync_get_number(row[2]), psync_get_number(row[4]));
|
||||
}
|
||||
|
|
@ -1539,7 +1539,7 @@ void pdownload_tasks_delete(psync_fileid_t fileid,
|
|||
aff = psync_sql_affected_rows();
|
||||
psync_sql_free_result(res);
|
||||
if (aff)
|
||||
psync_status_recalc_to_download_async();
|
||||
pstatus_download_recalc_async();
|
||||
if (deltemp)
|
||||
deltemp = 2;
|
||||
else
|
||||
|
|
@ -1569,7 +1569,7 @@ void pdownload_stop_sync(psync_syncid_t syncid) {
|
|||
PSYNC_TASK_DWLUPL_MASK) "=" NTO_STR(PSYNC_TASK_DOWNLOAD));
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_run_free(res);
|
||||
psync_status_recalc_to_download_async();
|
||||
pstatus_download_recalc_async();
|
||||
pthread_mutex_lock(¤t_downloads_mutex);
|
||||
psync_list_for_each_element(dwl, &downloads, download_list_t,
|
||||
list) if (dwl->syncid == syncid) dwl->stop = 1;
|
||||
|
|
|
|||
|
|
@ -1,508 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2014 pCloud Ltd. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met: Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer. Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided with
|
||||
the distribution. Neither the name of pCloud Ltd nor the names of
|
||||
its contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL pCloud
|
||||
Ltd BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pfile.h"
|
||||
#include "pexternalstatus.h"
|
||||
#include "pfolder.h"
|
||||
#include "pfsfolder.h"
|
||||
#include "pfstasks.h"
|
||||
#include "plibs.h"
|
||||
#include "pstatus.h"
|
||||
#include "psynclib.h"
|
||||
|
||||
#define MAX_RECURS_DEPTH 31
|
||||
|
||||
#define SLASHCHAR '/'
|
||||
|
||||
static int sync_offline() {
|
||||
if (psync_status_is_offline() ||
|
||||
(psync_status_get(PSTATUS_TYPE_ACCFULL) == PSTATUS_ACCFULL_OVERQUOTA) ||
|
||||
(psync_status_get(PSTATUS_TYPE_DISKFULL) == PSTATUS_DISKFULL_FULL) ||
|
||||
(psync_status_get(PSTATUS_TYPE_RUN) == PSTATUS_RUN_PAUSE))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int folder_in_sync_nolock(psync_fsfolderid_t folderid) {
|
||||
psync_sql_res *res = NULL;
|
||||
psync_uint_row row;
|
||||
uint64_t result;
|
||||
|
||||
if ((folderid == 0) || (folderid == PSYNC_INVALID_FSFOLDERID))
|
||||
return 0;
|
||||
|
||||
res = psync_sql_query_nolock("select id from syncfolder where folderid = ?;");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
result = row[0];
|
||||
psync_sql_free_result(res);
|
||||
return result;
|
||||
}
|
||||
|
||||
psync_sql_free_result(res);
|
||||
|
||||
res =
|
||||
psync_sql_query_nolock("select parentfolderid from folder where id = ?;");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
result = folder_in_sync_nolock(row[0]);
|
||||
psync_sql_free_result(res);
|
||||
return result;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int task_for_sync_nolock(int syncid) {
|
||||
psync_sql_res *res = NULL;
|
||||
psync_uint_row row;
|
||||
uint64_t ret;
|
||||
|
||||
res = psync_sql_query_nolock(
|
||||
"select 1 from localfile as f, task as t, localfolder as fl where "
|
||||
"t.syncid = ? and t.localitemid = f.id and f.localparentfolderid = fl.id "
|
||||
"limit 1;");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
ret = row[0];
|
||||
psync_sql_free_result(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
psync_sql_free_result(res);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fsexternal_status_folderid(psync_fsfolderid_t folder_id, int level) {
|
||||
psync_fstask_folder_t *tasksp;
|
||||
psync_sql_res *res = NULL;
|
||||
int result = 0;
|
||||
int syncid = 0;
|
||||
psync_uint_row row;
|
||||
int synctsk = 0;
|
||||
|
||||
if (level >= MAX_RECURS_DEPTH)
|
||||
return 0;
|
||||
|
||||
tasksp = psync_fstask_get_folder_tasks_rdlocked(folder_id);
|
||||
if (tasksp && (tasksp->creats || tasksp->mkdirs)) {
|
||||
if (psync_status_get(PSTATUS_TYPE_ACCFULL) == PSTATUS_ACCFULL_OVERQUOTA)
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
syncid = folder_in_sync_nolock(folder_id);
|
||||
if (syncid) {
|
||||
synctsk = task_for_sync_nolock(syncid);
|
||||
if (synctsk > 0) {
|
||||
if (level == 1) {
|
||||
if (sync_offline())
|
||||
return 1;
|
||||
else
|
||||
return 2;
|
||||
} else {
|
||||
if ((psync_sync_status_folderid(folder_id, syncid) != INSYNC)) {
|
||||
if (sync_offline())
|
||||
return 1;
|
||||
else
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
++level;
|
||||
res = psync_sql_query_nolock("SELECT id FROM folder WHERE parentfolderid=?");
|
||||
psync_sql_bind_int(res, 1, folder_id);
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
result = fsexternal_status_folderid(row[0], level);
|
||||
if (result)
|
||||
break;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
external_status psync_external_status_folderid(psync_fsfolderid_t folder_id) {
|
||||
int stat = 0;
|
||||
|
||||
if (folder_id == PSYNC_INVALID_FSFOLDERID) {
|
||||
return NOSYNC;
|
||||
}
|
||||
if (folder_id >= 0) {
|
||||
psync_sql_rdlock();
|
||||
stat = fsexternal_status_folderid(folder_id, 0);
|
||||
psync_sql_rdunlock();
|
||||
} else
|
||||
stat = 2;
|
||||
|
||||
switch (stat) {
|
||||
case 1:
|
||||
return NOSYNC;
|
||||
break;
|
||||
case 2:
|
||||
if (sync_offline())
|
||||
return NOSYNC;
|
||||
else
|
||||
return INPROG;
|
||||
break;
|
||||
case 0:
|
||||
return INSYNC;
|
||||
break;
|
||||
default:
|
||||
return INSYNC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static char *replace_sync_folder(const char *path, int *syncid /*OUT*/) {
|
||||
psync_sql_res *res = NULL;
|
||||
psync_variant_row row;
|
||||
size_t len;
|
||||
char *rootpath;
|
||||
char *drivepath;
|
||||
const char *rest;
|
||||
psync_fsfolderid_t folderid;
|
||||
const char *syncfolder;
|
||||
int i = 0;
|
||||
char *ret = NULL;
|
||||
int rootlen = 0, reslen = 0;
|
||||
|
||||
psync_sql_rdlock();
|
||||
res =
|
||||
psync_sql_query_nolock("select localpath, id, folderid from syncfolder;");
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
syncfolder = psync_get_lstring(row[0], &len);
|
||||
i = strncmp(syncfolder, path, len);
|
||||
if (i == 0 && ((path[len] == '\0') || (path[len] == SLASHCHAR))) {
|
||||
(*syncid) = psync_get_snumber(row[1]);
|
||||
folderid = psync_get_snumber(row[2]);
|
||||
rootpath = psync_get_path_by_folderid(folderid, 0);
|
||||
if ((path[len] == '\0') ||
|
||||
((path[len] == SLASHCHAR) && (path[len + 1] == '\0'))) {
|
||||
ret = rootpath;
|
||||
break;
|
||||
}
|
||||
rest = path + len + 1;
|
||||
reslen = strlen(rest);
|
||||
if (rootpath) {
|
||||
rootlen = strlen(rootpath);
|
||||
drivepath = (char *)psync_malloc(rootlen + reslen +
|
||||
2); // Slash and null terminator
|
||||
memcpy(drivepath, rootpath, rootlen);
|
||||
memset(drivepath + rootlen, SLASHCHAR, 1);
|
||||
memcpy(drivepath + rootlen + 1, rest,
|
||||
reslen + 1); // Copy also the null terminator
|
||||
// debug(D_NOTICE,"Sync folder replace result: %s", drivepath);
|
||||
|
||||
psync_free(rootpath);
|
||||
ret = drivepath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
external_status psync_sync_status_folderid(psync_fsfolderid_t folderid,
|
||||
int syncid) {
|
||||
|
||||
psync_sql_res *res = NULL;
|
||||
psync_uint_row row;
|
||||
uint32_t offline;
|
||||
external_status result = INSYNC;
|
||||
// debug(D_NOTICE, "Psync folderid %" PRIu64 " syncid %d", folderid, syncid);
|
||||
offline = psync_status_is_offline();
|
||||
// upload
|
||||
res = psync_sql_query_nolock(
|
||||
"select 1 from localfile as f, task as t, localfolder as fl where "
|
||||
"t.syncid = ? and fl.folderid = ? and t.localitemid = f.id and "
|
||||
"f.localparentfolderid = fl.id limit 1;");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
if (row[0] > 0) {
|
||||
if (offline ||
|
||||
(psync_status_get(PSTATUS_TYPE_ACCFULL) == PSTATUS_ACCFULL_OVERQUOTA))
|
||||
result = NOSYNC;
|
||||
else
|
||||
result = INPROG;
|
||||
psync_sql_free_result(res);
|
||||
return result;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
// download
|
||||
res = psync_sql_query_nolock(
|
||||
"select 1 from task as t, localfolder as lf where t.localitemid = lf.id "
|
||||
"and t.syncid = ? and lf.folderid = ? and t.type = 2 limit 1;");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
if (row[0] > 0) {
|
||||
if (offline ||
|
||||
(psync_status_get(PSTATUS_TYPE_DISKFULL) == PSTATUS_DISKFULL_FULL))
|
||||
result = NOSYNC;
|
||||
else
|
||||
result = INPROG;
|
||||
break;
|
||||
}
|
||||
|
||||
psync_sql_free_result(res);
|
||||
return result;
|
||||
}
|
||||
|
||||
external_status psync_sync_status_folder(const char *path, int syncid) {
|
||||
psync_fsfolderid_t folderid;
|
||||
external_status result = INSYNC;
|
||||
|
||||
folderid = psync_fsfolderid_by_path(path, 0);
|
||||
if (folderid != PSYNC_INVALID_FSFOLDERID) {
|
||||
psync_sql_rdlock();
|
||||
result = psync_sync_status_folderid(folderid, syncid);
|
||||
psync_sql_rdunlock();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
external_status psync_sync_status_file(const char *name,
|
||||
psync_fsfolderid_t folderid,
|
||||
int syncid) {
|
||||
|
||||
psync_sql_res *res = NULL;
|
||||
psync_uint_row row;
|
||||
uint32_t offline;
|
||||
external_status result = INSYNC;
|
||||
|
||||
psync_sql_rdlock();
|
||||
offline = psync_status_is_offline();
|
||||
// upload
|
||||
res = psync_sql_query_nolock(
|
||||
"select 1 from localfile as f, task as t, localfolder as fl where "
|
||||
"t.syncid = ? and fl.folderid = ? and t.localitemid = f.id and "
|
||||
"f.localparentfolderid = fl.id and t.name = ?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
psync_sql_bind_string(res, 3, name);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
if (row[0] == 1) {
|
||||
if (offline ||
|
||||
(psync_status_get(PSTATUS_TYPE_ACCFULL) == PSTATUS_ACCFULL_OVERQUOTA))
|
||||
result = NOSYNC;
|
||||
else
|
||||
result = INPROG;
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
return result;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
// download
|
||||
res = psync_sql_query_nolock(
|
||||
"select 1 from task as t, localfolder as lf where t.localitemid = lf.id "
|
||||
"and t.syncid = ? and lf.folderid = ? and t.type = 2 and t.name = ?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
psync_sql_bind_string(res, 3, name);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
if (row[0] == 1) {
|
||||
if (offline ||
|
||||
(psync_status_get(PSTATUS_TYPE_DISKFULL) == PSTATUS_DISKFULL_FULL))
|
||||
result = NOSYNC;
|
||||
else
|
||||
result = INPROG;
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
psync_sql_free_result(res);
|
||||
// sync
|
||||
res = psync_sql_query_nolock(
|
||||
"select 1 from file as f where f.parentfolderid = ? and f.name = ? ");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_string(res, 2, name);
|
||||
if ((!psync_sql_fetch_rowint(res))) {
|
||||
if (sync_offline())
|
||||
result = NOSYNC;
|
||||
else
|
||||
result = INPROG;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
external_status do_psync_external_status_file(const char *path) {
|
||||
psync_fstask_folder_t *taskp;
|
||||
psync_fspath_t *filep;
|
||||
external_status result = INVSYNC;
|
||||
int syncid;
|
||||
|
||||
if (!path)
|
||||
return INVSYNC;
|
||||
psync_sql_rdlock();
|
||||
filep = psync_fsfolder_resolve_path(path);
|
||||
if (filep) {
|
||||
if ((syncid = folder_in_sync_nolock(filep->folderid))) {
|
||||
result = psync_sync_status_file(filep->name, filep->folderid, syncid);
|
||||
} else {
|
||||
taskp = psync_fstask_get_folder_tasks_rdlocked(filep->folderid);
|
||||
if (taskp) {
|
||||
if (psync_fstask_find_creat(taskp, filep->name, 0)) {
|
||||
if (sync_offline())
|
||||
result = NOSYNC;
|
||||
else
|
||||
result = INPROG;
|
||||
} else
|
||||
result = INSYNC;
|
||||
} else
|
||||
result = INSYNC;
|
||||
}
|
||||
}
|
||||
psync_sql_rdunlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
external_status do_psync_external_status_folder(const char *path) {
|
||||
psync_fsfolderid_t folderid;
|
||||
external_status result = INVSYNC;
|
||||
|
||||
if (!path)
|
||||
return INVSYNC;
|
||||
folderid = psync_fsfolderid_by_path(path, 0);
|
||||
if (folderid != PSYNC_INVALID_FSFOLDERID) {
|
||||
result = psync_external_status_folderid(folderid);
|
||||
} else
|
||||
debug(D_WARNING,
|
||||
"Sync folder folderid not found! Called on no actual path ?");
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
static void do_normalize_path(char * path) {
|
||||
int i = 0;
|
||||
int to_move = 0;
|
||||
int new_ind = 0;
|
||||
int path_size = strlen(path);
|
||||
for (; i < (path_size - to_move); ++i) {
|
||||
if ((path[i] == '\\') && (path[i + 1] == '\\')) {
|
||||
path[i] = '/';
|
||||
++to_move;
|
||||
i += 2;
|
||||
if (i >= path_size)
|
||||
break;
|
||||
}
|
||||
if (to_move) {
|
||||
new_ind = i - to_move;
|
||||
if (new_ind > 0)
|
||||
path[new_ind] = path[i];
|
||||
}
|
||||
}
|
||||
path[path_size - to_move] = '\0';
|
||||
}
|
||||
*/
|
||||
static void do_normalize_path(char *path) {
|
||||
int i = 0;
|
||||
int path_size = strlen(path);
|
||||
for (; i < path_size; ++i)
|
||||
if (path[i] == '\\')
|
||||
path[i] = '/';
|
||||
}
|
||||
|
||||
external_status do_psync_external_status(char *path) {
|
||||
char *fsroot = NULL;
|
||||
char *folder = NULL;
|
||||
int syncid = 0, rootlen = 0;
|
||||
struct stat st;
|
||||
external_status result = INVSYNC;
|
||||
char *pcpath = NULL;
|
||||
|
||||
fsroot = psync_fs_getmountpoint();
|
||||
if (fsroot) {
|
||||
rootlen = strlen(fsroot);
|
||||
} else
|
||||
debug(D_WARNING, "Not mounted!!!");
|
||||
if (fsroot && rootlen && !strncmp(fsroot, path, rootlen)) {
|
||||
pcpath = path + rootlen;
|
||||
// debug(D_NOTICE, "Drive root replace result: %s", pcpath);
|
||||
} else {
|
||||
folder = replace_sync_folder(path, &syncid);
|
||||
if (folder)
|
||||
pcpath = folder;
|
||||
else {
|
||||
// debug(D_NOTICE, "No sync nor drive folder! Called on no pCloud item?");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
do_normalize_path(pcpath);
|
||||
if (!stat(path, &st)) {
|
||||
if (!pfile_stat_isfolder(&st)) {
|
||||
result = do_psync_external_status_file(pcpath);
|
||||
if (syncid && (result == INVSYNC))
|
||||
result = NOSYNC;
|
||||
} else {
|
||||
result = do_psync_external_status_folder(pcpath);
|
||||
if (syncid && (result == INVSYNC))
|
||||
result = NOSYNC;
|
||||
}
|
||||
}
|
||||
|
||||
if (folder)
|
||||
free(folder);
|
||||
if (fsroot)
|
||||
free(fsroot);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
string_list_t *sync_get_sync_folders() {
|
||||
psync_sql_res *res = NULL;
|
||||
psync_str_row srow;
|
||||
string_list_t *result;
|
||||
|
||||
result = (string_list_t *)psync_malloc(sizeof(string_list_t));
|
||||
psync_list_init(&result->list);
|
||||
psync_sql_rdlock();
|
||||
res = psync_sql_query_rdlock("select localpath from syncfolder;");
|
||||
while ((srow = psync_sql_fetch_rowstr(res))) {
|
||||
string_list_t *name;
|
||||
name = psync_new(string_list_t);
|
||||
name->str = psync_strdup(srow[0]);
|
||||
psync_list_add_tail(&result->list, &name->list);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2013 pCloud Ltd. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met: Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer. Redistributions in binary form must reproduce the
|
||||
above copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution. Neither the name of pCloud Ltd nor the
|
||||
names of its contributors may be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL pCloud
|
||||
Ltd BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _PSYNC_EXTERNAL_STATUS_H
|
||||
#define _PSYNC_EXTERNAL_STATUS_H
|
||||
|
||||
#include "pfsfolder.h"
|
||||
#include "plist.h"
|
||||
#include "psynclib.h"
|
||||
|
||||
typedef struct {
|
||||
psync_list list;
|
||||
char *str;
|
||||
} string_list_t;
|
||||
|
||||
static inline const char *print_external_status(external_status stat) {
|
||||
switch (stat) {
|
||||
case INSYNC:
|
||||
return "INSYNC";
|
||||
case INPROG:
|
||||
return "INPROG";
|
||||
case NOSYNC:
|
||||
return "NOSYNC";
|
||||
default:
|
||||
return "NOSYNC";
|
||||
}
|
||||
}
|
||||
|
||||
external_status do_psync_external_status(char *path);
|
||||
external_status do_psync_external_status_file(const char *path);
|
||||
external_status do_psync_external_status_folder(const char *path);
|
||||
|
||||
external_status psync_sync_status_folder(const char *path, int syncid);
|
||||
string_list_t *sync_get_sync_folders();
|
||||
|
||||
external_status psync_external_status_folderid(psync_fsfolderid_t folder_id);
|
||||
external_status psync_sync_status_file(const char *name,
|
||||
psync_fsfolderid_t folderid, int syncid);
|
||||
external_status psync_sync_status_folderid(psync_fsfolderid_t folderid,
|
||||
int syncid);
|
||||
|
||||
#endif //_PSYNC_EXTERNAL_STATUS_H
|
||||
|
|
@ -1822,7 +1822,7 @@ static void psync_fs_upload_release_timer(void *ptr) {
|
|||
}
|
||||
psync_fs_dec_of_refcnt(ofw->of);
|
||||
psync_free(ofw);
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
}
|
||||
|
||||
static void psync_fs_write_timer(psync_timer_t timer, void *ptr) {
|
||||
|
|
@ -1912,7 +1912,7 @@ static int psync_fs_flush(const char *path, struct fuse_file_info *fi) {
|
|||
psync_sql_bind_uint(res, 3, writeid);
|
||||
psync_sql_run_free(res);
|
||||
}
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
return 0;
|
||||
}
|
||||
pthread_mutex_unlock(&of->mutex);
|
||||
|
|
@ -3708,7 +3708,7 @@ err00:
|
|||
|
||||
static void psync_fs_wait_start() {
|
||||
debug(D_NOTICE, "waiting for online status");
|
||||
psync_wait_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
pstatus_wait(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
if (psync_do_run) {
|
||||
debug(D_NOTICE, "starting fs");
|
||||
psync_fs_do_start();
|
||||
|
|
@ -3717,7 +3717,7 @@ static void psync_fs_wait_start() {
|
|||
|
||||
static void psync_fs_wait_login() {
|
||||
debug(D_NOTICE, "waiting for online status");
|
||||
psync_wait_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
pstatus_wait(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_ONLINE);
|
||||
debug(D_NOTICE, "waited for online status");
|
||||
psync_sql_lock();
|
||||
waitingforlogin = 0;
|
||||
|
|
@ -3747,7 +3747,7 @@ int psync_fs_start() {
|
|||
pthread_mutex_unlock(&start_mutex);
|
||||
if (ret)
|
||||
return ret;
|
||||
status = psync_status_get(PSTATUS_TYPE_AUTH);
|
||||
status = pstatus_get(PSTATUS_TYPE_AUTH);
|
||||
debug(D_NOTICE, "auth status=%u", status);
|
||||
if (status == PSTATUS_AUTH_PROVIDED)
|
||||
return psync_fs_do_start();
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ static int save_meta(const binresult *meta, psync_folderid_t folderid,
|
|||
(unsigned long)folderid, name,
|
||||
(unsigned long)papi_find_result2(meta, "modified", PARAM_NUM)->num,
|
||||
(unsigned long)papi_find_result2(meta, "size", PARAM_NUM)->num);
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -604,7 +604,7 @@ static void perm_fail_upload_task(uint64_t taskid) {
|
|||
psync_sql_run_free(sql);
|
||||
psync_fs_task_deleted(taskid);
|
||||
psync_sql_commit_transaction();
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
}
|
||||
|
||||
static int copy_file(psock_t *api, const struct stat *st,
|
||||
|
|
@ -805,7 +805,7 @@ static int large_upload_creat(uint64_t taskid, psync_folderid_t folderid,
|
|||
debug(D_NOTICE, "got stop for file %s", name);
|
||||
goto err2;
|
||||
}
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
if (fsize - usize > PSYNC_COPY_BUFFER_SIZE)
|
||||
rd = PSYNC_COPY_BUFFER_SIZE;
|
||||
else
|
||||
|
|
@ -929,7 +929,7 @@ static int upload_modify_send_local(psock_t *api,
|
|||
debug(D_NOTICE, "got stop");
|
||||
goto err0;
|
||||
}
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
if (length - bw > PSYNC_COPY_BUFFER_SIZE)
|
||||
rd = PSYNC_COPY_BUFFER_SIZE;
|
||||
else
|
||||
|
|
@ -1149,7 +1149,7 @@ static void large_upload() {
|
|||
char fileidhex[sizeof(psync_fsfileid_t) * 2 + 2];
|
||||
debug(D_NOTICE, "started");
|
||||
while (1) {
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
res = psync_sql_query("SELECT id, type, folderid, text1, text2, int1, "
|
||||
"fileid, int2 FROM fstask WHERE status=2 AND "
|
||||
"type IN (" NTO_STR(PSYNC_FS_TASK_CREAT) ", " NTO_STR(
|
||||
|
|
@ -1211,7 +1211,7 @@ static void large_upload() {
|
|||
res = psync_sql_prep_statement("DELETE FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
}
|
||||
psync_upload_dec_uploads();
|
||||
if (ret) {
|
||||
|
|
@ -1934,9 +1934,9 @@ static void psync_fsupload_process_tasks(psync_list *tasks) {
|
|||
|
||||
if (creats) {
|
||||
psync_upload_dec_uploads_cnt(creats);
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
} else if (cancels || dels)
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
|
||||
if (dels)
|
||||
pdiff_wake();
|
||||
|
|
@ -2063,7 +2063,7 @@ static void psync_fsupload_check_tasks() {
|
|||
uint32_t cnt;
|
||||
psync_list_init(&tasks);
|
||||
cnt = 0;
|
||||
if (psync_status_get(PSTATUS_TYPE_ACCFULL) == PSTATUS_ACCFULL_QUOTAOK)
|
||||
if (pstatus_get(PSTATUS_TYPE_ACCFULL) == PSTATUS_ACCFULL_QUOTAOK)
|
||||
res = psync_sql_query_rdlock(
|
||||
"SELECT f.id, f.type, f.folderid, f.fileid, f.text1, f.text2, f.int1, "
|
||||
"f.int2, f.sfolderid, f.status FROM fstask f"
|
||||
|
|
@ -2129,7 +2129,7 @@ static void psync_fsupload_thread() {
|
|||
clean_stuck_tasks();
|
||||
waited = 0;
|
||||
while (psync_do_run) {
|
||||
psync_wait_statuses_array(requiredstatusesnooverquota,
|
||||
pstatus_wait_statuses_arr(requiredstatusesnooverquota,
|
||||
ARRAY_SIZE(requiredstatusesnooverquota));
|
||||
// it is better to sleep a bit to give a chance for events to accumulate
|
||||
if (waited)
|
||||
|
|
|
|||
|
|
@ -992,7 +992,7 @@ restart:
|
|||
pthread_cond_wait(&scan_cond, &scan_mutex);
|
||||
restart_scan = 0;
|
||||
pthread_mutex_unlock(&scan_mutex);
|
||||
if (!psync_statuses_ok_array(requiredstatuses, ARRAY_SIZE(requiredstatuses)))
|
||||
if (!pstatus_ok_status_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses)))
|
||||
return;
|
||||
reload_ignored_folders();
|
||||
for (i = 0; i < SCAN_LIST_CNT; i++)
|
||||
|
|
@ -1169,7 +1169,7 @@ restart:
|
|||
|
||||
if (w) {
|
||||
psync_wake_upload();
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
}
|
||||
for (i = 0; i < SCAN_LIST_CNT; i++)
|
||||
psync_list_for_each_element_call(&scan_lists[i], sync_folderlist, list,
|
||||
|
|
@ -1203,15 +1203,15 @@ static void scanner_thread() {
|
|||
time_t lastscan;
|
||||
int w;
|
||||
psys_sleep_milliseconds(1500);
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
psync_wait_status(PSTATUS_TYPE_RUN, PSTATUS_RUN_RUN | PSTATUS_RUN_PAUSE);
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait(PSTATUS_TYPE_RUN, PSTATUS_RUN_RUN | PSTATUS_RUN_PAUSE);
|
||||
scanner_scan(1);
|
||||
psync_set_status(PSTATUS_TYPE_LOCALSCAN, PSTATUS_LOCALSCAN_READY);
|
||||
pstatus_set(PSTATUS_TYPE_LOCALSCAN, PSTATUS_LOCALSCAN_READY);
|
||||
scanner_wait();
|
||||
w = 0;
|
||||
lastscan = 0;
|
||||
while (psync_do_run) {
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
if (lastscan + 5 >= psync_current_time) {
|
||||
psys_sleep_milliseconds(2000);
|
||||
pthread_mutex_lock(&scan_mutex);
|
||||
|
|
|
|||
|
|
@ -393,15 +393,15 @@ void psync_set_local_full(int over) {
|
|||
if (over != isover) {
|
||||
isover = over;
|
||||
if (isover) {
|
||||
psync_set_status(PSTATUS_TYPE_DISKFULL, PSTATUS_DISKFULL_FULL);
|
||||
pstatus_set(PSTATUS_TYPE_DISKFULL, PSTATUS_DISKFULL_FULL);
|
||||
} else
|
||||
psync_set_status(PSTATUS_TYPE_DISKFULL, PSTATUS_DISKFULL_OK);
|
||||
pstatus_set(PSTATUS_TYPE_DISKFULL, PSTATUS_DISKFULL_OK);
|
||||
}
|
||||
}
|
||||
|
||||
int psync_handle_api_result(uint64_t result) {
|
||||
if (result == 2000) {
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADLOGIN);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_BADLOGIN);
|
||||
psync_timer_notify_exception();
|
||||
return PSYNC_NET_TEMPFAIL;
|
||||
} else if (result == 2003 || result == 2009 || result == 2005 ||
|
||||
|
|
@ -734,7 +734,7 @@ void psync_account_downloaded_bytes(int unsigned bytes) {
|
|||
psync_current_time - PSYNC_SPEED_CALC_AVERAGE_SEC)
|
||||
sum += download_bytes_sec[i].bytes;
|
||||
download_speed = sum / PSYNC_SPEED_CALC_AVERAGE_SEC;
|
||||
psync_status_set_download_speed(download_speed);
|
||||
pstatus_download_set_speed(download_speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -829,7 +829,7 @@ static void account_uploaded_bytes(int unsigned bytes) {
|
|||
psync_current_time - PSYNC_SPEED_CALC_AVERAGE_SEC)
|
||||
sum += upload_bytes_sec[i].bytes;
|
||||
upload_speed = sum / PSYNC_SPEED_CALC_AVERAGE_SEC;
|
||||
psync_status_set_upload_speed(upload_speed);
|
||||
pstatus_upload_set_speed(upload_speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ static void psync_p2p_thread() {
|
|||
int tcpsock, socks[2], *inconn;
|
||||
socklen_t sl;
|
||||
int sret;
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
tcpsock = INVALID_SOCKET;
|
||||
/* udpsock=psock_create(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (unlikely_log(udpsock==INVALID_SOCKET)){*/
|
||||
|
|
@ -499,7 +499,7 @@ static void psync_p2p_thread() {
|
|||
}
|
||||
pthread_mutex_unlock(&p2pmutex);
|
||||
}
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
sret = psock_select_in(socks, 2, -1);
|
||||
if (unlikely_log(sret == -1)) {
|
||||
psys_sleep_milliseconds(1);
|
||||
|
|
|
|||
|
|
@ -2083,7 +2083,7 @@ static void psync_pagecache_read_unmodified_thread(void *ptr) {
|
|||
pcrypto_sector_encdec_t enc;
|
||||
int err, tries;
|
||||
request = (psync_request_t *)ptr;
|
||||
if (psync_status_get(PSTATUS_TYPE_ONLINE) == PSTATUS_ONLINE_OFFLINE) {
|
||||
if (pstatus_get(PSTATUS_TYPE_ONLINE) == PSTATUS_ONLINE_OFFLINE) {
|
||||
psync_pagecache_send_error(request, -ENOTCONN);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -824,7 +824,7 @@ static psync_path_status_t rdunlock_return_in_prog() {
|
|||
PSTATUS_COMBINE(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_QUOTAOK),
|
||||
PSTATUS_COMBINE(PSTATUS_TYPE_DISKFULL, PSTATUS_DISKFULL_OK)};
|
||||
psync_sql_rdunlock();
|
||||
if (psync_statuses_ok_array(requiredstatuses, ARRAY_SIZE(requiredstatuses)))
|
||||
if (pstatus_ok_status_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses)))
|
||||
return PSYNC_PATH_STATUS_IN_PROG;
|
||||
else
|
||||
return PSYNC_PATH_STATUS_PAUSED; // TODO: fix to return proper status
|
||||
|
|
|
|||
|
|
@ -316,20 +316,20 @@ static void proc_send_event(void *ptr) {
|
|||
}
|
||||
}
|
||||
|
||||
void psync_callbacks_get_status(pstatus_t *status) {
|
||||
void pstatus_get_cb(pstatus_t *status) {
|
||||
static char downloadstr[MAX_STATUS_STR_LEN], uploadstr[MAX_STATUS_STR_LEN];
|
||||
memcpy(status, &psync_status, sizeof(pstatus_t));
|
||||
status_fill_formatted_str(status, downloadstr, uploadstr);
|
||||
}
|
||||
|
||||
void psync_set_status_callback(pstatus_change_callback_t callback) {
|
||||
void pstatus_set_cb(pstatus_change_callback_t callback) {
|
||||
pthread_mutex_lock(&statusmutex);
|
||||
statusthreadrunning = 1;
|
||||
pthread_mutex_unlock(&statusmutex);
|
||||
prun_thread1("status change", status_change_thread, callback);
|
||||
}
|
||||
|
||||
void psync_send_status_update() {
|
||||
void pstatus_send_status_update() {
|
||||
if (statusthreadrunning) {
|
||||
pthread_mutex_lock(&statusmutex);
|
||||
if (++statuschanges == 0) {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ static pthread_mutex_t status_internal_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|||
static pthread_cond_t statuscond = PTHREAD_COND_INITIALIZER;
|
||||
static unsigned long status_waiters = 0;
|
||||
|
||||
static uint32_t psync_calc_status() {
|
||||
static uint32_t calc_status() {
|
||||
if (statuses[PSTATUS_TYPE_AUTH] != PSTATUS_AUTH_PROVIDED &&
|
||||
statuses[PSTATUS_TYPE_AUTH] != PSTATUS_INVALID) {
|
||||
if (statuses[PSTATUS_TYPE_AUTH] == PSTATUS_AUTH_REQUIRED)
|
||||
|
|
@ -139,7 +139,17 @@ static uint32_t psync_calc_status() {
|
|||
return PSTATUS_READY;
|
||||
}
|
||||
|
||||
void psync_status_init() {
|
||||
static void proc_recalc_download() {
|
||||
pstatus_download_recalc();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
||||
static void proc_recalc_upload() {
|
||||
pstatus_upload_recalc();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
||||
void pstatus_init() {
|
||||
memset(&psync_status, 0, sizeof(psync_status));
|
||||
statuses[PSTATUS_TYPE_RUN] =
|
||||
psync_sql_cellint("SELECT value FROM setting WHERE id='runstatus'", 0);
|
||||
|
|
@ -150,12 +160,12 @@ void psync_status_init() {
|
|||
"REPLACE INTO setting (id, value) VALUES ('runstatus', " NTO_STR(
|
||||
PSTATUS_RUN_RUN) ")");
|
||||
}
|
||||
psync_status_recalc_to_download();
|
||||
psync_status_recalc_to_upload();
|
||||
psync_status.status = psync_calc_status();
|
||||
pstatus_download_recalc();
|
||||
pstatus_upload_recalc();
|
||||
psync_status.status = calc_status();
|
||||
}
|
||||
|
||||
void psync_status_recalc_to_download() {
|
||||
void pstatus_download_recalc() {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query_rdlock("SELECT COUNT(*), SUM(f.size) FROM task t, file "
|
||||
|
|
@ -172,10 +182,10 @@ void psync_status_recalc_to_download() {
|
|||
if (!psync_status.filestodownload) {
|
||||
psync_status.downloadspeed = 0;
|
||||
}
|
||||
psync_status.status = psync_calc_status();
|
||||
psync_status.status = calc_status();
|
||||
}
|
||||
|
||||
void psync_status_recalc_to_upload() {
|
||||
void pstatus_upload_recalc() {
|
||||
char fileidhex[sizeof(psync_fsfileid_t) * 2 + 2];
|
||||
char *filename;
|
||||
const char *fscpath;
|
||||
|
|
@ -218,39 +228,25 @@ void psync_status_recalc_to_upload() {
|
|||
psync_status.bytestoupload = bytestou;
|
||||
if (!filestou)
|
||||
psync_status.uploadspeed = 0;
|
||||
psync_status.status = psync_calc_status();
|
||||
psync_status.status = calc_status();
|
||||
}
|
||||
|
||||
static void psync_status_recalc_to_download_async_thread() {
|
||||
psync_status_recalc_to_download();
|
||||
psync_send_status_update();
|
||||
void pstatus_download_recalc_async() {
|
||||
psync_run_ratelimited("recalc download", proc_recalc_download, PSYNC_MIN_INTERVAL_RECALC_DOWNLOAD, 1);
|
||||
}
|
||||
|
||||
void psync_status_recalc_to_download_async() {
|
||||
psync_run_ratelimited("recalc download",
|
||||
psync_status_recalc_to_download_async_thread,
|
||||
PSYNC_MIN_INTERVAL_RECALC_DOWNLOAD, 1);
|
||||
void pstatus_upload_recalc_async() {
|
||||
psync_run_ratelimited("recalc upload", proc_recalc_upload, PSYNC_MIN_INTERVAL_RECALC_UPLOAD, 1);
|
||||
}
|
||||
|
||||
static void psync_status_recalc_to_upload_async_thread() {
|
||||
psync_status_recalc_to_upload();
|
||||
psync_send_status_update();
|
||||
}
|
||||
|
||||
void psync_status_recalc_to_upload_async() {
|
||||
psync_run_ratelimited("recalc upload",
|
||||
psync_status_recalc_to_upload_async_thread,
|
||||
PSYNC_MIN_INTERVAL_RECALC_UPLOAD, 1);
|
||||
}
|
||||
|
||||
uint32_t psync_status_get(uint32_t statusid) {
|
||||
uint32_t pstatus_get(uint32_t statusid) {
|
||||
pthread_mutex_lock(&status_internal_mutex);
|
||||
statusid = statuses[statusid];
|
||||
pthread_mutex_unlock(&status_internal_mutex);
|
||||
return statusid;
|
||||
}
|
||||
|
||||
void psync_set_status(uint32_t statusid, uint32_t status) {
|
||||
void pstatus_set(uint32_t statusid, uint32_t status) {
|
||||
pthread_mutex_lock(&status_internal_mutex);
|
||||
statuses[statusid] = status;
|
||||
if (status_waiters)
|
||||
|
|
@ -260,14 +256,14 @@ void psync_set_status(uint32_t statusid, uint32_t status) {
|
|||
psync_status.localisfull =
|
||||
(statuses[PSTATUS_TYPE_DISKFULL] == PSTATUS_DISKFULL_FULL);
|
||||
pthread_mutex_unlock(&status_internal_mutex);
|
||||
status = psync_calc_status();
|
||||
status = calc_status();
|
||||
if (psync_status.status != status) {
|
||||
psync_status.status = status;
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
}
|
||||
|
||||
void psync_wait_status(uint32_t statusid, uint32_t status) {
|
||||
void pstatus_wait(uint32_t statusid, uint32_t status) {
|
||||
pthread_mutex_lock(&status_internal_mutex);
|
||||
while ((statuses[statusid] & status) == 0 && psync_do_run) {
|
||||
status_waiters++;
|
||||
|
|
@ -281,14 +277,14 @@ void psync_wait_status(uint32_t statusid, uint32_t status) {
|
|||
}
|
||||
}
|
||||
|
||||
void psync_terminate_status_waiters() {
|
||||
void pstatus_wait_term() {
|
||||
pthread_mutex_lock(&status_internal_mutex);
|
||||
if (status_waiters)
|
||||
pthread_cond_broadcast(&statuscond);
|
||||
pthread_mutex_unlock(&status_internal_mutex);
|
||||
}
|
||||
|
||||
void psync_wait_statuses_array(const uint32_t *combinedstatuses, uint32_t cnt) {
|
||||
void pstatus_wait_statuses_arr(const uint32_t *combinedstatuses, uint32_t cnt) {
|
||||
uint32_t waited, i, statusid, status;
|
||||
pthread_mutex_lock(&status_internal_mutex);
|
||||
do {
|
||||
|
|
@ -307,7 +303,7 @@ void psync_wait_statuses_array(const uint32_t *combinedstatuses, uint32_t cnt) {
|
|||
pthread_mutex_unlock(&status_internal_mutex);
|
||||
}
|
||||
|
||||
void psync_wait_statuses(uint32_t first, ...) {
|
||||
void pstatus_wait_status(uint32_t first, ...) {
|
||||
uint32_t arr[PSTATUS_NUM_STATUSES];
|
||||
uint32_t cnt;
|
||||
va_list ap;
|
||||
|
|
@ -317,10 +313,10 @@ void psync_wait_statuses(uint32_t first, ...) {
|
|||
arr[cnt++] = first;
|
||||
} while ((first = va_arg(ap, uint32_t)));
|
||||
va_end(ap);
|
||||
psync_wait_statuses_array(arr, cnt);
|
||||
pstatus_wait_statuses_arr(arr, cnt);
|
||||
}
|
||||
|
||||
int psync_statuses_ok_array(const uint32_t *combinedstatuses, uint32_t cnt) {
|
||||
int pstatus_ok_status_arr(const uint32_t *combinedstatuses, uint32_t cnt) {
|
||||
uint32_t i, statusid, status;
|
||||
pthread_mutex_lock(&status_internal_mutex);
|
||||
for (i = 0; i < cnt; i++) {
|
||||
|
|
@ -335,27 +331,27 @@ int psync_statuses_ok_array(const uint32_t *combinedstatuses, uint32_t cnt) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
void psync_status_set_download_speed(uint32_t speed) {
|
||||
void pstatus_download_set_speed(uint32_t speed) {
|
||||
if (psync_status.downloadspeed != speed) {
|
||||
if (psync_status.filesdownloading)
|
||||
psync_status.downloadspeed = speed;
|
||||
else
|
||||
psync_status.downloadspeed = 0;
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
}
|
||||
|
||||
void psync_status_set_upload_speed(uint32_t speed) {
|
||||
void pstatus_upload_set_speed(uint32_t speed) {
|
||||
if (psync_status.uploadspeed != speed) {
|
||||
if (psync_status.filesuploading)
|
||||
psync_status.uploadspeed = speed;
|
||||
else
|
||||
psync_status.uploadspeed = 0;
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
}
|
||||
|
||||
void psync_status_send_update() {
|
||||
psync_status.status = psync_calc_status();
|
||||
psync_send_status_update();
|
||||
void pstatus_send_update() {
|
||||
psync_status.status = calc_status();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,34 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ptevent.h"
|
||||
#include "psynclib.h"
|
||||
#include "plist.h"
|
||||
|
||||
#define PSTATUS_NUM_STATUSES 6
|
||||
|
||||
#define PSTATUS_READY 0
|
||||
#define PSTATUS_DOWNLOADING 1
|
||||
#define PSTATUS_UPLOADING 2
|
||||
#define PSTATUS_DOWNLOADINGANDUPLOADING 3
|
||||
#define PSTATUS_LOGIN_REQUIRED 4
|
||||
#define PSTATUS_BAD_LOGIN_DATA 5
|
||||
#define PSTATUS_BAD_LOGIN_TOKEN 6
|
||||
#define PSTATUS_ACCOUNT_FULL 7
|
||||
#define PSTATUS_DISK_FULL 8
|
||||
#define PSTATUS_PAUSED 9
|
||||
#define PSTATUS_STOPPED 10
|
||||
#define PSTATUS_OFFLINE 11
|
||||
#define PSTATUS_CONNECTING 12
|
||||
#define PSTATUS_SCANNING 13
|
||||
#define PSTATUS_USER_MISMATCH 14
|
||||
#define PSTATUS_ACCOUNT_EXPIRED 15
|
||||
#define PSTATUS_TFA_REQUIRED 16
|
||||
#define PSTATUS_BAD_TFA_CODE 17
|
||||
#define PSTATUS_VERIFY_REQUIRED 18
|
||||
#define PSTATUS_RELOCATION 19
|
||||
#define PSTATUS_RELOCATED 20
|
||||
#define PSTATUS_ACCOUT_TFAERR PSTATUS_TFA_REQUIRED
|
||||
#define PSTATUS_ACCOUT_EXPIRED PSTATUS_ACCOUNT_EXPIRED
|
||||
|
||||
#define PSTATUS_TYPE_RUN 0
|
||||
#define PSTATUS_TYPE_ONLINE 1
|
||||
#define PSTATUS_TYPE_AUTH 2
|
||||
|
|
@ -77,35 +100,59 @@
|
|||
#define PSTATUS_LOCALSCAN_SCANNING 1
|
||||
#define PSTATUS_LOCALSCAN_READY 2
|
||||
|
||||
typedef struct {
|
||||
psync_list list;
|
||||
char *str;
|
||||
} string_list_t;
|
||||
|
||||
typedef enum Status { INSYNC, INPROG, NOSYNC, INVSYNC } external_status_t;
|
||||
|
||||
#define PSTATUS_COMBINE(type, statuses) (((type) << 24) + (statuses))
|
||||
|
||||
typedef struct pstatus_struct_ {
|
||||
const char *downloadstr; // formatted string with the status of uploads
|
||||
const char *uploadstr; // formatted string with the status of downloads
|
||||
uint64_t bytestoupload; // sum of the sizes of files that need to be uploaded to sync state
|
||||
uint64_t bytestouploadcurrent; // sum of the sizes of files in filesuploading
|
||||
uint64_t bytesuploaded; // bytes uploaded in files accounted in filesuploading
|
||||
uint64_t bytestodownload; // sum of the sizes of files that need to be downloaded to sync state
|
||||
uint64_t bytestodownloadcurrent; // sum of the sizes of files in filesdownloading
|
||||
uint64_t bytesdownloaded; // bytes downloaded in files accounted in filesdownloading
|
||||
uint32_t status; // current status, one of PSTATUS_ constants
|
||||
uint32_t filestoupload; // number of files to upload in order to sync state, including filesuploading
|
||||
uint32_t filesuploading; // number of files currently uploading
|
||||
uint32_t uploadspeed; // in bytes/sec
|
||||
uint32_t filestodownload; // number of files to download in order to sync state, including filesdownloading
|
||||
uint32_t filesdownloading; // number of files currently downloading
|
||||
uint32_t downloadspeed; // in bytes/sec
|
||||
uint8_t remoteisfull; // account is full and no files will be synced upwards
|
||||
uint8_t localisfull; // (some) local hard drive is full and no files will be synced from the cloud
|
||||
} pstatus_t;
|
||||
|
||||
void psync_status_init();
|
||||
void psync_status_recalc_to_download();
|
||||
void psync_status_recalc_to_download_async();
|
||||
void psync_status_recalc_to_upload();
|
||||
void psync_status_recalc_to_upload_async();
|
||||
uint32_t psync_status_get(uint32_t statusid);
|
||||
void psync_set_status(uint32_t statusid, uint32_t status);
|
||||
void psync_wait_status(uint32_t statusid, uint32_t status);
|
||||
void psync_terminate_status_waiters();
|
||||
void psync_wait_statuses_array(const uint32_t *combinedstatuses, uint32_t cnt);
|
||||
void psync_wait_statuses(uint32_t first, ...);
|
||||
int psync_statuses_ok_array(const uint32_t *combinedstatuses, uint32_t cnt);
|
||||
/* Status change callback is called every time value is changed. It may be
|
||||
* called quite often when there are active uploads/downloads. Callbacks are
|
||||
* issued from a special callback thread (e.g. the same thread all the time) and
|
||||
* are guaranteed not to overlap.
|
||||
*/
|
||||
typedef void (*pstatus_change_callback_t)(pstatus_t *status);
|
||||
|
||||
void psync_status_set_download_speed(uint32_t speed);
|
||||
void psync_status_set_upload_speed(uint32_t speed);
|
||||
;
|
||||
void pstatus_init();
|
||||
void pstatus_download_recalc();
|
||||
void pstatus_download_recalc_async();
|
||||
void pstatus_upload_recalc();
|
||||
void pstatus_upload_recalc_async();
|
||||
uint32_t pstatus_get(uint32_t statusid);
|
||||
void pstatus_set(uint32_t statusid, uint32_t status);
|
||||
void pstatus_wait(uint32_t statusid, uint32_t status);
|
||||
void pstatus_wait_term();
|
||||
void pstatus_wait_statuses_arr(const uint32_t *combinedstatuses, uint32_t cnt);
|
||||
void pstatus_wait_status(uint32_t first, ...);
|
||||
int pstatus_ok_status_arr(const uint32_t *combinedstatuses, uint32_t cnt);
|
||||
void pstatus_download_set_speed(uint32_t speed);
|
||||
void pstatus_upload_set_speed(uint32_t speed);
|
||||
void pstatus_send_update();
|
||||
void pstatus_get_cb(pstatus_t *status);
|
||||
void pstatus_set_cb(pstatus_change_callback_t callback);
|
||||
void pstatus_send_status_update();
|
||||
|
||||
void psync_status_send_update();
|
||||
|
||||
void psync_callbacks_get_status(pstatus_t *status);
|
||||
void psync_set_status_callback(pstatus_change_callback_t callback);
|
||||
void psync_send_status_update();
|
||||
void ptevent_process(event_data_struct *data);
|
||||
|
||||
|
||||
static inline int psync_status_is_offline() {
|
||||
return psync_status_get(PSTATUS_TYPE_ONLINE) == PSTATUS_ONLINE_OFFLINE;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -333,8 +333,8 @@ static void psync_sync_newsyncedfolder(psync_syncid_t syncid) {
|
|||
if (synctype & PSYNC_UPLOAD_ONLY)
|
||||
psync_wake_localscan();
|
||||
if (synctype & PSYNC_DOWNLOAD_ONLY) {
|
||||
psync_status_recalc_to_download();
|
||||
psync_send_status_update();
|
||||
pstatus_download_recalc();
|
||||
pstatus_send_status_update();
|
||||
pdownload_wake();
|
||||
}
|
||||
psync_localnotify_add_sync(syncid);
|
||||
|
|
|
|||
|
|
@ -112,6 +112,10 @@ static time_t links_last_refresh_time;
|
|||
extern int unlinked;
|
||||
extern int tfa;
|
||||
|
||||
static inline int psync_status_is_offline() {
|
||||
return pstatus_get(PSTATUS_TYPE_ONLINE) == PSTATUS_ONLINE_OFFLINE;
|
||||
}
|
||||
|
||||
#define return_error(err) \
|
||||
do { \
|
||||
psync_error = err; \
|
||||
|
|
@ -287,7 +291,7 @@ int psync_init() {
|
|||
|
||||
psync_libs_init();
|
||||
psync_settings_init();
|
||||
psync_status_init();
|
||||
pstatus_init();
|
||||
psync_timer_sleep_handler(psync_stop_crypto_on_sleep);
|
||||
psync_path_status_init();
|
||||
if (IS_DEBUG) {
|
||||
|
|
@ -322,7 +326,7 @@ void psync_start_sync(pstatus_change_callback_t status_callback,
|
|||
}
|
||||
psync_apiserver_init();
|
||||
if (status_callback)
|
||||
psync_set_status_callback(status_callback);
|
||||
pstatus_set_cb(status_callback);
|
||||
if (event_callback)
|
||||
pqevent_process(event_callback);
|
||||
psync_syncer_init();
|
||||
|
|
@ -354,8 +358,8 @@ void psync_destroy() {
|
|||
debug(D_ERROR, "failed to cleanup shm");
|
||||
}
|
||||
psync_fs_stop();
|
||||
psync_terminate_status_waiters();
|
||||
psync_send_status_update();
|
||||
pstatus_wait_term();
|
||||
pstatus_send_status_update();
|
||||
ptask_stop_async();
|
||||
psync_timer_wake();
|
||||
psync_timer_notify_exception();
|
||||
|
|
@ -366,7 +370,7 @@ void psync_destroy() {
|
|||
psync_sql_close();
|
||||
}
|
||||
|
||||
void psync_get_status(pstatus_t *status) { psync_callbacks_get_status(status); }
|
||||
void psync_get_status(pstatus_t *status) { pstatus_get_cb(status); }
|
||||
|
||||
char *psync_get_username() {
|
||||
return psync_sql_cellstr("SELECT value FROM setting WHERE id='username'");
|
||||
|
|
@ -392,7 +396,7 @@ void psync_set_user_pass(const char *username, const char *password, int save) {
|
|||
psync_my_pass = psync_strdup(password);
|
||||
pthread_mutex_unlock(&psync_my_auth_mutex);
|
||||
}
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
psync_recache_contacts = 1;
|
||||
}
|
||||
|
||||
|
|
@ -406,7 +410,7 @@ void psync_set_pass(const char *password, int save) {
|
|||
psync_my_pass = psync_strdup(password);
|
||||
pthread_mutex_unlock(&psync_my_auth_mutex);
|
||||
}
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
}
|
||||
|
||||
void psync_set_auth(const char *auth, int save) {
|
||||
|
|
@ -415,7 +419,7 @@ void psync_set_auth(const char *auth, int save) {
|
|||
psync_set_string_value("auth", auth);
|
||||
else
|
||||
psync_strlcpy(psync_my_auth, auth, sizeof(psync_my_auth));
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
}
|
||||
|
||||
int psync_mark_notificaitons_read(uint32_t notificationid) {
|
||||
|
|
@ -442,8 +446,8 @@ void psync_logout2(uint32_t auth_status, int doinvauth) {
|
|||
psync_free(psync_my_pass);
|
||||
psync_my_pass = NULL;
|
||||
pthread_mutex_unlock(&psync_my_auth_mutex);
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, auth_status);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, auth_status);
|
||||
psync_fs_pause_until_login();
|
||||
pdownload_stop_all();
|
||||
psync_stop_all_upload();
|
||||
|
|
@ -549,17 +553,17 @@ void psync_unlink() {
|
|||
// the deviceid from local DB.
|
||||
psync_stop_device(0, &errMsg);
|
||||
|
||||
psync_status_recalc_to_download();
|
||||
psync_status_recalc_to_upload();
|
||||
pstatus_download_recalc();
|
||||
pstatus_upload_recalc();
|
||||
psync_invalidate_auth(psync_my_auth);
|
||||
pcryptofolder_lock();
|
||||
psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT);
|
||||
psys_sleep_milliseconds(20);
|
||||
psync_stop_localscan();
|
||||
psync_sql_checkpoint_lock();
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_REQUIRED);
|
||||
psync_set_status(PSTATUS_TYPE_RUN, PSTATUS_RUN_STOP);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_REQUIRED);
|
||||
pstatus_set(PSTATUS_TYPE_RUN, PSTATUS_RUN_STOP);
|
||||
psync_timer_notify_exception();
|
||||
psync_sql_lock();
|
||||
debug(D_NOTICE, "clearing database, locked");
|
||||
|
|
@ -598,10 +602,10 @@ void psync_unlink() {
|
|||
psync_notifications_clean();
|
||||
psync_pagecache_reopen_read_cache();
|
||||
pdiff_unlock();
|
||||
psync_set_status(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
psync_set_status(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_QUOTAOK);
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_REQUIRED);
|
||||
psync_set_status(PSTATUS_TYPE_RUN, PSTATUS_RUN_RUN);
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
pstatus_set(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_QUOTAOK);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_REQUIRED);
|
||||
pstatus_set(PSTATUS_TYPE_RUN, PSTATUS_RUN_RUN);
|
||||
psync_resume_localscan();
|
||||
if (psync_fs_need_per_folder_refresh())
|
||||
psync_fs_refresh_folder(0);
|
||||
|
|
@ -613,10 +617,10 @@ int psync_tfa_type() { return psync_my_2fa_type; }
|
|||
|
||||
static void check_tfa_result(uint64_t result) {
|
||||
if (result == 2064) {
|
||||
if (psync_status_get(PSTATUS_TYPE_AUTH) == PSTATUS_AUTH_TFAREQ) {
|
||||
if (pstatus_get(PSTATUS_TYPE_AUTH) == PSTATUS_AUTH_TFAREQ) {
|
||||
psync_free(psync_my_2fa_token);
|
||||
psync_my_2fa_token = NULL;
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -729,7 +733,7 @@ void psync_tfa_set_code(const char *code, int trusted, int is_recovery) {
|
|||
psync_my_2fa_code[sizeof(psync_my_2fa_code) - 1] = 0;
|
||||
psync_my_2fa_trust = trusted;
|
||||
psync_my_2fa_code_type = is_recovery ? 2 : 1;
|
||||
psync_set_status(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_PROVIDED);
|
||||
}
|
||||
|
||||
psync_syncid_t psync_add_sync_by_path(const char *localpath,
|
||||
|
|
@ -859,7 +863,7 @@ int psync_add_sync_by_path_delayed(const char *localpath,
|
|||
psync_sql_bind_uint(res, 3, synctype);
|
||||
psync_sql_run_free(res);
|
||||
psync_sql_sync();
|
||||
if (psync_status_get(PSTATUS_TYPE_ONLINE) == PSTATUS_ONLINE_ONLINE)
|
||||
if (pstatus_get(PSTATUS_TYPE_ONLINE) == PSTATUS_ONLINE_ONLINE)
|
||||
prun_thread("check delayed syncs", psync_syncer_check_delayed_syncs);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1108,7 +1112,7 @@ int psync_is_name_to_ignore(const char *name) {
|
|||
}
|
||||
|
||||
static void psync_set_run_status(uint32_t status) {
|
||||
psync_set_status(PSTATUS_TYPE_RUN, status);
|
||||
pstatus_set(PSTATUS_TYPE_RUN, status);
|
||||
psync_set_uint_value("runstatus", status);
|
||||
}
|
||||
|
||||
|
|
@ -2412,7 +2416,7 @@ int psync_crypto_crypto_send_change_user_private() {
|
|||
return PRINT_RETURN_CONST(PSYNC_CRYPTO_SETUP_UNKNOWN_ERROR);
|
||||
}
|
||||
|
||||
external_status psync_filesystem_status(const char *path) {
|
||||
external_status_t psync_filesystem_status(const char *path) {
|
||||
switch (psync_path_status_get_status(psync_path_status_get(path))) {
|
||||
case PSYNC_PATH_STATUS_IN_SYNC:
|
||||
return INSYNC;
|
||||
|
|
@ -2427,11 +2431,11 @@ external_status psync_filesystem_status(const char *path) {
|
|||
}
|
||||
}
|
||||
|
||||
external_status psync_status_file(const char *path) {
|
||||
external_status_t psync_status_file(const char *path) {
|
||||
return psync_filesystem_status(path);
|
||||
}
|
||||
|
||||
external_status psync_status_folder(const char *path) {
|
||||
external_status_t psync_status_folder(const char *path) {
|
||||
return psync_filesystem_status(path);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
|
||||
#include "paccountevents.h"
|
||||
#include "ptools.h"
|
||||
#include "pstatus.h"
|
||||
|
||||
typedef uint64_t psync_folderid_t;
|
||||
typedef uint64_t psync_fileid_t;
|
||||
|
|
@ -135,60 +136,6 @@ typedef struct {
|
|||
#define BEAPI_ERR_MV_TOO_MANY_IN_SHA \
|
||||
2352 // Too many objects moved at once in shared folder
|
||||
|
||||
#define PSTATUS_READY 0
|
||||
#define PSTATUS_DOWNLOADING 1
|
||||
#define PSTATUS_UPLOADING 2
|
||||
#define PSTATUS_DOWNLOADINGANDUPLOADING 3
|
||||
#define PSTATUS_LOGIN_REQUIRED 4
|
||||
#define PSTATUS_BAD_LOGIN_DATA 5
|
||||
#define PSTATUS_BAD_LOGIN_TOKEN 6
|
||||
#define PSTATUS_ACCOUNT_FULL 7
|
||||
#define PSTATUS_DISK_FULL 8
|
||||
#define PSTATUS_PAUSED 9
|
||||
#define PSTATUS_STOPPED 10
|
||||
#define PSTATUS_OFFLINE 11
|
||||
#define PSTATUS_CONNECTING 12
|
||||
#define PSTATUS_SCANNING 13
|
||||
#define PSTATUS_USER_MISMATCH 14
|
||||
#define PSTATUS_ACCOUNT_EXPIRED 15
|
||||
#define PSTATUS_TFA_REQUIRED 16
|
||||
#define PSTATUS_BAD_TFA_CODE 17
|
||||
#define PSTATUS_VERIFY_REQUIRED 18
|
||||
#define PSTATUS_RELOCATION 19
|
||||
#define PSTATUS_RELOCATED 20
|
||||
|
||||
#define PSTATUS_ACCOUT_TFAERR PSTATUS_TFA_REQUIRED
|
||||
#define PSTATUS_ACCOUT_EXPIRED PSTATUS_ACCOUNT_EXPIRED
|
||||
|
||||
typedef struct pstatus_struct_ {
|
||||
const char *downloadstr; /* formatted string with the status of uploads */
|
||||
const char *uploadstr; /* formatted string with the status of downloads */
|
||||
uint64_t bytestoupload; /* sum of the sizes of files that need to be uploaded
|
||||
to sync state */
|
||||
uint64_t
|
||||
bytestouploadcurrent; /* sum of the sizes of files in filesuploading */
|
||||
uint64_t
|
||||
bytesuploaded; /* bytes uploaded in files accounted in filesuploading */
|
||||
uint64_t bytestodownload; /* sum of the sizes of files that need to be
|
||||
downloaded to sync state */
|
||||
uint64_t bytestodownloadcurrent; /* sum of the sizes of files in
|
||||
filesdownloading */
|
||||
uint64_t bytesdownloaded; /* bytes downloaded in files accounted in
|
||||
filesdownloading */
|
||||
uint32_t status; /* current status, one of PSTATUS_ constants */
|
||||
uint32_t filestoupload; /* number of files to upload in order to sync state,
|
||||
including filesuploading*/
|
||||
uint32_t filesuploading; /* number of files currently uploading */
|
||||
uint32_t uploadspeed; /* in bytes/sec */
|
||||
uint32_t filestodownload; /* number of files to download in order to sync
|
||||
state, including filesdownloading*/
|
||||
uint32_t filesdownloading; /* number of files currently downloading */
|
||||
uint32_t downloadspeed; /* in bytes/sec */
|
||||
uint8_t remoteisfull; /* account is full and no files will be synced upwards*/
|
||||
uint8_t localisfull; /* (some) local hard drive is full and no files will be
|
||||
synced from the cloud */
|
||||
} pstatus_t;
|
||||
|
||||
/* PEVENT_LOCAL_FOLDER_CREATED means that a folder was created in remotely and
|
||||
* this action was replicated locally, not the other way around. Accordingly
|
||||
* PEVENT_REMOTE_FOLDER_CREATED is fired when locally created folder is
|
||||
|
|
@ -536,8 +483,6 @@ typedef struct {
|
|||
psync_notification_t notifications[];
|
||||
} psync_notification_list_t;
|
||||
|
||||
typedef enum Status { INSYNC, INPROG, NOSYNC, INVSYNC } external_status;
|
||||
|
||||
typedef struct {
|
||||
uint64_t linkid;
|
||||
const char *name;
|
||||
|
|
@ -699,14 +644,6 @@ void *psync_malloc(size_t size);
|
|||
void *psync_realloc(void *ptr, size_t size);
|
||||
void psync_free(void *ptr);
|
||||
|
||||
/* Status change callback is called every time value is changed. It may be
|
||||
* called quite often when there are active uploads/downloads. Callbacks are
|
||||
* issued from a special callback thread (e.g. the same thread all the time) and
|
||||
* are guaranteed not to overlap.
|
||||
*/
|
||||
|
||||
typedef void (*pstatus_change_callback_t)(pstatus_t *status);
|
||||
|
||||
/* Event callback is called every time a download/upload is started/finished,
|
||||
* quota is changed, folder is shared or similar. Look at the PEVENT_ constants
|
||||
* for a list of possible events.
|
||||
|
|
@ -1551,9 +1488,9 @@ uint64_t psync_crypto_priv_key_flags();
|
|||
* files and folders not in drive or sync folder INSYNC is returned.
|
||||
*/
|
||||
|
||||
external_status psync_filesystem_status(const char *path);
|
||||
external_status psync_status_file(const char *path);
|
||||
external_status psync_status_folder(const char *path);
|
||||
external_status_t psync_filesystem_status(const char *path);
|
||||
external_status_t psync_status_file(const char *path);
|
||||
external_status_t psync_status_folder(const char *path);
|
||||
|
||||
/*
|
||||
* Publik links API functions.
|
||||
|
|
|
|||
|
|
@ -891,8 +891,8 @@ void ptask_download_q(psync_syncid_t syncid, psync_fileid_t fileid, psync_folder
|
|||
void ptask_download(psync_syncid_t syncid, psync_fileid_t fileid, psync_folderid_t localfolderid, const char *name) {
|
||||
ptask_download_q(syncid, fileid, localfolderid, name);
|
||||
pdownload_wake();
|
||||
psync_status_recalc_to_download();
|
||||
psync_send_status_update();
|
||||
pstatus_download_recalc();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
||||
void ptask_lfile_rename(psync_syncid_t oldsyncid, psync_syncid_t newsyncid, psync_fileid_t fileid, psync_folderid_t oldlocalfolderid, psync_folderid_t newlocalfolderid, const char *newname) {
|
||||
|
|
@ -966,7 +966,7 @@ void ptask_upload(psync_syncid_t syncid, psync_fileid_t localfileid, const char
|
|||
psync_sql_bind_string(res, 5, name);
|
||||
psync_sql_run_free(res);
|
||||
psync_wake_upload();
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
}
|
||||
|
||||
void ptask_rfile_rename(psync_syncid_t oldsyncid, psync_syncid_t newsyncid, psync_fileid_t localfileid, psync_folderid_t newlocalparentfolderid, const char *newname) {
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ void psync_upload_inc_uploads() {
|
|||
pthread_mutex_lock(&upload_mutex);
|
||||
psync_status.filesuploading++;
|
||||
pthread_mutex_unlock(&upload_mutex);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
||||
void psync_upload_dec_uploads() {
|
||||
|
|
@ -112,7 +112,7 @@ void psync_upload_dec_uploads() {
|
|||
if (psync_status.filesuploading == 0 && current_uploads_waiters)
|
||||
pthread_cond_broadcast(¤t_uploads_cond);
|
||||
pthread_mutex_unlock(&upload_mutex);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
void psync_upload_dec_uploads_cnt(uint32_t cnt) {
|
||||
pthread_mutex_lock(&upload_mutex);
|
||||
|
|
@ -120,21 +120,21 @@ void psync_upload_dec_uploads_cnt(uint32_t cnt) {
|
|||
if (psync_status.filesuploading == 0 && current_uploads_waiters)
|
||||
pthread_cond_broadcast(¤t_uploads_cond);
|
||||
pthread_mutex_unlock(&upload_mutex);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
||||
void psync_upload_add_bytes_uploaded(uint64_t bytes) {
|
||||
pthread_mutex_lock(&upload_mutex);
|
||||
psync_status.bytesuploaded += bytes;
|
||||
pthread_mutex_unlock(&upload_mutex);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
||||
void psync_upload_sub_bytes_uploaded(uint64_t bytes) {
|
||||
pthread_mutex_lock(&upload_mutex);
|
||||
psync_status.bytesuploaded -= bytes;
|
||||
pthread_mutex_unlock(&upload_mutex);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
||||
static int task_wait_no_uploads(uint64_t taskid) {
|
||||
|
|
@ -650,7 +650,7 @@ static void add_bytes_uploaded(uint64_t bytes) {
|
|||
psync_status.bytesuploaded += bytes;
|
||||
wake_upload_when_ready();
|
||||
pthread_mutex_unlock(¤t_uploads_mutex);
|
||||
psync_send_status_update();
|
||||
pstatus_send_status_update();
|
||||
}
|
||||
|
||||
static int upload_file(const char *localpath, const unsigned char *hashhex,
|
||||
|
|
@ -701,7 +701,7 @@ static int upload_file(const char *localpath, const unsigned char *hashhex,
|
|||
debug(D_NOTICE, "upload of %s stopped", localpath);
|
||||
goto err2;
|
||||
}
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
if (fsize - bw > PSYNC_COPY_BUFFER_SIZE)
|
||||
rd = PSYNC_COPY_BUFFER_SIZE;
|
||||
else
|
||||
|
|
@ -815,7 +815,7 @@ static int upload_range(psock_t *api, psync_upload_range_list_t *r,
|
|||
debug(D_NOTICE, "upload stopped");
|
||||
goto err0;
|
||||
}
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
if (r->len - bw > PSYNC_COPY_BUFFER_SIZE)
|
||||
rd = PSYNC_COPY_BUFFER_SIZE;
|
||||
else
|
||||
|
|
@ -1338,7 +1338,7 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
|
|||
uhashhex[PSYNC_HASH_DIGEST_HEXLEN], phashhex[PSYNC_HASH_DIGEST_HEXLEN];
|
||||
binparam pr;
|
||||
int ret;
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
if (upload->stop)
|
||||
return -1;
|
||||
localpath = psync_local_path_for_local_file(localfileid, NULL);
|
||||
|
|
@ -1577,7 +1577,7 @@ static void task_run_upload_file_thread(void *ptr) {
|
|||
psync_list_del(&ut->upllist.list);
|
||||
wake_upload_when_ready();
|
||||
pthread_mutex_unlock(¤t_uploads_mutex);
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
psync_free(ut);
|
||||
}
|
||||
|
||||
|
|
@ -1641,7 +1641,7 @@ static int task_run_uploadfile(uint64_t taskid, psync_syncid_t syncid,
|
|||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
} else {
|
||||
psync_status_send_update();
|
||||
pstatus_send_update();
|
||||
prun_thread1("upload file", task_run_upload_file_thread, ut);
|
||||
}
|
||||
return -1;
|
||||
|
|
@ -1716,7 +1716,7 @@ static void upload_thread() {
|
|||
uint64_t taskid;
|
||||
uint32_t type;
|
||||
while (psync_do_run) {
|
||||
psync_wait_statuses_array(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
|
||||
row = psync_sql_row("SELECT id, type, syncid, itemid, localitemid, "
|
||||
"newitemid, name, newsyncid FROM task WHERE "
|
||||
|
|
@ -1733,7 +1733,7 @@ static void upload_thread() {
|
|||
psync_get_number_or_null(row[7]))) {
|
||||
if (type == PSYNC_UPLOAD_FILE) {
|
||||
delete_upload_task(taskid, psync_get_number(row[3]));
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
} else {
|
||||
res = psync_sql_prep_statement("DELETE FROM task WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
|
|
@ -1774,7 +1774,7 @@ void psync_delete_upload_tasks_for_file(psync_fileid_t localfileid) {
|
|||
psync_sql_bind_uint(res, 2, localfileid);
|
||||
psync_sql_run(res);
|
||||
if (psync_sql_affected_rows())
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
psync_sql_free_result(res);
|
||||
pthread_mutex_lock(¤t_uploads_mutex);
|
||||
psync_list_for_each_element(upl, &uploads, upload_list_t,
|
||||
|
|
@ -1799,7 +1799,7 @@ void psync_stop_sync_upload(psync_syncid_t syncid) {
|
|||
|
||||
pthread_mutex_unlock(¤t_uploads_mutex);
|
||||
|
||||
psync_status_recalc_to_upload_async();
|
||||
pstatus_upload_recalc_async();
|
||||
}
|
||||
|
||||
void psync_stop_all_upload() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue