psql namespace
This commit is contained in:
parent
0b128ba9db
commit
6df75c5a97
|
|
@ -327,16 +327,16 @@ void get_ba_member_email(uint64_t userid, char **email /*OUT*/,
|
|||
psync_variant_row row;
|
||||
const char *cstr;
|
||||
*length = 0;
|
||||
res = psync_sql_query("SELECT mail FROM baccountemail WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, userid);
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query("SELECT mail FROM baccountemail WHERE id=?");
|
||||
psql_bind_uint(res, 1, userid);
|
||||
if ((row = psql_fetch(res))) {
|
||||
cstr = psync_get_lstring(row[0], length);
|
||||
*email = (char *)malloc(*length);
|
||||
memcpy(*email, cstr, *length);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return;
|
||||
} else
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
|
||||
{
|
||||
binresult *bres;
|
||||
|
|
@ -373,13 +373,13 @@ void get_ba_member_email(uint64_t userid, char **email /*OUT*/,
|
|||
|
||||
if (*length) {
|
||||
psync_sql_res *q;
|
||||
q = psync_sql_prep_statement("REPLACE INTO baccountemail (id, mail, "
|
||||
q = psql_prepare("REPLACE INTO baccountemail (id, mail, "
|
||||
"firstname, lastname) VALUES (?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(q, 1, userid);
|
||||
psync_sql_bind_lstring(q, 2, *email, *length);
|
||||
psync_sql_bind_lstring(q, 3, fname, strlen(fname));
|
||||
psync_sql_bind_lstring(q, 4, lname, strlen(lname));
|
||||
psync_sql_run_free(q);
|
||||
psql_bind_uint(q, 1, userid);
|
||||
psql_bind_lstr(q, 2, *email, *length);
|
||||
psql_bind_lstr(q, 3, fname, strlen(fname));
|
||||
psql_bind_lstr(q, 4, lname, strlen(lname));
|
||||
psql_run_free(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -393,16 +393,16 @@ void get_ba_team_name(uint64_t teamid, char **name /*OUT*/,
|
|||
binresult *bres;
|
||||
const binresult *teams;
|
||||
|
||||
res = psync_sql_query("SELECT name FROM baccountteam WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, teamid);
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query("SELECT name FROM baccountteam WHERE id=?");
|
||||
psql_bind_uint(res, 1, teamid);
|
||||
if ((row = psql_fetch(res))) {
|
||||
cstr = psync_get_lstring(row[0], length);
|
||||
*name = (char *)malloc(*length);
|
||||
memcpy(*name, cstr, *length);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return;
|
||||
} else
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
|
||||
// pdbg_logf(D_NOTICE, "Account_teams numids %d\n", nids);
|
||||
binparam params[] = {PAPI_STR("auth", psync_my_auth),
|
||||
|
|
@ -435,11 +435,11 @@ void get_ba_team_name(uint64_t teamid, char **name /*OUT*/,
|
|||
free(bres);
|
||||
|
||||
psync_sql_res *q;
|
||||
q = psync_sql_prep_statement(
|
||||
q = psql_prepare(
|
||||
"REPLACE INTO baccountteam (id, name) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(q, 1, teamid);
|
||||
psync_sql_bind_lstring(q, 2, *name, *length);
|
||||
psync_sql_run_free(q);
|
||||
psql_bind_uint(q, 1, teamid);
|
||||
psql_bind_lstr(q, 2, *name, *length);
|
||||
psql_run_free(q);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -476,10 +476,10 @@ void cache_account_emails() {
|
|||
goto end_close;
|
||||
} else {
|
||||
psync_sql_res *q;
|
||||
psync_sql_start_transaction();
|
||||
q = psync_sql_prep_statement("DELETE FROM baccountemail");
|
||||
if (unlikely(psync_sql_run_free(q))) {
|
||||
psync_sql_rollback_transaction();
|
||||
psql_start();
|
||||
q = psql_prepare("DELETE FROM baccountemail");
|
||||
if (unlikely(psql_run_free(q))) {
|
||||
psql_rollback();
|
||||
goto end_close;
|
||||
}
|
||||
|
||||
|
|
@ -500,20 +500,20 @@ void cache_account_emails() {
|
|||
lname = papi_find_result2(user, "lastname", PARAM_STR)->str;
|
||||
|
||||
if (userid && (active || frozen)) {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO baccountemail (id, mail, firstname, lastname) VALUES "
|
||||
"(?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, userid);
|
||||
psync_sql_bind_lstring(res, 2, nameret, strlen(nameret));
|
||||
psync_sql_bind_lstring(res, 3, fname, strlen(fname));
|
||||
psync_sql_bind_lstring(res, 4, lname, strlen(lname));
|
||||
if (unlikely(psync_sql_run_free(res))) {
|
||||
psync_sql_rollback_transaction();
|
||||
psql_bind_uint(res, 1, userid);
|
||||
psql_bind_lstr(res, 2, nameret, strlen(nameret));
|
||||
psql_bind_lstr(res, 3, fname, strlen(fname));
|
||||
psql_bind_lstr(res, 4, lname, strlen(lname));
|
||||
if (unlikely(psql_run_free(res))) {
|
||||
psql_rollback();
|
||||
goto end_close;
|
||||
}
|
||||
}
|
||||
}
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
end_close:
|
||||
free(bres);
|
||||
|
|
@ -555,10 +555,10 @@ void cache_account_teams() {
|
|||
return;
|
||||
} else {
|
||||
psync_sql_res *q;
|
||||
psync_sql_start_transaction();
|
||||
q = psync_sql_prep_statement("DELETE FROM baccountteam");
|
||||
if (unlikely(psync_sql_run_free(q)))
|
||||
psync_sql_rollback_transaction();
|
||||
psql_start();
|
||||
q = psql_prepare("DELETE FROM baccountteam");
|
||||
if (unlikely(psql_run_free(q)))
|
||||
psql_rollback();
|
||||
|
||||
for (i = 0; i < users->length; ++i) {
|
||||
const char *nameret = 0;
|
||||
|
|
@ -569,14 +569,14 @@ void cache_account_teams() {
|
|||
teamid = papi_find_result2(users->array[i], "id", PARAM_NUM)->num;
|
||||
// pdbg_logf(D_NOTICE, "Team name %s team id %lld\n", nameret,(long
|
||||
// long)teamid);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO baccountteam (id, name) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(res, 1, teamid);
|
||||
psync_sql_bind_lstring(res, 2, nameret, strlen(nameret));
|
||||
if (unlikely(psync_sql_run_free(res)))
|
||||
psync_sql_rollback_transaction();
|
||||
psql_bind_uint(res, 1, teamid);
|
||||
psql_bind_lstr(res, 2, nameret, strlen(nameret));
|
||||
if (unlikely(psql_run_free(res)))
|
||||
psql_rollback();
|
||||
}
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
free(bres);
|
||||
return;
|
||||
|
|
@ -594,10 +594,10 @@ static void cache_my_team(const binresult *team1) {
|
|||
teamid = papi_find_result2(team, "id", PARAM_NUM)->num;
|
||||
// pdbg_logf(D_NOTICE, "My Team name %s team id %lld\n", nameret,(long
|
||||
// long)teamid);
|
||||
q = psync_sql_prep_statement("INSERT INTO myteams (id, name) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(q, 1, teamid);
|
||||
psync_sql_bind_lstring(q, 2, nameret, strlen(nameret));
|
||||
psync_sql_run_free(q);
|
||||
q = psql_prepare("INSERT INTO myteams (id, name) VALUES (?, ?)");
|
||||
psql_bind_uint(q, 1, teamid);
|
||||
psql_bind_lstr(q, 2, nameret, strlen(nameret));
|
||||
psql_run_free(q);
|
||||
}
|
||||
|
||||
void cache_ba_my_teams() {
|
||||
|
|
@ -628,15 +628,15 @@ void cache_ba_my_teams() {
|
|||
return;
|
||||
}
|
||||
|
||||
psync_sql_lock();
|
||||
q = psync_sql_prep_statement("DELETE FROM myteams");
|
||||
psync_sql_run_free(q);
|
||||
psql_lock();
|
||||
q = psql_prepare("DELETE FROM myteams");
|
||||
psql_run_free(q);
|
||||
user = users->array[0];
|
||||
teams = papi_find_result2(user, "teams", PARAM_ARRAY);
|
||||
for (i = 0; i < teams->length; i++)
|
||||
cache_my_team(teams->array[i]);
|
||||
free(bres);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
int api_error_result(binresult *res) {
|
||||
|
|
@ -669,27 +669,27 @@ void psync_update_cryptostatus() {
|
|||
if (api_error_result(res))
|
||||
return;
|
||||
|
||||
q = psync_sql_prep_statement(
|
||||
q = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
|
||||
is_business = papi_find_result2(res, "business", PARAM_BOOL)->num;
|
||||
|
||||
u = papi_find_result2(res, "cryptosetup", PARAM_BOOL)->num;
|
||||
psync_sql_bind_string(q, 1, "cryptosetup");
|
||||
psync_sql_bind_uint(q, 2, u);
|
||||
psync_sql_run(q);
|
||||
psql_bind_str(q, 1, "cryptosetup");
|
||||
psql_bind_uint(q, 2, u);
|
||||
psql_run(q);
|
||||
if (u)
|
||||
crst = 1;
|
||||
psync_sql_bind_string(q, 1, "cryptosubscription");
|
||||
psql_bind_str(q, 1, "cryptosubscription");
|
||||
crsub = papi_find_result2(res, "cryptosubscription", PARAM_BOOL)->num;
|
||||
psync_sql_bind_uint(q, 2, crsub);
|
||||
psync_sql_run(q);
|
||||
psql_bind_uint(q, 2, crsub);
|
||||
psql_run(q);
|
||||
|
||||
cres = papi_check_result2(res, "cryptoexpires", PARAM_NUM);
|
||||
crexp = cres ? cres->num : 0;
|
||||
psync_sql_bind_string(q, 1, "cryptoexpires");
|
||||
psync_sql_bind_uint(q, 2, crexp);
|
||||
psync_sql_run(q);
|
||||
psql_bind_str(q, 1, "cryptoexpires");
|
||||
psql_bind_uint(q, 2, crexp);
|
||||
psql_run(q);
|
||||
|
||||
if (is_business || crsub) {
|
||||
if (crst)
|
||||
|
|
@ -706,10 +706,10 @@ void psync_update_cryptostatus() {
|
|||
crstat = 2;
|
||||
}
|
||||
}
|
||||
psync_sql_bind_string(q, 1, "cryptostatus");
|
||||
psync_sql_bind_uint(q, 2, crstat);
|
||||
psync_sql_run(q);
|
||||
psync_sql_free_result(q);
|
||||
psql_bind_str(q, 1, "cryptostatus");
|
||||
psql_bind_uint(q, 2, crstat);
|
||||
psql_run(q);
|
||||
psql_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -719,9 +719,9 @@ static int check_write_permissions(psync_folderid_t folderid) {
|
|||
int ret = 0;
|
||||
|
||||
res =
|
||||
psync_sql_query("SELECT permissions, flags, name FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_query("SELECT permissions, flags, name FROM folder WHERE id=?");
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
row = psql_fetch_int(res);
|
||||
if (unlikely(!row))
|
||||
pdbg_logf(D_ERROR, "could not find folder of folderid %lu",
|
||||
(unsigned long)folderid);
|
||||
|
|
@ -729,7 +729,7 @@ static int check_write_permissions(psync_folderid_t folderid) {
|
|||
(row[0] & PSYNC_PERM_CREATE)))
|
||||
ret = 1;
|
||||
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
static psync_folderid_t create_index_folder(const char *path) {
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@ int do_call_contactlist(result_visitor vis, void *param) {
|
|||
pdbg_logf(D_WARNING, "Account_users returned empty result!\n");
|
||||
return -2;
|
||||
} else {
|
||||
psync_sql_start_transaction();
|
||||
psync_sql_statement("DELETE FROM contacts");
|
||||
psql_start();
|
||||
psql_statement("DELETE FROM contacts");
|
||||
for (i = 0; i < contacts->length; ++i)
|
||||
vis(i, contacts->array[i], param);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
|
||||
free(bres);
|
||||
|
|
@ -94,10 +94,10 @@ static void insert_cache_contact(int i, const binresult *user, void *_this) {
|
|||
// char_field = papi_find_result2(user, "name", PARAM_STR)->str; // not
|
||||
id = papi_find_result2(user, "source", PARAM_NUM)->num;
|
||||
if ((id == 1) || (id == 3)) {
|
||||
q = psync_sql_prep_statement("REPLACE INTO contacts (mail) VALUES (?)");
|
||||
q = psql_prepare("REPLACE INTO contacts (mail) VALUES (?)");
|
||||
char_field = papi_find_result2(user, "value", PARAM_STR)->str;
|
||||
psync_sql_bind_lstring(q, 1, char_field, strlen(char_field));
|
||||
psync_sql_run_free(q);
|
||||
psql_bind_lstr(q, 1, char_field, strlen(char_field));
|
||||
psql_run_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ pcontacts_list_t *do_psync_list_contacts() {
|
|||
psync_sql_res *res;
|
||||
builder = psync_list_builder_create(sizeof(contact_info_t),
|
||||
offsetof(pcontacts_list_t, entries));
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"select mail, ifnull(name, ' ') , 0 as teamid, 1 as type from contacts "
|
||||
"union all "
|
||||
"select mail, (firstname||' '||lastname) as name, 0 as teamid , 2 as "
|
||||
|
|
@ -136,7 +136,7 @@ pcontacts_list_t *do_psync_list_contacts() {
|
|||
"union all "
|
||||
"select '' as mail, name , id as teamid, 3 as type from baccountteam "
|
||||
"ORDER BY name ");
|
||||
psync_list_bulder_add_sql(builder, res, create_contact);
|
||||
psql_list_add(builder, res, create_contact);
|
||||
|
||||
return (pcontacts_list_t *)psync_list_builder_finalize(builder);
|
||||
}
|
||||
|
|
@ -146,10 +146,10 @@ pcontacts_list_t *do_psync_list_myteams() {
|
|||
psync_sql_res *res;
|
||||
builder = psync_list_builder_create(sizeof(contact_info_t),
|
||||
offsetof(pcontacts_list_t, entries));
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT '' AS mail, name , id AS teamid, 3 AS type FROM myteams "
|
||||
"ORDER BY name ");
|
||||
psync_list_bulder_add_sql(builder, res, create_contact);
|
||||
psql_list_add(builder, res, create_contact);
|
||||
|
||||
return (pcontacts_list_t *)psync_list_builder_finalize(builder);
|
||||
}
|
||||
|
|
@ -169,28 +169,28 @@ static void process_shares_out(const binresult *shares_out, int shcnt) {
|
|||
psync_get_current_userid(&owneruserid);
|
||||
isincomming = (folderowneruserid == owneruserid) ? 0 : 1;
|
||||
|
||||
q = psync_sql_prep_statement(
|
||||
q = psql_prepare(
|
||||
"REPLACE INTO sharedfolder (id, folderid, ctime, permissions, userid, "
|
||||
"mail, name, isincoming) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
// pdbg_logf(D_NOTICE, "INSERT NORMAL SHARE OUT id: %lld", (long long)
|
||||
// papi_find_result2(share, "shareid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 1,
|
||||
psql_bind_uint(q, 1,
|
||||
papi_find_result2(share, "shareid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 2,
|
||||
psql_bind_uint(q, 2,
|
||||
papi_find_result2(share, "folderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 3,
|
||||
psql_bind_uint(q, 3,
|
||||
papi_find_result2(share, "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 4, pfileops_get_perms(share));
|
||||
psync_sql_bind_uint(q, 5,
|
||||
psql_bind_uint(q, 4, pfileops_get_perms(share));
|
||||
psql_bind_uint(q, 5,
|
||||
papi_find_result2(share, "touserid", PARAM_NUM)->num);
|
||||
br = papi_find_result2(share, "tomail", PARAM_STR);
|
||||
psync_sql_bind_lstring(q, 6, br->str, br->length);
|
||||
psql_bind_lstr(q, 6, br->str, br->length);
|
||||
if (!(br = papi_check_result2(share, "foldername", PARAM_STR)))
|
||||
br = papi_check_result2(share, "sharename", PARAM_STR);
|
||||
psync_sql_bind_lstring(q, 7, br->str, br->length);
|
||||
psync_sql_bind_uint(q, 8, isincomming);
|
||||
psync_sql_run_free(q);
|
||||
psql_bind_lstr(q, 7, br->str, br->length);
|
||||
psql_bind_uint(q, 8, isincomming);
|
||||
psql_run_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,27 +203,27 @@ static void process_shares_in(const binresult *shares_in, int shcnt) {
|
|||
for (i = 0; i < shcnt; ++i) {
|
||||
share = shares_in->array[i];
|
||||
|
||||
q = psync_sql_prep_statement(
|
||||
q = psql_prepare(
|
||||
"REPLACE INTO sharedfolder (id, isincoming, folderid, ctime, "
|
||||
"permissions, userid, mail, name) "
|
||||
"VALUES (?, 1, ?, ?, ?, ?, ?, ?)");
|
||||
// pdbg_logf(D_WARNING, "INSERT NORMAL SHARE IN id: %lld", (long long)
|
||||
// papi_find_result2(share, "shareid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 1,
|
||||
psql_bind_uint(q, 1,
|
||||
papi_find_result2(share, "shareid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 2,
|
||||
psql_bind_uint(q, 2,
|
||||
papi_find_result2(share, "folderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 3,
|
||||
psql_bind_uint(q, 3,
|
||||
papi_find_result2(share, "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 4, pfileops_get_perms(share));
|
||||
psync_sql_bind_uint(q, 5,
|
||||
psql_bind_uint(q, 4, pfileops_get_perms(share));
|
||||
psql_bind_uint(q, 5,
|
||||
papi_find_result2(share, "fromuserid", PARAM_NUM)->num);
|
||||
br = papi_find_result2(share, "frommail", PARAM_STR);
|
||||
psync_sql_bind_lstring(q, 6, br->str, br->length);
|
||||
psql_bind_lstr(q, 6, br->str, br->length);
|
||||
if (!(br = papi_check_result2(share, "foldername", PARAM_STR)))
|
||||
br = papi_check_result2(share, "sharename", PARAM_STR);
|
||||
psync_sql_bind_lstring(q, 7, br->str, br->length);
|
||||
psync_sql_run_free(q);
|
||||
psql_bind_lstr(q, 7, br->str, br->length);
|
||||
psql_run_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -242,33 +242,33 @@ static void process_shares_req_out(const binresult *shares_out, int shcnt) {
|
|||
psync_get_current_userid(&owneruserid);
|
||||
isincomming = (folderowneruserid == owneruserid) ? 0 : 1;
|
||||
|
||||
q = psync_sql_prep_statement(
|
||||
q = psql_prepare(
|
||||
"REPLACE INTO sharerequest (id, folderid, ctime, etime, permissions, "
|
||||
"userid, mail, name, message, isincoming, isba) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
q, 1, papi_find_result2(share, "sharerequestid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 2,
|
||||
psql_bind_uint(q, 2,
|
||||
papi_find_result2(share, "folderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 3,
|
||||
psql_bind_uint(q, 3,
|
||||
papi_find_result2(share, "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 4,
|
||||
psql_bind_uint(q, 4,
|
||||
papi_find_result2(share, "expires", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 5, pfileops_get_perms(share));
|
||||
psync_sql_bind_uint(q, 6, folderowneruserid);
|
||||
psql_bind_uint(q, 5, pfileops_get_perms(share));
|
||||
psql_bind_uint(q, 6, folderowneruserid);
|
||||
br = papi_find_result2(share, "tomail", PARAM_STR);
|
||||
psync_sql_bind_lstring(q, 7, br->str, br->length);
|
||||
psql_bind_lstr(q, 7, br->str, br->length);
|
||||
if (!(br = papi_check_result2(share, "foldername", PARAM_STR)))
|
||||
br = papi_check_result2(share, "sharename", PARAM_STR);
|
||||
psync_sql_bind_lstring(q, 8, br->str, br->length);
|
||||
psql_bind_lstr(q, 8, br->str, br->length);
|
||||
br = papi_check_result2(share, "message", PARAM_STR);
|
||||
if (br)
|
||||
psync_sql_bind_lstring(q, 9, br->str, br->length);
|
||||
psql_bind_lstr(q, 9, br->str, br->length);
|
||||
else
|
||||
psync_sql_bind_null(q, 9);
|
||||
psync_sql_bind_uint(q, 10, isincomming);
|
||||
psync_sql_bind_uint(q, 11, isincomming);
|
||||
psync_sql_run_free(q);
|
||||
psql_bind_null(q, 9);
|
||||
psql_bind_uint(q, 10, isincomming);
|
||||
psql_bind_uint(q, 11, isincomming);
|
||||
psql_run_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -288,34 +288,34 @@ static void process_shares_req_in(const binresult *shares_in, int shcnt) {
|
|||
isincomming = (folderowneruserid == owneruserid) ? 0 : 1;
|
||||
}
|
||||
|
||||
q = psync_sql_prep_statement(
|
||||
q = psql_prepare(
|
||||
"REPLACE INTO sharerequest (id, folderid, ctime, etime, permissions, "
|
||||
"userid, mail, name, message, isincoming, isba) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
q, 1, papi_find_result2(share, "sharerequestid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 2,
|
||||
psql_bind_uint(q, 2,
|
||||
papi_find_result2(share, "folderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 3,
|
||||
psql_bind_uint(q, 3,
|
||||
papi_find_result2(share, "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 4,
|
||||
psql_bind_uint(q, 4,
|
||||
papi_find_result2(share, "expires", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 5, pfileops_get_perms(share));
|
||||
psync_sql_bind_uint(q, 6,
|
||||
psql_bind_uint(q, 5, pfileops_get_perms(share));
|
||||
psql_bind_uint(q, 6,
|
||||
papi_find_result2(share, "fromuserid", PARAM_NUM)->num);
|
||||
br = papi_find_result2(share, "frommail", PARAM_STR);
|
||||
psync_sql_bind_lstring(q, 7, br->str, br->length);
|
||||
psql_bind_lstr(q, 7, br->str, br->length);
|
||||
if (!(br = papi_check_result2(share, "foldername", PARAM_STR)))
|
||||
br = papi_check_result2(share, "sharename", PARAM_STR);
|
||||
psync_sql_bind_lstring(q, 8, br->str, br->length);
|
||||
psql_bind_lstr(q, 8, br->str, br->length);
|
||||
br = papi_check_result2(share, "message", PARAM_STR);
|
||||
if (br)
|
||||
psync_sql_bind_lstring(q, 9, br->str, br->length);
|
||||
psql_bind_lstr(q, 9, br->str, br->length);
|
||||
else
|
||||
psync_sql_bind_null(q, 9);
|
||||
psync_sql_bind_uint(q, 10, isincomming);
|
||||
psync_sql_bind_uint(q, 11, !isincomming);
|
||||
psync_sql_run_free(q);
|
||||
psql_bind_null(q, 9);
|
||||
psql_bind_uint(q, 10, isincomming);
|
||||
psql_bind_uint(q, 11, !isincomming);
|
||||
psql_run_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -368,13 +368,13 @@ void cache_shares() {
|
|||
|
||||
shares = papi_find_result2(bres, "shares", PARAM_HASH);
|
||||
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
|
||||
q = psync_sql_prep_statement("DELETE FROM sharerequest ");
|
||||
psync_sql_run_free(q);
|
||||
q = psql_prepare("DELETE FROM sharerequest ");
|
||||
psql_run_free(q);
|
||||
|
||||
q = psync_sql_prep_statement("DELETE FROM sharedfolder ");
|
||||
psync_sql_run_free(q);
|
||||
q = psql_prepare("DELETE FROM sharedfolder ");
|
||||
psql_run_free(q);
|
||||
|
||||
array = papi_find_result2(shares, "outgoing", PARAM_ARRAY);
|
||||
|
||||
|
|
@ -405,7 +405,7 @@ void cache_shares() {
|
|||
process_shares_req_in(array, shcnt);
|
||||
}
|
||||
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
|
||||
free(bres);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,39 +117,39 @@ static void save_to_db(
|
|||
size_t saltlen, size_t iterations, time_t expires, const char *publicsha1,
|
||||
const char *privatesha1, uint32_t flags) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
psync_sql_start_transaction();
|
||||
psync_sql_bind_string(res, 1, "cryptosetup");
|
||||
psync_sql_bind_uint(res, 2, 1);
|
||||
psync_sql_run(res);
|
||||
psql_start();
|
||||
psql_bind_str(res, 1, "cryptosetup");
|
||||
psql_bind_uint(res, 2, 1);
|
||||
psql_run(res);
|
||||
if (expires) {
|
||||
psync_sql_bind_string(res, 1, "cryptoexpires");
|
||||
psync_sql_bind_uint(res, 2, expires);
|
||||
psync_sql_run(res);
|
||||
psql_bind_str(res, 1, "cryptoexpires");
|
||||
psql_bind_uint(res, 2, expires);
|
||||
psql_run(res);
|
||||
}
|
||||
psync_sql_bind_string(res, 1, "crypto_private_key");
|
||||
psync_sql_bind_blob(res, 2, (const char *)rsapriv, rsaprivlen);
|
||||
psync_sql_run(res);
|
||||
psync_sql_bind_string(res, 1, "crypto_public_key");
|
||||
psync_sql_bind_blob(res, 2, (const char *)rsapub, rsapublen);
|
||||
psync_sql_run(res);
|
||||
psync_sql_bind_string(res, 1, "crypto_private_salt");
|
||||
psync_sql_bind_blob(res, 2, (const char *)salt, saltlen);
|
||||
psync_sql_run(res);
|
||||
psync_sql_bind_string(res, 1, "crypto_private_iter");
|
||||
psync_sql_bind_uint(res, 2, iterations);
|
||||
psync_sql_run(res);
|
||||
psync_sql_bind_string(res, 1, "crypto_public_sha1");
|
||||
psync_sql_bind_string(res, 2, publicsha1);
|
||||
psync_sql_run(res);
|
||||
psync_sql_bind_string(res, 1, "crypto_private_sha1");
|
||||
psync_sql_bind_string(res, 2, privatesha1);
|
||||
psync_sql_run(res);
|
||||
psync_sql_bind_string(res, 1, "crypto_private_flags");
|
||||
psync_sql_bind_uint(res, 2, flags);
|
||||
psync_sql_run_free(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_bind_str(res, 1, "crypto_private_key");
|
||||
psql_bind_blob(res, 2, (const char *)rsapriv, rsaprivlen);
|
||||
psql_run(res);
|
||||
psql_bind_str(res, 1, "crypto_public_key");
|
||||
psql_bind_blob(res, 2, (const char *)rsapub, rsapublen);
|
||||
psql_run(res);
|
||||
psql_bind_str(res, 1, "crypto_private_salt");
|
||||
psql_bind_blob(res, 2, (const char *)salt, saltlen);
|
||||
psql_run(res);
|
||||
psql_bind_str(res, 1, "crypto_private_iter");
|
||||
psql_bind_uint(res, 2, iterations);
|
||||
psql_run(res);
|
||||
psql_bind_str(res, 1, "crypto_public_sha1");
|
||||
psql_bind_str(res, 2, publicsha1);
|
||||
psql_run(res);
|
||||
psql_bind_str(res, 1, "crypto_private_sha1");
|
||||
psql_bind_str(res, 2, privatesha1);
|
||||
psql_run(res);
|
||||
psql_bind_str(res, 1, "crypto_private_flags");
|
||||
psql_bind_uint(res, 2, flags);
|
||||
psql_run_free(res);
|
||||
psql_commit();
|
||||
}
|
||||
|
||||
static int setup_do_upload(const unsigned char *rsapriv,
|
||||
|
|
@ -361,7 +361,7 @@ setup_upload(const unsigned char *rsapriv, size_t rsaprivlen,
|
|||
}
|
||||
|
||||
int pcryptofolder_issetup() {
|
||||
return psync_sql_cellint("SELECT value FROM setting WHERE id='cryptosetup'", 0);
|
||||
return psql_cellint("SELECT value FROM setting WHERE id='cryptosetup'", 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -564,17 +564,17 @@ int pcryptofolder_unlock(const char *password) {
|
|||
rowcnt = 0;
|
||||
rsapriv = rsapub = salt = NULL;
|
||||
iterations = 0;
|
||||
if (psync_sql_trylock()) {
|
||||
if (psql_trylock()) {
|
||||
pthread_rwlock_unlock(&crypto_lock);
|
||||
psys_sleep_milliseconds(1);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT id, value FROM setting WHERE id IN ('crypto_private_key', "
|
||||
"'crypto_public_key', 'crypto_private_salt', 'crypto_private_iter')");
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
id = psync_get_string(row[0]);
|
||||
rowcnt++;
|
||||
if (!strcmp(id, "crypto_private_key"))
|
||||
|
|
@ -588,8 +588,8 @@ int pcryptofolder_unlock(const char *password) {
|
|||
iterations = atoi(psync_get_string(row[1]));
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_unlock();
|
||||
psql_free(res);
|
||||
psql_unlock();
|
||||
if (rowcnt < 4) {
|
||||
if (unlikely(rowcnt != 0)) {
|
||||
pdbg_logf(D_BUG,
|
||||
|
|
@ -925,17 +925,17 @@ static psync_encrypted_symmetric_key_t get_fldr_enckey(psync_folderid_t folderid
|
|||
psync_variant_row row;
|
||||
const char *ckey;
|
||||
size_t ckeylen;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT enckey FROM cryptofolderkey WHERE folderid=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
if ((row = psql_fetch(res))) {
|
||||
ckey = psync_get_lstring(row[0], &ckeylen);
|
||||
enckey = psymkey_alloc_encrypted(ckeylen);
|
||||
memcpy(enckey->data, ckey, ckeylen);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return enckey;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return download_fldr_enckey(folderid);
|
||||
}
|
||||
|
||||
|
|
@ -946,18 +946,18 @@ static psync_encrypted_symmetric_key_t get_file_enckey(psync_fileid_t fileid, ui
|
|||
psync_variant_row row;
|
||||
const char *ckey;
|
||||
size_t ckeylen;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT enckey FROM cryptofilekey WHERE fileid=? AND hash=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
psync_sql_bind_uint(res, 2, hash);
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
psql_bind_uint(res, 2, hash);
|
||||
if ((row = psql_fetch(res))) {
|
||||
ckey = psync_get_lstring(row[0], &ckeylen);
|
||||
enckey = psymkey_alloc_encrypted(ckeylen);
|
||||
memcpy(enckey->data, ckey, ckeylen);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return enckey;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (nonetwork) {
|
||||
pdbg_logf(D_NOTICE, "delaying key download for file %lu",
|
||||
(unsigned long)fileid);
|
||||
|
|
@ -1131,28 +1131,28 @@ static pcrypto_textenc_t get_tmp_fldrencoder_safe(psync_fsfolderid_t folderid) {
|
|||
sym_key_ver1 *skv1;
|
||||
psync_sql_res *res;
|
||||
psync_variant_row row;
|
||||
res = psync_sql_query_rdlock("SELECT text2 FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, -folderid);
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query_rdlock("SELECT text2 FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, -folderid);
|
||||
if ((row = psql_fetch(res))) {
|
||||
const unsigned char *b64enckey;
|
||||
unsigned char *enckey;
|
||||
size_t b64enckeylen, enckeylen;
|
||||
;
|
||||
if (psync_is_null(row[0])) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return (pcrypto_textenc_t)errptr(
|
||||
pdbg_return_const(PSYNC_CRYPTO_FOLDER_NOT_ENCRYPTED));
|
||||
}
|
||||
b64enckey = (const unsigned char *)psync_get_lstring(row[0], &b64enckeylen);
|
||||
enckey = psync_base64_decode(b64enckey, b64enckeylen, &enckeylen);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (enckey) {
|
||||
symkey = prsa_decrypt_data(crypto_privkey, enckey, enckeylen);
|
||||
free(enckey);
|
||||
} else
|
||||
symkey = PSYNC_INVALID_SYM_KEY;
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return (pcrypto_textenc_t)errptr(
|
||||
pdbg_return_const(PSYNC_CRYPTO_FOLDER_NOT_FOUND));
|
||||
}
|
||||
|
|
@ -1187,21 +1187,21 @@ static pcrypto_textdec_t get_tmp_fldrdecoder_safe(psync_fsfolderid_t folderid) {
|
|||
sym_key_ver1 *skv1;
|
||||
psync_sql_res *res;
|
||||
psync_variant_row row;
|
||||
res = psync_sql_query_rdlock("SELECT text2 FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, -folderid);
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query_rdlock("SELECT text2 FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, -folderid);
|
||||
if ((row = psql_fetch(res))) {
|
||||
const unsigned char *b64enckey;
|
||||
unsigned char *enckey;
|
||||
size_t b64enckeylen, enckeylen;
|
||||
;
|
||||
if (psync_is_null(row[0])) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return (pcrypto_textdec_t)errptr(
|
||||
pdbg_return_const(PSYNC_CRYPTO_FOLDER_NOT_ENCRYPTED));
|
||||
}
|
||||
b64enckey = (const unsigned char *)psync_get_lstring(row[0], &b64enckeylen);
|
||||
enckey = psync_base64_decode(b64enckey, b64enckeylen, &enckeylen);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (enckey) {
|
||||
symkey = prsa_decrypt_data(crypto_privkey, enckey, enckeylen);
|
||||
|
||||
|
|
@ -1213,7 +1213,7 @@ static pcrypto_textdec_t get_tmp_fldrdecoder_safe(psync_fsfolderid_t folderid) {
|
|||
pdbg_logf(D_WARNING, "got key from database that fails base64_decode");
|
||||
}
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return (pcrypto_textdec_t)errptr(
|
||||
pdbg_return_const(PSYNC_CRYPTO_FOLDER_NOT_FOUND));
|
||||
}
|
||||
|
|
@ -1417,12 +1417,12 @@ static pcrypto_sector_encdec_t get_fileencoder_tmp(psync_fsfileid_t fileid,
|
|||
unsigned char *enckey;
|
||||
size_t enckeylen, b64enckeylen;
|
||||
psync_symmetric_key_t symkey;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT type, fileid, text2, int1 FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, -fileid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
psql_bind_uint(res, 1, -fileid);
|
||||
row = psql_fetch(res);
|
||||
if (pdbg_unlikely(!row)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return (pcrypto_sector_encdec_t)errptr(
|
||||
pdbg_return_const(PSYNC_CRYPTO_FILE_NOT_FOUND));
|
||||
}
|
||||
|
|
@ -1430,7 +1430,7 @@ static pcrypto_sector_encdec_t get_fileencoder_tmp(psync_fsfileid_t fileid,
|
|||
case PSYNC_FS_TASK_CREAT:
|
||||
b64enckey = (const unsigned char *)psync_get_lstring(row[2], &b64enckeylen);
|
||||
enckey = psync_base64_decode(b64enckey, b64enckeylen, &enckeylen);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (enckey) {
|
||||
symkey = prsa_decrypt_data(crypto_privkey, enckey, enckeylen);
|
||||
|
||||
|
|
@ -1464,10 +1464,10 @@ static pcrypto_sector_encdec_t get_fileencoder_tmp(psync_fsfileid_t fileid,
|
|||
case PSYNC_FS_TASK_MODIFY:
|
||||
fileid = psync_get_number(row[1]);
|
||||
hash = psync_get_number(row[3]);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return get_fileencoder(fileid, hash, nonetwork);
|
||||
default:
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return (pcrypto_sector_encdec_t)errptr(
|
||||
pdbg_return_const(PSYNC_CRYPTO_INTERNAL_ERROR));
|
||||
}
|
||||
|
|
@ -1611,11 +1611,11 @@ static int get_fldr_name(psync_folderid_t folderid,
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
int enc;
|
||||
res = psync_sql_query_rdlock("SELECT flags FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
res = psql_query_rdlock("SELECT flags FROM folder WHERE id=?");
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
enc = (row[0] & PSYNC_FOLDER_FLAG_ENCRYPTED) != 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (!row)
|
||||
return set_err(pdbg_return_const(PSYNC_CRYPTO_FOLDER_NOT_FOUND), err);
|
||||
if (enc)
|
||||
|
|
@ -1671,11 +1671,11 @@ int psync_cloud_crypto_send_mkdir(psync_folderid_t folderid, const char *name,
|
|||
meta = papi_find_result2(res, "metadata", PARAM_HASH);
|
||||
if (newfolderid)
|
||||
*newfolderid = papi_find_result2(meta, "folderid", PARAM_NUM)->num;
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
pfileops_create_fldr(meta);
|
||||
save_folder_key(papi_find_result2(meta, "folderid", PARAM_NUM)->num,
|
||||
encsym);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
free(res);
|
||||
return PSYNC_CRYPTO_SUCCESS;
|
||||
}
|
||||
|
|
@ -2013,15 +2013,15 @@ int pcryptofolder_change_pass(const char *oldpassphrase,
|
|||
|
||||
if (!newpassphrase || !newpassphrase[0])
|
||||
return PSYNC_CRYPTO_BAD_PASSPHRASE;
|
||||
while (psync_sql_trylock()) {
|
||||
while (psql_trylock()) {
|
||||
psys_sleep_milliseconds(1);
|
||||
}
|
||||
rowcnt = 0;
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT id, value FROM setting WHERE id IN ('crypto_private_key', "
|
||||
"'crypto_public_key', 'crypto_private_salt') ORDER BY id");
|
||||
if (res) {
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
id = psync_get_string(row[0]);
|
||||
rowcnt++;
|
||||
if (!strcmp(id, "crypto_private_key")) {
|
||||
|
|
@ -2053,9 +2053,9 @@ int pcryptofolder_change_pass(const char *oldpassphrase,
|
|||
free(salt);
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
if (rowcnt < 3) {
|
||||
free(privatekey_struct);
|
||||
free(pubkey_struct);
|
||||
|
|
|
|||
1047
pclsync/pdiff.c
1047
pclsync/pdiff.c
File diff suppressed because it is too large
Load Diff
|
|
@ -53,6 +53,7 @@
|
|||
#include "pfile.h"
|
||||
|
||||
extern const unsigned char pfile_invalid_chars[];
|
||||
pstatus_t psync_status;
|
||||
|
||||
typedef struct {
|
||||
psync_list list;
|
||||
|
|
@ -215,14 +216,14 @@ static void update_local_folder_mtime(const char *localpath,
|
|||
pdbg_logf(D_ERROR, "stat failed for %s", localpath);
|
||||
return;
|
||||
}
|
||||
res = psync_sql_prep_statement("UPDATE localfolder SET inode=?, deviceid=?, "
|
||||
res = psql_prepare("UPDATE localfolder SET inode=?, deviceid=?, "
|
||||
"mtime=?, mtimenative=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, pfile_stat_inode(&st));
|
||||
psync_sql_bind_uint(res, 2, pfile_stat_device(&st));
|
||||
psync_sql_bind_uint(res, 3, pfile_stat_mtime(&st));
|
||||
psync_sql_bind_uint(res, 4, pfile_stat_mtime_native(&st));
|
||||
psync_sql_bind_uint(res, 5, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, pfile_stat_inode(&st));
|
||||
psql_bind_uint(res, 2, pfile_stat_device(&st));
|
||||
psql_bind_uint(res, 3, pfile_stat_mtime(&st));
|
||||
psql_bind_uint(res, 4, pfile_stat_mtime_native(&st));
|
||||
psql_bind_uint(res, 5, localfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static int call_func_for_folder(psync_folderid_t localfolderid,
|
||||
|
|
@ -283,29 +284,29 @@ static void delete_local_folder_from_db(psync_folderid_t localfolderid,
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
if (likely(localfolderid)) {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id, syncid FROM localfolder WHERE localparentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
delete_local_folder_from_db(row[0], row[1]);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
res =
|
||||
psync_sql_query("SELECT id FROM localfile WHERE localparentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_query("SELECT id FROM localfile WHERE localparentfolderid=?");
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
pupload_del_tasks(row[0]);
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM localfile WHERE localparentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM syncedfolder WHERE localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement("DELETE FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM localfolder WHERE id=?");
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
ppathstatus_syncfldr_deleted(syncid, localfolderid);
|
||||
}
|
||||
|
|
@ -323,12 +324,12 @@ static int task_renamefolder(psync_syncid_t newsyncid,
|
|||
int ret;
|
||||
pdbg_assert(newname != NULL);
|
||||
task_wait_no_downloads();
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT syncid, localparentfolderid, name FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
row = psql_fetch(res);
|
||||
if (unlikely(!row)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_ERROR, "could not find local folder id %lu",
|
||||
(unsigned long)localfolderid);
|
||||
return 0;
|
||||
|
|
@ -337,44 +338,44 @@ static int task_renamefolder(psync_syncid_t newsyncid,
|
|||
if (oldsyncid == newsyncid &&
|
||||
psync_get_number(row[1]) == newlocalparentfolderid &&
|
||||
!strcmp(psync_get_string(row[2]), newname)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE,
|
||||
"folder %s already renamed locally, probably update initiated from "
|
||||
"this client",
|
||||
newname);
|
||||
return 0;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
oldpath = pfolder_lpath_lfldr(localfolderid, oldsyncid, NULL);
|
||||
if (unlikely(!oldpath)) {
|
||||
pdbg_logf(D_ERROR, "could not get local path for folder id %lu",
|
||||
(unsigned long)localfolderid);
|
||||
return 0;
|
||||
}
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
psync_restart_localscan();
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT syncid, localparentfolderid FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
if ((urow = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
if ((urow = psql_fetch_int(res))) {
|
||||
ppathstatus_syncfldr_moved(localfolderid, urow[0], urow[1],
|
||||
newsyncid, newlocalparentfolderid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE, "localfolderid %u not found in localfolder",
|
||||
(unsigned)localfolderid);
|
||||
}
|
||||
res = psync_sql_prep_statement("UPDATE localfolder SET syncid=?, "
|
||||
res = psql_prepare("UPDATE localfolder SET syncid=?, "
|
||||
"localparentfolderid=?, name=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, newsyncid);
|
||||
psync_sql_bind_uint(res, 2, newlocalparentfolderid);
|
||||
psync_sql_bind_string(res, 3, newname);
|
||||
psync_sql_bind_uint(res, 4, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, newsyncid);
|
||||
psql_bind_uint(res, 2, newlocalparentfolderid);
|
||||
psql_bind_str(res, 3, newname);
|
||||
psql_bind_uint(res, 4, localfolderid);
|
||||
psql_run_free(res);
|
||||
newpath = pfolder_lpath_lfldr(localfolderid, newsyncid, NULL);
|
||||
if (unlikely(!newpath)) {
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
free(oldpath);
|
||||
pdbg_logf(D_ERROR, "could not get local path for folder id %lu",
|
||||
(unsigned long)localfolderid);
|
||||
|
|
@ -382,10 +383,10 @@ static int task_renamefolder(psync_syncid_t newsyncid,
|
|||
}
|
||||
ret = task_renamedir(oldpath, newpath);
|
||||
if (ret)
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
else {
|
||||
psyncer_folder_dec_tasks(localfolderid);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
pqevent_queue_sync_event_id(PEVENT_LOCAL_FOLDER_RENAMED, newsyncid, newpath,
|
||||
folderid);
|
||||
pdbg_logf(D_NOTICE, "local folder renamed from %s to %s", oldpath, newpath);
|
||||
|
|
@ -403,12 +404,12 @@ static int create_conflicted(const char *name, psync_folderid_t localfolderid,
|
|||
psync_resume_localscan();
|
||||
return -1;
|
||||
}
|
||||
res = psync_sql_prep_statement("DELETE FROM localfile WHERE syncid=? AND "
|
||||
res = psql_prepare("DELETE FROM localfile WHERE syncid=? AND "
|
||||
"localparentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, localfolderid);
|
||||
psync_sql_bind_string(res, 3, filename);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, localfolderid);
|
||||
psql_bind_str(res, 3, filename);
|
||||
psql_run_free(res);
|
||||
psync_resume_localscan();
|
||||
psync_wake_localscan();
|
||||
return 0;
|
||||
|
|
@ -456,27 +457,27 @@ static int stat_and_create_local(psync_syncid_t syncid, psync_fileid_t fileid,
|
|||
pdbg_unlikely(pfile_stat_size(&st) != serversize))
|
||||
return -1;
|
||||
localfileid = 0;
|
||||
psync_sql_start_transaction();
|
||||
sql = psync_sql_query_nolock("SELECT id FROM localfile WHERE syncid=? AND "
|
||||
psql_start();
|
||||
sql = psql_query_nolock("SELECT id FROM localfile WHERE syncid=? AND "
|
||||
"localparentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(sql, 1, syncid);
|
||||
psync_sql_bind_uint(sql, 2, localfolderid);
|
||||
psync_sql_bind_string(sql, 3, filename);
|
||||
if ((row = psync_sql_fetch_rowint(sql)))
|
||||
psql_bind_uint(sql, 1, syncid);
|
||||
psql_bind_uint(sql, 2, localfolderid);
|
||||
psql_bind_str(sql, 3, filename);
|
||||
if ((row = psql_fetch_int(sql)))
|
||||
localfileid = row[0];
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
|
||||
sql = psync_sql_query_nolock("SELECT parentfolderid FROM file WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, fileid);
|
||||
row = psync_sql_fetch_rowint(sql);
|
||||
sql = psql_query_nolock("SELECT parentfolderid FROM file WHERE id=?");
|
||||
psql_bind_uint(sql, 1, fileid);
|
||||
row = psql_fetch_int(sql);
|
||||
if (!row || !psyncer_dl_has_folder(row[0])) {
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
if (localfileid) {
|
||||
sql = psync_sql_prep_statement("DELETE FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, localfileid);
|
||||
psync_sql_run_free(sql);
|
||||
sql = psql_prepare("DELETE FROM localfile WHERE id=?");
|
||||
psql_bind_uint(sql, 1, localfileid);
|
||||
psql_run_free(sql);
|
||||
}
|
||||
psync_sql_commit_transaction(sql);
|
||||
psql_commit(sql);
|
||||
pfile_delete(name);
|
||||
if (row)
|
||||
pdbg_logf(D_NOTICE,
|
||||
|
|
@ -489,43 +490,43 @@ static int stat_and_create_local(psync_syncid_t syncid, psync_fileid_t fileid,
|
|||
(unsigned long)fileid, filename, name);
|
||||
return 0;
|
||||
}
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
|
||||
if (localfileid) {
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"UPDATE localfile SET localparentfolderid=?, fileid=?, hash=?, "
|
||||
"syncid=?, size=?, inode=?, mtime=?, mtimenative=?, "
|
||||
"name=?, checksum=? WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, localfolderid);
|
||||
psync_sql_bind_uint(sql, 2, fileid);
|
||||
psync_sql_bind_uint(sql, 3, hash);
|
||||
psync_sql_bind_uint(sql, 4, syncid);
|
||||
psync_sql_bind_uint(sql, 5, pfile_stat_size(&st));
|
||||
psync_sql_bind_uint(sql, 6, pfile_stat_inode(&st));
|
||||
psync_sql_bind_uint(sql, 7, pfile_stat_mtime(&st));
|
||||
psync_sql_bind_uint(sql, 8, pfile_stat_mtime_native(&st));
|
||||
psync_sql_bind_string(sql, 9, filename);
|
||||
psync_sql_bind_lstring(sql, 10, (char *)checksum, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psync_sql_bind_uint(sql, 11, localfileid);
|
||||
psync_sql_run_free(sql);
|
||||
psql_bind_uint(sql, 1, localfolderid);
|
||||
psql_bind_uint(sql, 2, fileid);
|
||||
psql_bind_uint(sql, 3, hash);
|
||||
psql_bind_uint(sql, 4, syncid);
|
||||
psql_bind_uint(sql, 5, pfile_stat_size(&st));
|
||||
psql_bind_uint(sql, 6, pfile_stat_inode(&st));
|
||||
psql_bind_uint(sql, 7, pfile_stat_mtime(&st));
|
||||
psql_bind_uint(sql, 8, pfile_stat_mtime_native(&st));
|
||||
psql_bind_str(sql, 9, filename);
|
||||
psql_bind_lstr(sql, 10, (char *)checksum, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psql_bind_uint(sql, 11, localfileid);
|
||||
psql_run_free(sql);
|
||||
} else {
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"REPLACE INTO localfile (localparentfolderid, fileid, hash, syncid, "
|
||||
"size, inode, mtime, mtimenative, name, checksum)"
|
||||
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(sql, 1, localfolderid);
|
||||
psync_sql_bind_uint(sql, 2, fileid);
|
||||
psync_sql_bind_uint(sql, 3, hash);
|
||||
psync_sql_bind_uint(sql, 4, syncid);
|
||||
psync_sql_bind_uint(sql, 5, pfile_stat_size(&st));
|
||||
psync_sql_bind_uint(sql, 6, pfile_stat_inode(&st));
|
||||
psync_sql_bind_uint(sql, 7, pfile_stat_mtime(&st));
|
||||
psync_sql_bind_uint(sql, 8, pfile_stat_mtime_native(&st));
|
||||
psync_sql_bind_string(sql, 9, filename);
|
||||
psync_sql_bind_lstring(sql, 10, (char *)checksum, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psync_sql_run_free(sql);
|
||||
psql_bind_uint(sql, 1, localfolderid);
|
||||
psql_bind_uint(sql, 2, fileid);
|
||||
psql_bind_uint(sql, 3, hash);
|
||||
psql_bind_uint(sql, 4, syncid);
|
||||
psql_bind_uint(sql, 5, pfile_stat_size(&st));
|
||||
psql_bind_uint(sql, 6, pfile_stat_inode(&st));
|
||||
psql_bind_uint(sql, 7, pfile_stat_mtime(&st));
|
||||
psql_bind_uint(sql, 8, pfile_stat_mtime_native(&st));
|
||||
psql_bind_str(sql, 9, filename);
|
||||
psql_bind_lstr(sql, 10, (char *)checksum, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psql_run_free(sql);
|
||||
}
|
||||
return psync_sql_commit_transaction();
|
||||
return psql_commit();
|
||||
}
|
||||
|
||||
// rename_and_create_local(dt->tmpname, dt->localname, dt->dwllist.syncid,
|
||||
|
|
@ -607,30 +608,30 @@ static int task_download_file(download_task_t *dt) {
|
|||
pstatus_send_update();
|
||||
}
|
||||
|
||||
sql = psync_sql_query_rdlock(
|
||||
sql = psql_query_rdlock(
|
||||
"SELECT fileid, id, hash FROM localfile WHERE size=? AND checksum=? AND "
|
||||
"localparentfolderid=? AND syncid=? AND name=?");
|
||||
psync_sql_bind_uint(sql, 1, serversize);
|
||||
psync_sql_bind_lstring(sql, 2, (char *)serverhashhex,
|
||||
psql_bind_uint(sql, 1, serversize);
|
||||
psql_bind_lstr(sql, 2, (char *)serverhashhex,
|
||||
PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psync_sql_bind_uint(sql, 3, dt->localfolderid);
|
||||
psync_sql_bind_uint(sql, 4, dt->dwllist.syncid);
|
||||
psync_sql_bind_string(sql, 5, dt->filename);
|
||||
if ((row = psync_sql_fetch_rowint(sql))) {
|
||||
psql_bind_uint(sql, 3, dt->localfolderid);
|
||||
psql_bind_uint(sql, 4, dt->dwllist.syncid);
|
||||
psql_bind_str(sql, 5, dt->filename);
|
||||
if ((row = psql_fetch_int(sql))) {
|
||||
rt = row[0] != dt->dwllist.fileid || row[2] != hash;
|
||||
result = row[1];
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
if (rt) {
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"UPDATE localfile SET fileid=?, hash=? WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, dt->dwllist.fileid);
|
||||
psync_sql_bind_uint(sql, 2, hash);
|
||||
psync_sql_bind_uint(sql, 3, result);
|
||||
psync_sql_run_free(sql);
|
||||
psql_bind_uint(sql, 1, dt->dwllist.fileid);
|
||||
psql_bind_uint(sql, 2, hash);
|
||||
psql_bind_uint(sql, 3, result);
|
||||
psql_run_free(sql);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
|
||||
if (dt->localexists && dt->localsize == serversize &&
|
||||
!memcmp(dt->checksum, serverhashhex, PSYNC_HASH_DIGEST_HEXLEN)) {
|
||||
|
|
@ -647,16 +648,16 @@ static int task_download_file(download_task_t *dt) {
|
|||
}
|
||||
}
|
||||
|
||||
sql = psync_sql_query_rdlock(
|
||||
sql = psql_query_rdlock(
|
||||
"SELECT id FROM localfile WHERE size=? AND checksum=?");
|
||||
psync_sql_bind_uint(sql, 1, serversize);
|
||||
psync_sql_bind_lstring(sql, 2, (char *)serverhashhex,
|
||||
psql_bind_uint(sql, 1, serversize);
|
||||
psql_bind_lstr(sql, 2, (char *)serverhashhex,
|
||||
PSYNC_HASH_DIGEST_HEXLEN);
|
||||
while ((row = psync_sql_fetch_rowint(sql))) {
|
||||
while ((row = psql_fetch_int(sql))) {
|
||||
tmpold = pfolder_lpath_lfile(row[0], NULL);
|
||||
if (pdbg_unlikely(!tmpold))
|
||||
continue;
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
sql = NULL;
|
||||
rt = psync_copy_local_file_if_checksum_matches(tmpold, dt->tmpname,
|
||||
serverhashhex, serversize);
|
||||
|
|
@ -675,7 +676,7 @@ static int task_download_file(download_task_t *dt) {
|
|||
break;
|
||||
}
|
||||
if (sql)
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
|
||||
if (dt->dwllist.stop)
|
||||
return 0;
|
||||
|
|
@ -893,14 +894,14 @@ static int task_delete_file(psync_syncid_t syncid, psync_fileid_t fileid,
|
|||
ret = 0;
|
||||
task_wait_no_downloads();
|
||||
if (syncid) {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id, syncid FROM localfile WHERE fileid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
} else
|
||||
res = psync_sql_query("SELECT id, syncid FROM localfile WHERE fileid=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
res = psql_query("SELECT id, syncid FROM localfile WHERE fileid=?");
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
psync_restart_localscan();
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
while ((row = psql_fetch_int(res))) {
|
||||
name = pfolder_lpath_lfile(row[0], NULL);
|
||||
if (pdbg_likely(name)) {
|
||||
if (unlikely(pfile_delete(name))) {
|
||||
|
|
@ -919,11 +920,11 @@ static int task_delete_file(psync_syncid_t syncid, psync_fileid_t fileid,
|
|||
// fileid, remotepath);
|
||||
free(name);
|
||||
}
|
||||
stmt = psync_sql_prep_statement("DELETE FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(stmt, 1, row[0]);
|
||||
psync_sql_run_free(stmt);
|
||||
stmt = psql_prepare("DELETE FROM localfile WHERE id=?");
|
||||
psql_bind_uint(stmt, 1, row[0]);
|
||||
psql_run_free(stmt);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -940,11 +941,11 @@ static int task_rename_file(psync_syncid_t oldsyncid, psync_syncid_t newsyncid,
|
|||
psync_syncid_t syncid;
|
||||
int ret;
|
||||
task_wait_no_downloads();
|
||||
res = psync_sql_query("SELECT id, localparentfolderid, syncid, name FROM "
|
||||
res = psql_query("SELECT id, localparentfolderid, syncid, name FROM "
|
||||
"localfile WHERE fileid=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
lfileid = 0;
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
syncid = psync_get_number(row[2]);
|
||||
if (psync_get_number(row[1]) == newlocalfolderid && syncid == newsyncid &&
|
||||
!strcmp(psync_get_string(row[3]), newname)) {
|
||||
|
|
@ -952,14 +953,14 @@ static int task_rename_file(psync_syncid_t oldsyncid, psync_syncid_t newsyncid,
|
|||
"file %s already renamed locally, probably update initiated from "
|
||||
"this client",
|
||||
newname);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return 0;
|
||||
} else if (syncid == oldsyncid) {
|
||||
lfileid = psync_get_number(row[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (pdbg_unlikely(!lfileid)) {
|
||||
ptask_download(newsyncid, fileid, newlocalfolderid, newname);
|
||||
return 0;
|
||||
|
|
@ -986,17 +987,17 @@ static int task_rename_file(psync_syncid_t oldsyncid, psync_syncid_t newsyncid,
|
|||
ret = -1;
|
||||
} else {
|
||||
if (pdbg_likely(!stat(newpath, &st))) {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE OR REPLACE localfile SET localparentfolderid=?, syncid=?, "
|
||||
"name=?, inode=?, mtime=?, mtimenative=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, newlocalfolderid);
|
||||
psync_sql_bind_uint(res, 2, newsyncid);
|
||||
psync_sql_bind_string(res, 3, newname);
|
||||
psync_sql_bind_uint(res, 4, pfile_stat_inode(&st));
|
||||
psync_sql_bind_uint(res, 5, pfile_stat_mtime(&st));
|
||||
psync_sql_bind_uint(res, 6, pfile_stat_mtime_native(&st));
|
||||
psync_sql_bind_uint(res, 7, lfileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, newlocalfolderid);
|
||||
psql_bind_uint(res, 2, newsyncid);
|
||||
psql_bind_str(res, 3, newname);
|
||||
psql_bind_uint(res, 4, pfile_stat_inode(&st));
|
||||
psql_bind_uint(res, 5, pfile_stat_mtime(&st));
|
||||
psql_bind_uint(res, 6, pfile_stat_mtime_native(&st));
|
||||
psql_bind_uint(res, 7, lfileid);
|
||||
psql_run_free(res);
|
||||
pdbg_logf(D_NOTICE, "renamed %s to %s", oldpath, newpath);
|
||||
}
|
||||
psync_resume_localscan();
|
||||
|
|
@ -1009,17 +1010,17 @@ static int task_rename_file(psync_syncid_t oldsyncid, psync_syncid_t newsyncid,
|
|||
|
||||
static void set_task_inprogress(uint64_t taskid, uint32_t val) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("UPDATE task SET inprogress=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, val);
|
||||
psync_sql_bind_uint(res, 2, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE task SET inprogress=? WHERE id=?");
|
||||
psql_bind_uint(res, 1, val);
|
||||
psql_bind_uint(res, 2, taskid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void delete_task(uint64_t taskid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("DELETE FROM task WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM task WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void free_download_task(download_task_t *dt) {
|
||||
|
|
@ -1060,11 +1061,11 @@ static void handle_async_error(download_task_t *dt, psync_async_result_t *res) {
|
|||
psync_sql_res *sres;
|
||||
pdbg_assert(res->file.size > PSYNC_MAX_SIZE_FOR_ASYNC_DOWNLOAD);
|
||||
sres =
|
||||
psync_sql_prep_statement("UPDATE file SET size=?, hash=? WHERE id=?");
|
||||
psync_sql_bind_uint(sres, 1, res->file.size);
|
||||
psync_sql_bind_uint(sres, 2, res->file.hash);
|
||||
psync_sql_bind_uint(sres, 3, dt->dwllist.fileid);
|
||||
psync_sql_run_free(sres);
|
||||
psql_prepare("UPDATE file SET size=?, hash=? WHERE id=?");
|
||||
psql_bind_uint(sres, 1, res->file.size);
|
||||
psql_bind_uint(sres, 2, res->file.hash);
|
||||
psql_bind_uint(sres, 3, dt->dwllist.fileid);
|
||||
psql_run_free(sres);
|
||||
set_task_inprogress(dt->taskid, 0);
|
||||
free_download_task(dt);
|
||||
pstatus_send_status_update();
|
||||
|
|
@ -1159,10 +1160,10 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid,
|
|||
size_t len;
|
||||
unsigned char targetchecksum[PSYNC_HASH_DIGEST_HEXLEN];
|
||||
int hastargetchecksum, ret;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT size, hash, ctime, mtime FROM file WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
row = psql_fetch_int(res);
|
||||
if (row) {
|
||||
size = row[0];
|
||||
hash = row[1];
|
||||
|
|
@ -1175,23 +1176,23 @@ static int task_run_download_file(uint64_t taskid, psync_syncid_t syncid,
|
|||
crtime = 0;
|
||||
mtime = 0;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (!row) {
|
||||
pdbg_logf(D_NOTICE, "possible race, fileid %lu not found in file table",
|
||||
(unsigned long)size);
|
||||
return 0; // this will delete the task
|
||||
}
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT checksum FROM hashchecksum WHERE hash=? AND size=?");
|
||||
psync_sql_bind_uint(res, 1, hash);
|
||||
psync_sql_bind_uint(res, 2, size);
|
||||
srow = psync_sql_fetch_rowstr(res);
|
||||
psql_bind_uint(res, 1, hash);
|
||||
psql_bind_uint(res, 2, size);
|
||||
srow = psql_fetch_str(res);
|
||||
if (srow) {
|
||||
memcpy(targetchecksum, srow[0], PSYNC_HASH_DIGEST_HEXLEN);
|
||||
hastargetchecksum = 1;
|
||||
} else
|
||||
hastargetchecksum = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
localpath = pfolder_lpath_lfldr(localfolderid, syncid, NULL);
|
||||
if (pdbg_unlikely(!localpath))
|
||||
return 0;
|
||||
|
|
@ -1329,11 +1330,11 @@ static void task_del_folder_rec_do(const char *localpath,
|
|||
psync_sql_res *res;
|
||||
psync_variant_row vrow;
|
||||
char *nm;
|
||||
res = psync_sql_query("SELECT id, name FROM localfile WHERE "
|
||||
res = psql_query("SELECT id, name FROM localfile WHERE "
|
||||
"localparentfolderid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
while ((vrow = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
while ((vrow = psql_fetch(res))) {
|
||||
pupload_del_tasks(psync_get_number(vrow[0]));
|
||||
nm = psync_strcat(localpath, "/",
|
||||
psync_get_string(vrow[1]), NULL);
|
||||
|
|
@ -1341,33 +1342,33 @@ static void task_del_folder_rec_do(const char *localpath,
|
|||
pfile_delete(nm);
|
||||
free(nm);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM localfile WHERE localparentfolderid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_query("SELECT id, name FROM localfolder WHERE "
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_run_free(res);
|
||||
res = psql_query("SELECT id, name FROM localfolder WHERE "
|
||||
"localparentfolderid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
while ((vrow = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
while ((vrow = psql_fetch(res))) {
|
||||
nm = psync_strcat(localpath, "/",
|
||||
psync_get_string(vrow[1]), NULL);
|
||||
task_del_folder_rec_do(nm, psync_get_number(vrow[0]), syncid);
|
||||
free(nm);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM localfolder WHERE localparentfolderid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_run_free(res);
|
||||
if (psync_sql_affected_rows()) {
|
||||
res = psync_sql_prep_statement(
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_run_free(res);
|
||||
if (psql_affected()) {
|
||||
res = psql_prepare(
|
||||
"DELETE FROM syncedfolder WHERE localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
ppathstatus_syncfldr_deleted(syncid, localfolderid);
|
||||
}
|
||||
|
|
@ -1386,20 +1387,20 @@ static int task_del_folder_rec(psync_folderid_t localfolderid,
|
|||
}
|
||||
pdbg_logf(D_NOTICE, "got recursive delete for localfolder %lu %s",
|
||||
(unsigned long)localfolderid, localpath);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
task_del_folder_rec_do(localpath, localfolderid, syncid);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"DELETE FROM localfolder WHERE id=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_run_free(res);
|
||||
if (psync_sql_affected_rows()) {
|
||||
res = psync_sql_prep_statement(
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_run_free(res);
|
||||
if (psql_affected()) {
|
||||
res = psql_prepare(
|
||||
"DELETE FROM syncedfolder WHERE localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
psync_rmdir_with_trashes(localpath);
|
||||
psync_resume_localscan();
|
||||
return 0;
|
||||
|
|
@ -1436,9 +1437,9 @@ static int download_task(uint64_t taskid, uint32_t type, psync_syncid_t syncid,
|
|||
PEVENT_LOCAL_FOLDER_DELETED, task_rmdir, 0,
|
||||
"local folder deleted");
|
||||
if (!res) {
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
delete_local_folder_from_db(localitemid, syncid);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
break;
|
||||
case PSYNC_DELREC_LOCAL_FOLDER:
|
||||
|
|
@ -1476,7 +1477,7 @@ static void download_thread() {
|
|||
while (psync_do_run) {
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
|
||||
row = psync_sql_row(
|
||||
row = psql_row(
|
||||
"SELECT id, type, syncid, itemid, localitemid, newitemid, name, "
|
||||
"newsyncid FROM task WHERE "
|
||||
"inprogress=0 AND type&" NTO_STR(PSYNC_TASK_DWLUPL_MASK) "=" NTO_STR(
|
||||
|
|
@ -1527,18 +1528,18 @@ void pdownload_tasks_delete(psync_fileid_t fileid,
|
|||
download_list_t *dwl;
|
||||
uint32_t aff;
|
||||
if (syncid)
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"DELETE FROM task WHERE type=? AND itemid=? AND syncid=?");
|
||||
else
|
||||
res =
|
||||
psync_sql_prep_statement("DELETE FROM task WHERE type=? AND itemid=?");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, fileid);
|
||||
psql_prepare("DELETE FROM task WHERE type=? AND itemid=?");
|
||||
psql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psql_bind_uint(res, 2, fileid);
|
||||
if (syncid)
|
||||
psync_sql_bind_uint(res, 3, syncid);
|
||||
psync_sql_run(res);
|
||||
aff = psync_sql_affected_rows();
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 3, syncid);
|
||||
psql_run(res);
|
||||
aff = psql_affected();
|
||||
psql_free(res);
|
||||
if (aff)
|
||||
pstatus_download_recalc_async();
|
||||
if (deltemp)
|
||||
|
|
@ -1565,11 +1566,11 @@ void pdownload_stop_file(psync_fileid_t fileid, psync_syncid_t syncid) {
|
|||
void pdownload_stop_sync(psync_syncid_t syncid) {
|
||||
download_list_t *dwl;
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"DELETE FROM task WHERE syncid=? AND type&" NTO_STR(
|
||||
PSYNC_TASK_DWLUPL_MASK) "=" NTO_STR(PSYNC_TASK_DOWNLOAD));
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_run_free(res);
|
||||
pstatus_download_recalc_async();
|
||||
pthread_mutex_lock(¤t_downloads_mutex);
|
||||
psync_list_for_each_element(dwl, &downloads, download_list_t,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ void pfileops_create_fldr(const binresult *meta) {
|
|||
flags = 0;
|
||||
if ((name = papi_check_result2(meta, "encrypted", PARAM_BOOL)) && name->num)
|
||||
flags |= PSYNC_FOLDER_FLAG_ENCRYPTED;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT OR IGNORE INTO folder (id, parentfolderid, userid, permissions, "
|
||||
"name, ctime, mtime, flags) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
if (papi_find_result2(meta, "ismine", PARAM_BOOL)->num) {
|
||||
|
|
@ -53,19 +53,19 @@ void pfileops_create_fldr(const binresult *meta) {
|
|||
perms = pfileops_get_perms(meta);
|
||||
}
|
||||
name = papi_find_result2(meta, "name", PARAM_STR);
|
||||
psync_sql_bind_uint(res, 1,
|
||||
psql_bind_uint(res, 1,
|
||||
papi_find_result2(meta, "folderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
res, 2, papi_find_result2(meta, "parentfolderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(res, 3, userid);
|
||||
psync_sql_bind_uint(res, 4, perms);
|
||||
psync_sql_bind_lstring(res, 5, name->str, name->length);
|
||||
psync_sql_bind_uint(res, 6,
|
||||
psql_bind_uint(res, 3, userid);
|
||||
psql_bind_uint(res, 4, perms);
|
||||
psql_bind_lstr(res, 5, name->str, name->length);
|
||||
psql_bind_uint(res, 6,
|
||||
papi_find_result2(meta, "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(res, 7,
|
||||
psql_bind_uint(res, 7,
|
||||
papi_find_result2(meta, "modified", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(res, 8, flags);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 8, flags);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void pfileops_update_fldr(const binresult *meta) {
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ psync_folderid_t pfolder_id(const char *path) {
|
|||
path++;
|
||||
if (*path == 0) {
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return cfolderid;
|
||||
}
|
||||
sl = strchr(path, '/');
|
||||
|
|
@ -89,18 +89,18 @@ psync_folderid_t pfolder_id(const char *path) {
|
|||
else
|
||||
len = strlen(path);
|
||||
if (!res) {
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id FROM folder WHERE parentfolderid=? AND name=?");
|
||||
if (pdbg_unlikely(!res)) {
|
||||
psync_error = PERROR_DATABASE_ERROR;
|
||||
return PSYNC_INVALID_FOLDERID;
|
||||
}
|
||||
} else
|
||||
psync_sql_reset(res);
|
||||
psql_reset(res);
|
||||
|
||||
psync_sql_bind_uint(res, 1, cfolderid);
|
||||
psync_sql_bind_lstring(res, 2, path, len);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, cfolderid);
|
||||
psql_bind_lstr(res, 2, path, len);
|
||||
row = psql_fetch_int(res);
|
||||
if (pdbg_unlikely(!row))
|
||||
goto err;
|
||||
cfolderid = row[0];
|
||||
|
|
@ -108,7 +108,7 @@ psync_folderid_t pfolder_id(const char *path) {
|
|||
}
|
||||
err:
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_error = PERROR_REMOTE_FOLDER_NOT_FOUND;
|
||||
return PSYNC_INVALID_FOLDERID;
|
||||
}
|
||||
|
|
@ -119,10 +119,10 @@ static psync_folderid_t wait_folder_id_in_db(psync_folderid_t folderid) {
|
|||
int tries;
|
||||
tries = 0;
|
||||
while (++tries <= 20) {
|
||||
res = psync_sql_query_rdlock("SELECT id FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
res = psql_query_rdlock("SELECT id FROM folder WHERE id=?");
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
if (row)
|
||||
return folderid;
|
||||
psys_sleep_milliseconds(50);
|
||||
|
|
@ -149,7 +149,7 @@ psync_folderid_t pfolder_id_create(const char *path) {
|
|||
path++;
|
||||
if (*path == 0) {
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return wait_folder_id_in_db(cfolderid);
|
||||
}
|
||||
sl = strchr(path, '/');
|
||||
|
|
@ -158,17 +158,17 @@ psync_folderid_t pfolder_id_create(const char *path) {
|
|||
else
|
||||
len = strlen(path);
|
||||
if (!res) {
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id FROM folder WHERE parentfolderid=? AND name=?");
|
||||
if (pdbg_unlikely(!res)) {
|
||||
psync_error = PERROR_DATABASE_ERROR;
|
||||
return PSYNC_INVALID_FOLDERID;
|
||||
}
|
||||
} else
|
||||
psync_sql_reset(res);
|
||||
psync_sql_bind_uint(res, 1, cfolderid);
|
||||
psync_sql_bind_lstring(res, 2, path, len);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_reset(res);
|
||||
psql_bind_uint(res, 1, cfolderid);
|
||||
psql_bind_lstr(res, 2, path, len);
|
||||
row = psql_fetch_int(res);
|
||||
if (row)
|
||||
cfolderid = row[0];
|
||||
else {
|
||||
|
|
@ -210,12 +210,12 @@ psync_folderid_t pfolder_id_create(const char *path) {
|
|||
}
|
||||
err:
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_error = PERROR_REMOTE_FOLDER_NOT_FOUND;
|
||||
return PSYNC_INVALID_FOLDERID;
|
||||
errnet:
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_error = PERROR_OFFLINE;
|
||||
return PSYNC_INVALID_FOLDERID;
|
||||
}
|
||||
|
|
@ -247,19 +247,19 @@ static int psync_add_path_to_list(psync_list *lst, psync_folderid_t folderid) {
|
|||
psync_list_add_head(lst, &e->list);
|
||||
return 0;
|
||||
}
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT parentfolderid, name FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
row = psql_fetch(res);
|
||||
if (unlikely(!row))
|
||||
break;
|
||||
folderid = psync_get_number(row[0]);
|
||||
str = psync_get_lstring(row[1], &len);
|
||||
e = str_to_list_element(str, len);
|
||||
psync_list_add_head(lst, &e->list);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_ERROR, "folder %lu not found in database", (unsigned long)folderid);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -304,10 +304,10 @@ static int psync_add_path_to_list_decode(psync_list *lst,
|
|||
psync_list_add_head(lst, &e->list);
|
||||
return 0;
|
||||
}
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT parentfolderid, name, flags FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
row = psql_fetch(res);
|
||||
if (pdbg_unlikely(!row))
|
||||
break;
|
||||
cfolderid = folderid;
|
||||
|
|
@ -315,7 +315,7 @@ static int psync_add_path_to_list_decode(psync_list *lst,
|
|||
folderid = psync_get_number(row[0]);
|
||||
str = psync_get_lstring(row[1], &len);
|
||||
c = str_to_list_element(str, len);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (e) {
|
||||
if (flags & PSYNC_FOLDER_FLAG_ENCRYPTED) {
|
||||
e = str_list_decode(cfolderid, e);
|
||||
|
|
@ -326,7 +326,7 @@ static int psync_add_path_to_list_decode(psync_list *lst,
|
|||
}
|
||||
e = c;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
err:
|
||||
pdbg_logf(D_ERROR, "folder %lu not found in database", (unsigned long)folderid);
|
||||
return -1;
|
||||
|
|
@ -363,9 +363,9 @@ char *pfolder_path(psync_folderid_t folderid, size_t *retlen) {
|
|||
char *ret;
|
||||
int res;
|
||||
psync_list_init(&folderlist);
|
||||
psync_sql_rdlock();
|
||||
psql_rdlock();
|
||||
res = psync_add_path_to_list(&folderlist, folderid);
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
if (pdbg_unlikely(res)) {
|
||||
psync_free_string_list(&folderlist);
|
||||
return PSYNC_INVALID_PATH;
|
||||
|
|
@ -413,27 +413,27 @@ char *pfolder_file_path(psync_fileid_t fileid, size_t *retlen) {
|
|||
psync_folderid_t folderid;
|
||||
size_t len;
|
||||
psync_list_init(&folderlist);
|
||||
psync_sql_rdlock();
|
||||
res = psync_sql_query_rdlock(
|
||||
psql_rdlock();
|
||||
res = psql_query_rdlock(
|
||||
"SELECT parentfolderid, name FROM file WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
row = psql_fetch(res);
|
||||
if (pdbg_unlikely(!row)) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
psql_free(res);
|
||||
psql_rdunlock();
|
||||
return PSYNC_INVALID_PATH;
|
||||
}
|
||||
folderid = psync_get_number(row[0]);
|
||||
str = psync_get_lstring(row[1], &len);
|
||||
e = str_to_list_element(str, len);
|
||||
psync_list_add_head(&folderlist, &e->list);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (pdbg_unlikely(psync_add_path_to_list(&folderlist, folderid))) {
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
psync_free_string_list(&folderlist);
|
||||
return PSYNC_INVALID_PATH;
|
||||
}
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
ret = psync_join_string_list("/", &folderlist, retlen);
|
||||
psync_free_string_list(&folderlist);
|
||||
return ret;
|
||||
|
|
@ -446,35 +446,35 @@ static int psync_add_local_path_to_list_by_localfolderid(
|
|||
psync_variant_row row;
|
||||
const char *str;
|
||||
size_t len;
|
||||
res = psync_sql_query_rdlock("SELECT localpath FROM syncfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
res = psql_query_rdlock("SELECT localpath FROM syncfolder WHERE id=?");
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
row = psql_fetch(res);
|
||||
if (unlikely(!row)) {
|
||||
pdbg_logf(D_ERROR, "could not find sync id %lu", (long unsigned)syncid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return -1;
|
||||
}
|
||||
str = psync_get_lstring(row[0], &len);
|
||||
le = str_to_list_element(str, len);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
while (1) {
|
||||
if (localfolderid == 0) {
|
||||
psync_list_add_head(lst, &le->list);
|
||||
return 0;
|
||||
}
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT localparentfolderid, name FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
row = psql_fetch(res);
|
||||
if (unlikely(!row))
|
||||
break;
|
||||
localfolderid = psync_get_number(row[0]);
|
||||
str = psync_get_lstring(row[1], &len);
|
||||
e = str_to_list_element(str, len);
|
||||
psync_list_add_head(lst, &e->list);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_list_add_head(lst, &le->list);
|
||||
pdbg_logf(D_ERROR, "local folder %lu not found in database",
|
||||
(unsigned long)localfolderid);
|
||||
|
|
@ -487,10 +487,10 @@ char *pfolder_lpath_lfldr(psync_folderid_t localfolderid,
|
|||
char *ret;
|
||||
int res;
|
||||
psync_list_init(&folderlist);
|
||||
psync_sql_rdlock();
|
||||
psql_rdlock();
|
||||
res = psync_add_local_path_to_list_by_localfolderid(&folderlist,
|
||||
localfolderid, syncid);
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
if (pdbg_unlikely(res)) {
|
||||
psync_free_string_list(&folderlist);
|
||||
return PSYNC_INVALID_PATH;
|
||||
|
|
@ -513,13 +513,13 @@ char *pfolder_lpath_lfile(psync_fileid_t localfileid,
|
|||
psync_syncid_t syncid;
|
||||
int rs;
|
||||
psync_list_init(&folderlist);
|
||||
psync_sql_rdlock();
|
||||
res = psync_sql_query_nolock(
|
||||
psql_rdlock();
|
||||
res = psql_query_nolock(
|
||||
"SELECT localparentfolderid, syncid, name FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
if (pdbg_unlikely(!(row = psync_sql_fetch_row(res)))) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
if (pdbg_unlikely(!(row = psql_fetch(res)))) {
|
||||
psql_free(res);
|
||||
psql_rdunlock();
|
||||
psync_free_string_list(&folderlist);
|
||||
return PSYNC_INVALID_PATH;
|
||||
}
|
||||
|
|
@ -527,11 +527,11 @@ char *pfolder_lpath_lfile(psync_fileid_t localfileid,
|
|||
syncid = psync_get_number(row[1]);
|
||||
str = psync_get_lstring(row[2], &len);
|
||||
e = str_to_list_element(str, len);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_list_add_head(&folderlist, &e->list);
|
||||
rs = psync_add_local_path_to_list_by_localfolderid(&folderlist, localfolderid,
|
||||
syncid);
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
if (pdbg_unlikely(rs)) {
|
||||
psync_free_string_list(&folderlist);
|
||||
return PSYNC_INVALID_PATH;
|
||||
|
|
@ -612,22 +612,22 @@ pfolder_list_t *pfolder_remote_folders(psync_folderid_t folderid,
|
|||
char *tmp;
|
||||
int parentencrypted = 0;
|
||||
if (listtype & PLIST_FOLDERS) {
|
||||
res = psync_sql_query_rdlock("SELECT flags FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query_rdlock("SELECT flags FROM folder WHERE id=?");
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
if ((row = psql_fetch(res))) {
|
||||
parentencrypted =
|
||||
(psync_get_number(row[0]) & PSYNC_FOLDER_FLAG_ENCRYPTED) ? 1 : 0;
|
||||
} else {
|
||||
pdbg_logf(D_ERROR, "Can't find folder with id %lu", folderid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return NULL;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query_rdlock(
|
||||
psql_free(res);
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, permissions, name, userid, flags FROM folder WHERE "
|
||||
"parentfolderid=? ORDER BY name");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
while ((row = psql_fetch(res))) {
|
||||
entry.folder.folderid = psync_get_number(row[0]);
|
||||
perms = psync_get_number(row[1]);
|
||||
flags = psync_get_number(row[4]);
|
||||
|
|
@ -666,13 +666,13 @@ pfolder_list_t *pfolder_remote_folders(psync_folderid_t folderid,
|
|||
entry.isfolder = 1;
|
||||
folder_list_add(list, &entry);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
if (listtype & PLIST_FILES) {
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, size, name FROM file WHERE parentfolderid=? ORDER BY name");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
while ((row = psql_fetch(res))) {
|
||||
entry.file.fileid = psync_get_number(row[0]);
|
||||
entry.file.size = psync_get_number(row[1]);
|
||||
entry.name = psync_get_lstring(row[2], &namelen);
|
||||
|
|
@ -680,7 +680,7 @@ pfolder_list_t *pfolder_remote_folders(psync_folderid_t folderid,
|
|||
entry.isfolder = 0;
|
||||
folder_list_add(list, &entry);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
return folder_list_finalize(list);
|
||||
}
|
||||
|
|
@ -755,11 +755,11 @@ pentry_t *pfolder_stat(const char *remotepath) {
|
|||
}
|
||||
len++;
|
||||
olen -= len;
|
||||
res = psync_sql_query_rdlock("SELECT id, permissions, userid, flags FROM "
|
||||
res = psql_query_rdlock("SELECT id, permissions, userid, flags FROM "
|
||||
"folder WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, remotepath + len, olen);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, remotepath + len, olen);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
ret = (pentry_t *)malloc(sizeof(pentry_t) + olen + 1);
|
||||
ret->folder.folderid = row[0];
|
||||
ret->folder.cansyncup = ((row[1] & PSYNC_PERM_WRITE) == PSYNC_PERM_WRITE);
|
||||
|
|
@ -770,15 +770,15 @@ pentry_t *pfolder_stat(const char *remotepath) {
|
|||
ret->namelen = olen;
|
||||
ret->isfolder = 1;
|
||||
memcpy(ret + 1, remotepath + len, olen + 1);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query_rdlock(
|
||||
psql_free(res);
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, size FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, remotepath + len, olen);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, remotepath + len, olen);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
ret = (pentry_t *)malloc(sizeof(pentry_t) + olen + 1);
|
||||
ret->file.fileid = row[0];
|
||||
ret->file.size = row[1];
|
||||
|
|
@ -786,10 +786,10 @@ pentry_t *pfolder_stat(const char *remotepath) {
|
|||
ret->namelen = olen;
|
||||
ret->isfolder = 0;
|
||||
memcpy(ret + 1, remotepath + len, olen + 1);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -831,9 +831,9 @@ psync_folder_list_t *pfolder_sync_folders(char *syncTypes) {
|
|||
"WHERE folderid IS NOT NULL");
|
||||
}
|
||||
|
||||
res = psync_sql_query_rdlock(sql);
|
||||
res = psql_query_rdlock(sql);
|
||||
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
if (alloced == lastfolder) {
|
||||
alloced = (alloced + 32) * 2;
|
||||
folders = (psync_tmp_folder_t *)realloc(
|
||||
|
|
@ -862,7 +862,7 @@ psync_folder_list_t *pfolder_sync_folders(char *syncTypes) {
|
|||
folders[lastfolder].synctype = psync_get_number(row[3]);
|
||||
lastfolder++;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
l = offsetof(psync_folder_list_t, folders) +
|
||||
sizeof(psync_folder_t) * lastfolder;
|
||||
ret = (psync_folder_list_t *)malloc(l + strlens);
|
||||
|
|
|
|||
498
pclsync/pfs.c
498
pclsync/pfs.c
File diff suppressed because it is too large
Load Diff
|
|
@ -2022,9 +2022,9 @@ static void psync_fs_pause_task_by_name(const char *fn) {
|
|||
mul *= 256;
|
||||
}
|
||||
pdbg_logf(D_NOTICE, "pausing taskid %lu", (unsigned long)taskid);
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET status=1 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET status=1 WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void psync_fs_crypto_check_log(char *path, const char *fn) {
|
||||
|
|
|
|||
|
|
@ -125,18 +125,18 @@ PSYNC_NOINLINE void do_check_userid(uint64_t userid, uint64_t folderid,
|
|||
uint32_t *shareid) {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id FROM sharedfolder WHERE userid=? AND folderid=?");
|
||||
psync_sql_bind_uint(res, 1, userid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, userid);
|
||||
psql_bind_uint(res, 2, folderid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
*shareid = row[0];
|
||||
else
|
||||
pdbg_logf(D_WARNING,
|
||||
"came up to a folder %lu owned by userid %lu but can't find it in "
|
||||
"sharedfolder",
|
||||
(unsigned long)folderid, (unsigned long)userid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
static void check_userid(uint64_t userid, uint64_t folderid,
|
||||
|
|
@ -176,7 +176,7 @@ psync_fspath_t *psync_fsfolder_resolve_path(const char *path) {
|
|||
|
||||
if (*path == 0) {
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -186,31 +186,31 @@ psync_fspath_t *psync_fsfolder_resolve_path(const char *path) {
|
|||
len = sl - path;
|
||||
else {
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
|
||||
return ret_folder_data(cfolderid, path, permissions, flags, shareid);
|
||||
}
|
||||
|
||||
if (!res)
|
||||
res = psync_sql_query_rdlock("SELECT id, permissions, flags, userid FROM "
|
||||
res = psql_query_rdlock("SELECT id, permissions, flags, userid FROM "
|
||||
"folder WHERE parentfolderid=? AND name=?");
|
||||
else
|
||||
psync_sql_reset(res);
|
||||
psql_reset(res);
|
||||
|
||||
psync_sql_bind_int(res, 1, cfolderid);
|
||||
psql_bind_int(res, 1, cfolderid);
|
||||
|
||||
if (flags & PSYNC_FOLDER_FLAG_ENCRYPTED) {
|
||||
ename = get_encname_for_folder(cfolderid, path, len);
|
||||
if (!ename)
|
||||
break;
|
||||
elen = strlen(ename);
|
||||
psync_sql_bind_lstring(res, 2, ename, elen);
|
||||
psql_bind_lstr(res, 2, ename, elen);
|
||||
} else {
|
||||
psync_sql_bind_lstring(res, 2, path, len);
|
||||
psql_bind_lstr(res, 2, path, len);
|
||||
ename = (char *)path;
|
||||
elen = len;
|
||||
}
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
row = psql_fetch_int(res);
|
||||
folder = psync_fstask_get_folder_tasks_rdlocked(cfolderid);
|
||||
if (folder) {
|
||||
char *name = psync_strndup(ename, elen);
|
||||
|
|
@ -249,7 +249,7 @@ psync_fspath_t *psync_fsfolder_resolve_path(const char *path) {
|
|||
}
|
||||
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ psync_fsfolderid_t psync_fsfolderid_by_path(const char *path,
|
|||
path++;
|
||||
if (*path == 0) {
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (pflags)
|
||||
*pflags = flags;
|
||||
return cfolderid;
|
||||
|
|
@ -288,23 +288,23 @@ psync_fsfolderid_t psync_fsfolderid_by_path(const char *path,
|
|||
else
|
||||
len = strlen(path);
|
||||
if (!res)
|
||||
res = psync_sql_query_rdlock("SELECT id, flags, permissions FROM folder "
|
||||
res = psql_query_rdlock("SELECT id, flags, permissions FROM folder "
|
||||
"WHERE parentfolderid=? AND name=?");
|
||||
else
|
||||
psync_sql_reset(res);
|
||||
psync_sql_bind_int(res, 1, cfolderid);
|
||||
psql_reset(res);
|
||||
psql_bind_int(res, 1, cfolderid);
|
||||
if (flags & PSYNC_FOLDER_FLAG_ENCRYPTED) {
|
||||
ename = get_encname_for_folder(cfolderid, path, len);
|
||||
if (!ename)
|
||||
break;
|
||||
elen = strlen(ename);
|
||||
psync_sql_bind_lstring(res, 2, ename, elen);
|
||||
psql_bind_lstr(res, 2, ename, elen);
|
||||
} else {
|
||||
psync_sql_bind_lstring(res, 2, path, len);
|
||||
psql_bind_lstr(res, 2, path, len);
|
||||
ename = (char *)path;
|
||||
elen = len;
|
||||
}
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
row = psql_fetch_int(res);
|
||||
folder = psync_fstask_get_folder_tasks_rdlocked(cfolderid);
|
||||
if (folder) {
|
||||
char *name = psync_strndup(ename, elen);
|
||||
|
|
@ -334,7 +334,7 @@ psync_fsfolderid_t psync_fsfolderid_by_path(const char *path,
|
|||
path += len;
|
||||
}
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return PSYNC_INVALID_FSFOLDERID;
|
||||
}
|
||||
|
||||
|
|
@ -363,7 +363,7 @@ psync_fsfolderid_t psync_fsfolderidperm_by_path(const char *path,
|
|||
path++;
|
||||
if (*path == 0) {
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (pflags)
|
||||
*pflags = flags;
|
||||
return cfolderid;
|
||||
|
|
@ -374,23 +374,23 @@ psync_fsfolderid_t psync_fsfolderidperm_by_path(const char *path,
|
|||
else
|
||||
len = strlen(path);
|
||||
if (!res)
|
||||
res = psync_sql_query_rdlock("SELECT id, flags, permissions FROM folder "
|
||||
res = psql_query_rdlock("SELECT id, flags, permissions FROM folder "
|
||||
"WHERE parentfolderid=? AND name=?");
|
||||
else
|
||||
psync_sql_reset(res);
|
||||
psync_sql_bind_int(res, 1, cfolderid);
|
||||
psql_reset(res);
|
||||
psql_bind_int(res, 1, cfolderid);
|
||||
if (flags & PSYNC_FOLDER_FLAG_ENCRYPTED) {
|
||||
ename = get_encname_for_folder(cfolderid, path, len);
|
||||
if (!ename)
|
||||
break;
|
||||
elen = strlen(ename);
|
||||
psync_sql_bind_lstring(res, 2, ename, elen);
|
||||
psql_bind_lstr(res, 2, ename, elen);
|
||||
} else {
|
||||
psync_sql_bind_lstring(res, 2, path, len);
|
||||
psql_bind_lstr(res, 2, path, len);
|
||||
ename = (char *)path;
|
||||
elen = len;
|
||||
}
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
row = psql_fetch_int(res);
|
||||
folder = psync_fstask_get_folder_tasks_rdlocked(cfolderid);
|
||||
if (folder) {
|
||||
char *name = psync_strndup(ename, elen);
|
||||
|
|
@ -422,7 +422,7 @@ psync_fsfolderid_t psync_fsfolderidperm_by_path(const char *path,
|
|||
path += len;
|
||||
}
|
||||
if (res)
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return PSYNC_INVALID_FSFOLDERID;
|
||||
}
|
||||
|
||||
|
|
@ -436,25 +436,25 @@ uint32_t psync_fsfolderflags_by_id(psync_fsfolderid_t folderid,
|
|||
if (pperm)
|
||||
*pperm = 0;
|
||||
retry:
|
||||
if (psync_sql_trylock()) {
|
||||
if (psql_trylock()) {
|
||||
psys_sleep_milliseconds(1);
|
||||
goto retry;
|
||||
}
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT flags, permissions FROM folder WHERE id=?");
|
||||
psync_sql_bind_int(res, 1, folderid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_int(res, 1, folderid);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row) {
|
||||
pdbg_logf(D_NOTICE, "Error reading flags by file id!");
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_unlock();
|
||||
psql_free(res);
|
||||
psql_unlock();
|
||||
return 0;
|
||||
}
|
||||
if (pperm)
|
||||
*pperm = row[1];
|
||||
ret = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_unlock();
|
||||
psql_free(res);
|
||||
psql_unlock();
|
||||
return ret;
|
||||
}
|
||||
/*********************************************************************************************************************/
|
||||
|
|
@ -464,17 +464,17 @@ psync_fsfolderid_t psync_get_folderid(psync_fsfolderid_t parent_fid,
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT id FROM folder WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, parent_fid);
|
||||
psync_sql_bind_string(res, 2, name);
|
||||
psql_bind_uint(res, 1, parent_fid);
|
||||
psql_bind_str(res, 2, name);
|
||||
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
row = psql_fetch_int(res);
|
||||
|
||||
if (row) {
|
||||
folder_id = row[0];
|
||||
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
return folder_id;
|
||||
|
|
|
|||
|
|
@ -68,25 +68,25 @@ static inline int psync_crypto_to_error(const void *ptr) {
|
|||
psync_fstask_folder_t *
|
||||
psync_fstask_get_or_create_folder_tasks(psync_fsfolderid_t folderid) {
|
||||
psync_fstask_folder_t *folder;
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
folder = psync_fstask_get_or_create_folder_tasks_locked(folderid);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
return folder;
|
||||
}
|
||||
|
||||
psync_fstask_folder_t *
|
||||
psync_fstask_get_folder_tasks(psync_fsfolderid_t folderid) {
|
||||
psync_fstask_folder_t *folder;
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
folder = psync_fstask_get_folder_tasks_locked(folderid);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
return folder;
|
||||
}
|
||||
|
||||
void psync_fstask_release_folder_tasks(psync_fstask_folder_t *folder) {
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
psync_fstask_folder_t *
|
||||
|
|
@ -338,44 +338,44 @@ psync_fstask_find_creat_by_fileid(psync_fstask_folder_t *folder,
|
|||
|
||||
static void psync_fstask_depend(uint64_t taskid, uint64_t dependontaskid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT OR IGNORE INTO fstaskdepend "
|
||||
res = psql_prepare("INSERT OR IGNORE INTO fstaskdepend "
|
||||
"(fstaskid, dependfstaskid) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_bind_uint(res, 2, dependontaskid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_bind_uint(res, 2, dependontaskid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static uint32_t psync_fstask_depend_on_name(uint64_t taskid,
|
||||
psync_fsfolderid_t folderid,
|
||||
const char *name, size_t len) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT OR IGNORE INTO fstaskdepend (fstaskid, dependfstaskid) SELECT ?, "
|
||||
"id FROM fstask "
|
||||
"WHERE folderid=? AND text1=? AND id!=? AND status!=3");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_bind_int(res, 2, folderid);
|
||||
psync_sql_bind_lstring(res, 3, name, len);
|
||||
psync_sql_bind_uint(res, 4, taskid);
|
||||
psync_sql_run_free(res);
|
||||
return psync_sql_affected_rows();
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_bind_int(res, 2, folderid);
|
||||
psql_bind_lstr(res, 3, name, len);
|
||||
psql_bind_uint(res, 4, taskid);
|
||||
psql_run_free(res);
|
||||
return psql_affected();
|
||||
}
|
||||
|
||||
static uint32_t psync_fstask_depend_on_name2(uint64_t taskid, uint64_t taskid2,
|
||||
psync_fsfolderid_t folderid,
|
||||
const char *name, size_t len) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT OR IGNORE INTO fstaskdepend (fstaskid, dependfstaskid) SELECT ?, "
|
||||
"id FROM fstask "
|
||||
"WHERE folderid=? AND text1=? AND id NOT IN (?, ?) AND status!=3");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_bind_int(res, 2, folderid);
|
||||
psync_sql_bind_lstring(res, 3, name, len);
|
||||
psync_sql_bind_uint(res, 4, taskid);
|
||||
psync_sql_bind_uint(res, 5, taskid2);
|
||||
psync_sql_run_free(res);
|
||||
return psync_sql_affected_rows();
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_bind_int(res, 2, folderid);
|
||||
psql_bind_lstr(res, 3, name, len);
|
||||
psql_bind_uint(res, 4, taskid);
|
||||
psql_bind_uint(res, 5, taskid2);
|
||||
psql_run_free(res);
|
||||
return psql_affected();
|
||||
}
|
||||
|
||||
int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name,
|
||||
|
|
@ -392,12 +392,12 @@ int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name,
|
|||
folder = psync_fstask_get_or_create_folder_tasks_locked(folderid);
|
||||
len = strlen(name);
|
||||
if (folderid >= 0) {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id FROM folder WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, name, len);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, name, len);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
if (row && !psync_fstask_find_rmdir(folder, name, 0)) {
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -pdbg_return_const(EEXIST);
|
||||
|
|
@ -421,27 +421,27 @@ int psync_fstask_mkdir(psync_fsfolderid_t folderid, const char *name,
|
|||
}
|
||||
} else
|
||||
key = NULL;
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, sfolderid, text1, text2, "
|
||||
"int1) VALUES (" NTO_STR(PSYNC_FS_TASK_MKDIR) ", 0, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, folderid);
|
||||
psync_sql_bind_int(res, 2, folderid);
|
||||
psync_sql_bind_lstring(res, 3, name, len);
|
||||
psql_bind_int(res, 1, folderid);
|
||||
psql_bind_int(res, 2, folderid);
|
||||
psql_bind_lstr(res, 3, name, len);
|
||||
if (key)
|
||||
psync_sql_bind_lstring(res, 4, key, klen);
|
||||
psql_bind_lstr(res, 4, key, klen);
|
||||
else
|
||||
psync_sql_bind_null(res, 4);
|
||||
psync_sql_bind_uint(res, 5, ctime);
|
||||
psync_sql_run_free(res);
|
||||
taskid = psync_sql_insertid();
|
||||
psql_bind_null(res, 4);
|
||||
psql_bind_uint(res, 5, ctime);
|
||||
psql_run_free(res);
|
||||
taskid = psql_insertid();
|
||||
if (folderid < 0) {
|
||||
psync_fstask_depend(taskid, -folderid);
|
||||
depend = 1;
|
||||
} else
|
||||
depend = 0;
|
||||
depend += psync_fstask_depend_on_name(taskid, folderid, name, len);
|
||||
if (pdbg_unlikely(psync_sql_commit_transaction())) {
|
||||
if (pdbg_unlikely(psql_commit())) {
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -EIO;
|
||||
}
|
||||
|
|
@ -479,20 +479,20 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags,
|
|||
if (folder && (mk = psync_fstask_find_mkdir(folder, name, 0)))
|
||||
cfolderid = mk->folderid;
|
||||
else {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id, flags FROM folder WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, name, len);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, name, len);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row || (folder && psync_fstask_find_rmdir(folder, name, 0))) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -ENOENT;
|
||||
}
|
||||
cfolderid = row[0];
|
||||
if ((row[1] & PSYNC_FOLDER_FLAG_ENCRYPTED) &&
|
||||
!(parentflags & PSYNC_FOLDER_FLAG_ENCRYPTED)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (folder)
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
pdbg_logf(D_WARNING,
|
||||
|
|
@ -500,7 +500,7 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags,
|
|||
name, (unsigned long)folderid);
|
||||
return -EACCES;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
cfolder = psync_fstask_get_folder_tasks_locked(cfolderid);
|
||||
if (cfolder && (cfolder->creats || cfolder->mkdirs)) {
|
||||
|
|
@ -511,11 +511,11 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags,
|
|||
return -ENOTEMPTY;
|
||||
}
|
||||
if (cfolderid >= 0) {
|
||||
res = psync_sql_query("SELECT name FROM file WHERE parentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, cfolderid);
|
||||
while ((srow = psync_sql_fetch_rowstr(res)))
|
||||
res = psql_query("SELECT name FROM file WHERE parentfolderid=?");
|
||||
psql_bind_uint(res, 1, cfolderid);
|
||||
while ((srow = psql_fetch_str(res)))
|
||||
if (!cfolder || !psync_fstask_find_unlink(cfolder, srow[0], 0)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (cfolder)
|
||||
psync_fstask_release_folder_tasks_locked(cfolder);
|
||||
if (folder)
|
||||
|
|
@ -523,12 +523,12 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags,
|
|||
pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name);
|
||||
return -ENOTEMPTY;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query("SELECT name FROM folder WHERE parentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, cfolderid);
|
||||
while ((srow = psync_sql_fetch_rowstr(res)))
|
||||
psql_free(res);
|
||||
res = psql_query("SELECT name FROM folder WHERE parentfolderid=?");
|
||||
psql_bind_uint(res, 1, cfolderid);
|
||||
while ((srow = psql_fetch_str(res)))
|
||||
if (!cfolder || !psync_fstask_find_rmdir(cfolder, srow[0], 0)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (cfolder)
|
||||
psync_fstask_release_folder_tasks_locked(cfolder);
|
||||
if (folder)
|
||||
|
|
@ -536,7 +536,7 @@ int psync_fstask_can_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags,
|
|||
pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name);
|
||||
return -ENOTEMPTY;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
if (cfolder)
|
||||
psync_fstask_release_folder_tasks_locked(cfolder);
|
||||
|
|
@ -560,27 +560,27 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags,
|
|||
folder = psync_fstask_get_or_create_folder_tasks_locked(folderid);
|
||||
mk = psync_fstask_find_mkdir(folder, name, 0);
|
||||
if (mk == NULL) {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id, flags FROM folder WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, name, len);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, name, len);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row || psync_fstask_find_rmdir(folder, name, 0)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -ENOENT;
|
||||
}
|
||||
cfolderid = row[0];
|
||||
if ((row[1] & PSYNC_FOLDER_FLAG_ENCRYPTED) &&
|
||||
!(parentflags & PSYNC_FOLDER_FLAG_ENCRYPTED)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
pdbg_logf(D_WARNING,
|
||||
"attempt to delete encrypted folder %s in folderid %lu rejected",
|
||||
name, (unsigned long)folderid);
|
||||
return -EACCES;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
depend = 0;
|
||||
} else {
|
||||
depend = mk->taskid;
|
||||
|
|
@ -595,30 +595,30 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags,
|
|||
return -ENOTEMPTY;
|
||||
}
|
||||
if (cfolderid >= 0) {
|
||||
res = psync_sql_query("SELECT name FROM file WHERE parentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, cfolderid);
|
||||
while ((srow = psync_sql_fetch_rowstr(res)))
|
||||
res = psql_query("SELECT name FROM file WHERE parentfolderid=?");
|
||||
psql_bind_uint(res, 1, cfolderid);
|
||||
while ((srow = psql_fetch_str(res)))
|
||||
if (!cfolder || !psync_fstask_find_unlink(cfolder, srow[0], 0)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (cfolder)
|
||||
psync_fstask_release_folder_tasks_locked(cfolder);
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name);
|
||||
return -ENOTEMPTY;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query("SELECT name FROM folder WHERE parentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, cfolderid);
|
||||
while ((srow = psync_sql_fetch_rowstr(res)))
|
||||
psql_free(res);
|
||||
res = psql_query("SELECT name FROM folder WHERE parentfolderid=?");
|
||||
psql_bind_uint(res, 1, cfolderid);
|
||||
while ((srow = psql_fetch_str(res)))
|
||||
if (!cfolder || !psync_fstask_find_rmdir(cfolder, srow[0], 0)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (cfolder)
|
||||
psync_fstask_release_folder_tasks_locked(cfolder);
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
pdbg_logf(D_NOTICE, "returning ENOTEMPTY for folder name %s", name);
|
||||
return -ENOTEMPTY;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
if (mk) {
|
||||
ptree_del(&folder->mkdirs, &mk->tree);
|
||||
|
|
@ -626,26 +626,26 @@ int psync_fstask_rmdir(psync_fsfolderid_t folderid, uint32_t parentflags,
|
|||
}
|
||||
if (cfolder)
|
||||
psync_fstask_release_folder_tasks_locked(cfolder);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, sfolderid, text1) VALUES "
|
||||
"(" NTO_STR(PSYNC_FS_TASK_RMDIR) ", 0, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, folderid);
|
||||
psync_sql_bind_int(res, 2, cfolderid);
|
||||
psync_sql_bind_lstring(res, 3, name, len);
|
||||
psync_sql_run_free(res);
|
||||
taskid = psync_sql_insertid();
|
||||
psql_bind_int(res, 1, folderid);
|
||||
psql_bind_int(res, 2, cfolderid);
|
||||
psql_bind_lstr(res, 3, name, len);
|
||||
psql_run_free(res);
|
||||
taskid = psql_insertid();
|
||||
if (depend)
|
||||
psync_fstask_depend(taskid, depend);
|
||||
res = psync_sql_query("SELECT id FROM fstask WHERE folderid=?");
|
||||
psync_sql_bind_int(res, 1, cfolderid);
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
res = psql_query("SELECT id FROM fstask WHERE folderid=?");
|
||||
psql_bind_int(res, 1, cfolderid);
|
||||
while ((row = psql_fetch_int(res))) {
|
||||
psync_fstask_depend(taskid, row[0]);
|
||||
depend++;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_fstask_depend_on_name(taskid, folderid, name, len);
|
||||
if (pdbg_unlikely(psync_sql_commit_transaction())) {
|
||||
if (pdbg_unlikely(psql_commit())) {
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -EIO;
|
||||
}
|
||||
|
|
@ -676,25 +676,25 @@ psync_fstask_creat_t *psync_fstask_add_creat(psync_fstask_folder_t *folder,
|
|||
size_t len;
|
||||
pdbg_assert(fileid >= 0);
|
||||
len = strlen(name);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, fileid, sfolderid, text1, "
|
||||
"text2, int1) "
|
||||
"VALUES (" NTO_STR(PSYNC_FS_TASK_CREAT) ", 1, ?, ?, ?, ?, ?, 0)");
|
||||
psync_sql_bind_int(res, 1, folder->folderid);
|
||||
psync_sql_bind_int(res, 2, fileid);
|
||||
psync_sql_bind_int(res, 3, folder->folderid);
|
||||
psync_sql_bind_lstring(res, 4, name, len);
|
||||
psql_bind_int(res, 1, folder->folderid);
|
||||
psql_bind_int(res, 2, fileid);
|
||||
psql_bind_int(res, 3, folder->folderid);
|
||||
psql_bind_lstr(res, 4, name, len);
|
||||
if (encsymkey)
|
||||
psync_sql_bind_lstring(res, 5, encsymkey, encsymkeylen);
|
||||
psql_bind_lstr(res, 5, encsymkey, encsymkeylen);
|
||||
else
|
||||
psync_sql_bind_null(res, 5);
|
||||
psync_sql_run_free(res);
|
||||
taskid = psync_sql_insertid();
|
||||
psql_bind_null(res, 5);
|
||||
psql_run_free(res);
|
||||
taskid = psql_insertid();
|
||||
if (folder->folderid < 0)
|
||||
psync_fstask_depend(taskid, -folder->folderid);
|
||||
psync_fstask_depend_on_name(taskid, folder->folderid, name, len);
|
||||
if (pdbg_unlikely(psync_sql_commit_transaction()))
|
||||
if (pdbg_unlikely(psql_commit()))
|
||||
return NULL;
|
||||
len++;
|
||||
un = (psync_fstask_unlink_t *)malloc(
|
||||
|
|
@ -743,22 +743,22 @@ psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name,
|
|||
size_t len;
|
||||
len = strlen(name);
|
||||
pdbg_assert(fileid > 0);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, fileid, sfolderid, text1, "
|
||||
"text2, int1, int2) "
|
||||
"VALUES (" NTO_STR(PSYNC_FS_TASK_MODIFY) ", 1, ?, ?, ?, ?, ?, 0, ?)");
|
||||
psync_sql_bind_int(res, 1, folder->folderid);
|
||||
psync_sql_bind_int(res, 2, fileid);
|
||||
psync_sql_bind_int(res, 3, folder->folderid);
|
||||
psync_sql_bind_lstring(res, 4, name, len);
|
||||
psql_bind_int(res, 1, folder->folderid);
|
||||
psql_bind_int(res, 2, fileid);
|
||||
psql_bind_int(res, 3, folder->folderid);
|
||||
psql_bind_lstr(res, 4, name, len);
|
||||
if (encsymkey)
|
||||
psync_sql_bind_lstring(res, 5, encsymkey, encsymkeylen);
|
||||
psql_bind_lstr(res, 5, encsymkey, encsymkeylen);
|
||||
else
|
||||
psync_sql_bind_null(res, 5);
|
||||
psync_sql_bind_uint(res, 6, hash);
|
||||
psync_sql_run_free(res);
|
||||
taskid = psync_sql_insertid();
|
||||
psql_bind_null(res, 5);
|
||||
psql_bind_uint(res, 6, hash);
|
||||
psql_run_free(res);
|
||||
taskid = psql_insertid();
|
||||
if (folder->folderid < 0)
|
||||
psync_fstask_depend(taskid, -folder->folderid);
|
||||
psync_fstask_depend_on_name(taskid, folder->folderid, name, len);
|
||||
|
|
@ -769,7 +769,7 @@ psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name,
|
|||
free(task);
|
||||
folder->taskscnt--;
|
||||
}
|
||||
if (pdbg_unlikely(psync_sql_commit_transaction()))
|
||||
if (pdbg_unlikely(psql_commit()))
|
||||
return NULL;
|
||||
len++;
|
||||
un = (psync_fstask_unlink_t *)malloc(
|
||||
|
|
@ -796,26 +796,26 @@ psync_fstask_add_modified_file(psync_fstask_folder_t *folder, const char *name,
|
|||
int psync_fstask_set_mtime(psync_fileid_t fileid, uint64_t oldtm,
|
||||
uint64_t newtm, int is_ctime) {
|
||||
psync_sql_res *res;
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
if (is_ctime)
|
||||
res = psync_sql_prep_statement("UPDATE file SET ctime=? WHERE id=?");
|
||||
res = psql_prepare("UPDATE file SET ctime=? WHERE id=?");
|
||||
else
|
||||
res = psync_sql_prep_statement("UPDATE file SET mtime=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, newtm);
|
||||
psync_sql_bind_uint(res, 2, fileid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE file SET mtime=? WHERE id=?");
|
||||
psql_bind_uint(res, 1, newtm);
|
||||
psql_bind_uint(res, 2, fileid);
|
||||
psql_run_free(res);
|
||||
// folderid is ignored for these tasks
|
||||
res =
|
||||
psync_sql_prep_statement("INSERT INTO fstask (type, status, folderid, "
|
||||
psql_prepare("INSERT INTO fstask (type, status, folderid, "
|
||||
"fileid, int1, int2) VALUES (?, 0, 0, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1,
|
||||
psql_bind_int(res, 1,
|
||||
is_ctime ? PSYNC_FS_TASK_SET_FILE_CR
|
||||
: PSYNC_FS_TASK_SET_FILE_MOD);
|
||||
psync_sql_bind_int(res, 2, fileid);
|
||||
psync_sql_bind_int(res, 3, oldtm);
|
||||
psync_sql_bind_int(res, 4, newtm);
|
||||
psync_sql_run_free(res);
|
||||
if (pdbg_unlikely(psync_sql_commit_transaction()))
|
||||
psql_bind_int(res, 2, fileid);
|
||||
psql_bind_int(res, 3, oldtm);
|
||||
psql_bind_int(res, 4, newtm);
|
||||
psql_run_free(res);
|
||||
if (pdbg_unlikely(psql_commit()))
|
||||
return -EIO;
|
||||
psync_fsupload_wake();
|
||||
return 0;
|
||||
|
|
@ -834,7 +834,7 @@ int psync_fstask_add_local_creat_static(psync_fsfolderid_t folderid,
|
|||
int ret;
|
||||
ret = -1;
|
||||
len = strlen(name);
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
folder = psync_fstask_get_or_create_folder_tasks_locked(folderid);
|
||||
cr = psync_fstask_find_creat(folder, name, 0);
|
||||
if (cr) {
|
||||
|
|
@ -844,12 +844,12 @@ int psync_fstask_add_local_creat_static(psync_fsfolderid_t folderid,
|
|||
goto ex;
|
||||
}
|
||||
if (folderid >= 0 && !psync_fstask_find_unlink(folder, name, 0)) {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, name, len);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, name, len);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
if (row) {
|
||||
pdbg_logf(D_NOTICE,
|
||||
"not adding file %s to folderid %ld as it already exists in the "
|
||||
|
|
@ -886,7 +886,7 @@ int psync_fstask_add_local_creat_static(psync_fsfolderid_t folderid,
|
|||
ret = 0;
|
||||
ex:
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -920,14 +920,14 @@ static psync_fsfileid_t get_file_at_old_location(psync_fsfileid_t fileid) {
|
|||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
}
|
||||
res =
|
||||
psync_sql_query("SELECT id FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, rec->folderid);
|
||||
psync_sql_bind_string(res, 2, rec->name);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_query("SELECT id FROM file WHERE parentfolderid=? AND name=?");
|
||||
psql_bind_uint(res, 1, rec->folderid);
|
||||
psql_bind_str(res, 2, rec->name);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
ret = row[0];
|
||||
else
|
||||
ret = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
free(rec);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -940,13 +940,13 @@ void psync_fstask_stop_and_delete_file(psync_fsfileid_t fileid) {
|
|||
return;
|
||||
}
|
||||
psync_fsupload_stop_upload_locked(-fileid);
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET status=11 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, -fileid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare("UPDATE fstask SET status=11 WHERE id=?");
|
||||
psql_bind_uint(res, 1, -fileid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare(
|
||||
"UPDATE fstask SET status=11 WHERE fileid=? AND status!=10");
|
||||
psync_sql_bind_int(res, 1, fileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_int(res, 1, fileid);
|
||||
psql_run_free(res);
|
||||
psync_fs_mark_openfile_deleted(-fileid);
|
||||
}
|
||||
|
||||
|
|
@ -960,18 +960,18 @@ int psync_fstask_can_unlink(psync_fsfolderid_t folderid, const char *name) {
|
|||
if (folder && psync_fstask_find_creat(folder, name, 0))
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
else {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, name, len);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, name, len);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row || (folder && psync_fstask_find_unlink(folder, name, 0))) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (folder)
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -ENOENT;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (folder)
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
}
|
||||
|
|
@ -992,18 +992,18 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) {
|
|||
folder = psync_fstask_get_or_create_folder_tasks_locked(folderid);
|
||||
cr = psync_fstask_find_creat(folder, name, 0);
|
||||
if (cr == NULL) {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, name, len);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, name, len);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row || psync_fstask_find_unlink(folder, name, 0)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -ENOENT;
|
||||
}
|
||||
fileid = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
depend = 0;
|
||||
rfileid = 0;
|
||||
} else {
|
||||
|
|
@ -1030,32 +1030,32 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) {
|
|||
ppathstatus_drive_fldr_changed(folder->folderid);
|
||||
}
|
||||
revoffileid = get_file_at_old_location(fileid);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
if (fileid < 0)
|
||||
psync_fstask_stop_and_delete_file(fileid);
|
||||
if (revoffileid) {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, fileid, int1, text1, "
|
||||
"int2) VALUES "
|
||||
"(" NTO_STR(PSYNC_FS_TASK_UN_SET_REV) ", 0, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, folderid);
|
||||
psync_sql_bind_int(res, 2, revoffileid);
|
||||
psync_sql_bind_int(res, 3, fileid);
|
||||
psync_sql_bind_lstring(res, 4, name, len);
|
||||
psync_sql_bind_uint(res, 5, rfileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_int(res, 1, folderid);
|
||||
psql_bind_int(res, 2, revoffileid);
|
||||
psql_bind_int(res, 3, fileid);
|
||||
psql_bind_lstr(res, 4, name, len);
|
||||
psql_bind_uint(res, 5, rfileid);
|
||||
psql_run_free(res);
|
||||
} else {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, fileid, text1, int2) "
|
||||
"VALUES (" NTO_STR(PSYNC_FS_TASK_UNLINK) ", ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, fileid < 0 ? 11 : 0);
|
||||
psync_sql_bind_int(res, 2, folderid);
|
||||
psync_sql_bind_int(res, 3, fileid);
|
||||
psync_sql_bind_lstring(res, 4, name, len);
|
||||
psync_sql_bind_uint(res, 5, rfileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_int(res, 1, fileid < 0 ? 11 : 0);
|
||||
psql_bind_int(res, 2, folderid);
|
||||
psql_bind_int(res, 3, fileid);
|
||||
psql_bind_lstr(res, 4, name, len);
|
||||
psql_bind_uint(res, 5, rfileid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
taskid = psync_sql_insertid();
|
||||
taskid = psql_insertid();
|
||||
if (depend)
|
||||
psync_fstask_depend(taskid, depend);
|
||||
if (revoffileid < 0)
|
||||
|
|
@ -1063,7 +1063,7 @@ int psync_fstask_unlink(psync_fsfolderid_t folderid, const char *name) {
|
|||
if (fileid < 0 && -fileid != depend)
|
||||
psync_fstask_depend(taskid, -fileid);
|
||||
psync_fstask_depend_on_name(taskid, folderid, name, len);
|
||||
if (pdbg_unlikely(psync_sql_commit_transaction())) {
|
||||
if (pdbg_unlikely(psql_commit())) {
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -EIO;
|
||||
}
|
||||
|
|
@ -1124,30 +1124,30 @@ int psync_fstask_rename_file(psync_fsfileid_t fileid,
|
|||
rfileid = 0;
|
||||
pdbg_logf(D_NOTICE, "renaming file %ld from %ld/%s to %ld/%s", (long)fileid,
|
||||
(long)parentfolderid, name, (long)to_folderid, new_name);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, fileid, text1) VALUES "
|
||||
"(" NTO_STR(PSYNC_FS_TASK_RENFILE_FROM) ", 10, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, parentfolderid);
|
||||
psync_sql_bind_int(res, 2, fileid);
|
||||
psync_sql_bind_lstring(res, 3, name, nlen);
|
||||
psync_sql_run_free(res);
|
||||
ftaskid = psync_sql_insertid();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_bind_int(res, 1, parentfolderid);
|
||||
psql_bind_int(res, 2, fileid);
|
||||
psql_bind_lstr(res, 3, name, nlen);
|
||||
psql_run_free(res);
|
||||
ftaskid = psql_insertid();
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, fileid, text1, int1, int2) "
|
||||
"VALUES (" NTO_STR(PSYNC_FS_TASK_RENFILE_TO) ", 0, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, to_folderid);
|
||||
psync_sql_bind_int(res, 2, fileid);
|
||||
psync_sql_bind_lstring(res, 3, new_name, nnlen);
|
||||
psync_sql_bind_uint(res, 4, ftaskid);
|
||||
psync_sql_bind_uint(res, 5, rfileid);
|
||||
psync_sql_run_free(res);
|
||||
ttaskid = psync_sql_insertid();
|
||||
psql_bind_int(res, 1, to_folderid);
|
||||
psql_bind_int(res, 2, fileid);
|
||||
psql_bind_lstr(res, 3, new_name, nnlen);
|
||||
psql_bind_uint(res, 4, ftaskid);
|
||||
psql_bind_uint(res, 5, rfileid);
|
||||
psql_run_free(res);
|
||||
ttaskid = psql_insertid();
|
||||
if (fileid < 0) {
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET sfolderid=? WHERE id=?");
|
||||
psync_sql_bind_int(res, 1, to_folderid);
|
||||
psync_sql_bind_uint(res, 2, -fileid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET sfolderid=? WHERE id=?");
|
||||
psql_bind_int(res, 1, to_folderid);
|
||||
psql_bind_uint(res, 2, -fileid);
|
||||
psql_run_free(res);
|
||||
psync_fstask_depend(ttaskid, -fileid);
|
||||
}
|
||||
if (parentfolderid < 0)
|
||||
|
|
@ -1158,7 +1158,7 @@ int psync_fstask_rename_file(psync_fsfileid_t fileid,
|
|||
psync_fstask_depend_on_name(ttaskid, to_folderid, new_name, nnlen);
|
||||
if (cr)
|
||||
psync_fstask_depend(ttaskid, cr->taskid);
|
||||
if (pdbg_unlikely(psync_sql_commit_transaction())) {
|
||||
if (pdbg_unlikely(psql_commit())) {
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -EIO;
|
||||
}
|
||||
|
|
@ -1227,21 +1227,21 @@ static void fill_mkdir_data(psync_fsfolderid_t folderid,
|
|||
mkdir->ctime = mkdir->mtime = ptimer_time();
|
||||
mkdir->subdircnt = 0;
|
||||
if (folderid < 0) {
|
||||
res = psync_sql_query("SELECT int1 FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, -folderid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
res = psql_query("SELECT int1 FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, -folderid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
mkdir->ctime = mkdir->mtime = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
} else {
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT ctime, mtime, subdircnt FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
mkdir->ctime = row[0];
|
||||
mkdir->mtime = row[1];
|
||||
mkdir->subdircnt = row[2];
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1277,17 +1277,17 @@ static uint64_t psync_fstask_delete_folder_if_ex(psync_fsfolderid_t folderid,
|
|||
return 0;
|
||||
}
|
||||
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id FROM folder WHERE parentfolderid=? AND id != ? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_uint(res, 2, from_fid);
|
||||
psync_sql_bind_lstring(res, 3, name, len);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_uint(res, 2, from_fid);
|
||||
psql_bind_lstr(res, 3, name, len);
|
||||
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
cfolderid = row[0];
|
||||
}
|
||||
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
|
||||
if (cfolderid == 0) {
|
||||
pdbg_logf(D_NOTICE, "Skip creation of a delete task.");
|
||||
|
|
@ -1295,15 +1295,15 @@ static uint64_t psync_fstask_delete_folder_if_ex(psync_fsfolderid_t folderid,
|
|||
}
|
||||
}
|
||||
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, sfolderid, text1) VALUES "
|
||||
"(" NTO_STR(PSYNC_FS_TASK_RMDIR) ", 0, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, folderid);
|
||||
psync_sql_bind_int(res, 2, cfolderid);
|
||||
psync_sql_bind_lstring(res, 3, name, len);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_int(res, 1, folderid);
|
||||
psql_bind_int(res, 2, cfolderid);
|
||||
psql_bind_lstr(res, 3, name, len);
|
||||
psql_run_free(res);
|
||||
|
||||
taskid = psync_sql_insertid();
|
||||
taskid = psql_insertid();
|
||||
|
||||
if (depend)
|
||||
psync_fstask_depend(taskid, depend);
|
||||
|
|
@ -1333,35 +1333,35 @@ int psync_fstask_rename_folder(psync_fsfolderid_t folderid,
|
|||
nnlen = nlen;
|
||||
}
|
||||
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
|
||||
rmtask = psync_fstask_delete_folder_if_ex(to_folderid, new_name, folderid);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, sfolderid, text1) VALUES "
|
||||
"(" NTO_STR(PSYNC_FS_TASK_RENFOLDER_FROM) ", 10, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, parentfolderid);
|
||||
psync_sql_bind_int(res, 2, folderid);
|
||||
psync_sql_bind_lstring(res, 3, name, nlen);
|
||||
psync_sql_run_free(res);
|
||||
ftaskid = psync_sql_insertid();
|
||||
psql_bind_int(res, 1, parentfolderid);
|
||||
psql_bind_int(res, 2, folderid);
|
||||
psql_bind_lstr(res, 3, name, nlen);
|
||||
psql_run_free(res);
|
||||
ftaskid = psql_insertid();
|
||||
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO fstask (type, status, folderid, sfolderid, text1, int1, "
|
||||
"int2) VALUES (" NTO_STR(
|
||||
PSYNC_FS_TASK_RENFOLDER_TO) ", 0, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_int(res, 1, to_folderid);
|
||||
psync_sql_bind_int(res, 2, folderid);
|
||||
psync_sql_bind_lstring(res, 3, new_name, nnlen);
|
||||
psync_sql_bind_uint(res, 4, ftaskid);
|
||||
psync_sql_bind_uint(res, 5, targetflags);
|
||||
psync_sql_run_free(res);
|
||||
ttaskid = psync_sql_insertid();
|
||||
psql_bind_int(res, 1, to_folderid);
|
||||
psql_bind_int(res, 2, folderid);
|
||||
psql_bind_lstr(res, 3, new_name, nnlen);
|
||||
psql_bind_uint(res, 4, ftaskid);
|
||||
psql_bind_uint(res, 5, targetflags);
|
||||
psql_run_free(res);
|
||||
ttaskid = psql_insertid();
|
||||
|
||||
if (folderid < 0) {
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET sfolderid=? WHERE id=?");
|
||||
psync_sql_bind_int(res, 1, to_folderid);
|
||||
psync_sql_bind_int(res, 2, -folderid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET sfolderid=? WHERE id=?");
|
||||
psql_bind_int(res, 1, to_folderid);
|
||||
psql_bind_int(res, 2, -folderid);
|
||||
psql_run_free(res);
|
||||
psync_fstask_depend(ttaskid, -folderid);
|
||||
}
|
||||
|
||||
|
|
@ -1382,7 +1382,7 @@ int psync_fstask_rename_folder(psync_fsfolderid_t folderid,
|
|||
if (mk)
|
||||
psync_fstask_depend(ttaskid, mk->taskid);
|
||||
|
||||
if (pdbg_unlikely(psync_sql_commit_transaction())) {
|
||||
if (pdbg_unlikely(psql_commit())) {
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
return -EIO;
|
||||
}
|
||||
|
|
@ -1482,14 +1482,14 @@ void psync_fstask_folder_created(psync_folderid_t parentfolderid,
|
|||
D_NOTICE,
|
||||
"could not find mkdir (taskid %lu) for created folder %s in folder %lu",
|
||||
(unsigned long)taskid, name, (unsigned long)parentfolderid);
|
||||
res = psync_sql_query("SELECT sfolderid FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
res = psql_query("SELECT sfolderid FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
row = psql_fetch_int(res);
|
||||
if (pdbg_unlikely(!row))
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
else {
|
||||
sfolderid = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
folder = psync_fstask_get_folder_tasks_locked(sfolderid);
|
||||
if (folder) {
|
||||
mk = psync_fstask_find_mkdir_by_folderid(folder,
|
||||
|
|
@ -1544,15 +1544,15 @@ static void psync_fstask_look_for_creat_in_db(psync_folderid_t parentfolderid,
|
|||
pdbg_logf(D_NOTICE,
|
||||
"could not find creat (taskid %lu) for uploaded file %s in folder %lu",
|
||||
(unsigned long)taskid, name, (unsigned long)parentfolderid);
|
||||
res = psync_sql_query("SELECT sfolderid FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
res = psql_query("SELECT sfolderid FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
row = psql_fetch_int(res);
|
||||
if (pdbg_unlikely(!row)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return;
|
||||
}
|
||||
sfolderid = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
folder = psync_fstask_get_folder_tasks_locked(sfolderid);
|
||||
if (folder) {
|
||||
cr = psync_fstask_find_creat_by_fileid(folder, -(psync_fsfileid_t)taskid);
|
||||
|
|
@ -1669,9 +1669,9 @@ void psync_fstask_file_renamed(psync_folderid_t folderid, uint64_t taskid,
|
|||
if (cr)
|
||||
ppathstatus_drive_fldr_changed(folderid);
|
||||
}
|
||||
res = psync_sql_query("SELECT id, folderid, text1 FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, frtaskid);
|
||||
if (pdbg_likely(row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query("SELECT id, folderid, text1 FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, frtaskid);
|
||||
if (pdbg_likely(row = psql_fetch(res))) {
|
||||
folder = psync_fstask_get_folder_tasks_locked(psync_get_snumber(row[1]));
|
||||
if (folder) {
|
||||
un = psync_fstask_find_unlink(folder, psync_get_string(row[2]),
|
||||
|
|
@ -1684,16 +1684,16 @@ void psync_fstask_file_renamed(psync_folderid_t folderid, uint64_t taskid,
|
|||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM fstaskdepend WHERE dependfstaskid=?");
|
||||
psync_sql_bind_uint(res, 1, frtaskid);
|
||||
psync_sql_run_free(res);
|
||||
if (psync_sql_affected_rows())
|
||||
psql_bind_uint(res, 1, frtaskid);
|
||||
psql_run_free(res);
|
||||
if (psql_affected())
|
||||
psync_fsupload_wake();
|
||||
res = psync_sql_prep_statement("DELETE FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, frtaskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, frtaskid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_fstask_folder_renamed(psync_folderid_t parentfolderid,
|
||||
|
|
@ -1722,9 +1722,9 @@ void psync_fstask_folder_renamed(psync_folderid_t parentfolderid,
|
|||
if (mk)
|
||||
ppathstatus_drive_fldr_changed(parentfolderid);
|
||||
}
|
||||
res = psync_sql_query("SELECT id, folderid, text1 FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, frtaskid);
|
||||
if (pdbg_likely(row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query("SELECT id, folderid, text1 FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, frtaskid);
|
||||
if (pdbg_likely(row = psql_fetch(res))) {
|
||||
folder = psync_fstask_get_folder_tasks_locked(psync_get_snumber(row[1]));
|
||||
if (folder) {
|
||||
rm = psync_fstask_find_rmdir(folder, psync_get_string(row[2]),
|
||||
|
|
@ -1737,16 +1737,16 @@ void psync_fstask_folder_renamed(psync_folderid_t parentfolderid,
|
|||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM fstaskdepend WHERE dependfstaskid=?");
|
||||
psync_sql_bind_uint(res, 1, frtaskid);
|
||||
psync_sql_run_free(res);
|
||||
if (psync_sql_affected_rows())
|
||||
psql_bind_uint(res, 1, frtaskid);
|
||||
psql_run_free(res);
|
||||
if (psql_affected())
|
||||
psync_fsupload_wake();
|
||||
res = psync_sql_prep_statement("DELETE FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, frtaskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, frtaskid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void psync_init_task_mkdir(psync_variant_row row) {
|
||||
|
|
@ -2084,7 +2084,7 @@ static void psync_fstask_free_tree(psync_tree *tr) {
|
|||
void psync_fstask_clean() {
|
||||
psync_fstask_folder_t *folder;
|
||||
psync_tree *tr;
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
tr = ptree_get_first(folders);
|
||||
while (tr) {
|
||||
folder = ptree_element(tr, psync_fstask_folder_t, tree);
|
||||
|
|
@ -2104,7 +2104,7 @@ void psync_fstask_clean() {
|
|||
folder->taskscnt = 0;
|
||||
}
|
||||
}
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
void psync_fstask_add_banned_folder(psync_fsfolderid_t folderid,
|
||||
|
|
@ -2127,7 +2127,7 @@ void psync_fstask_add_banned_folder(psync_fsfolderid_t folderid,
|
|||
rm->taskid = 0;
|
||||
rm->folderid = 0;
|
||||
memcpy(rm->name, name, len);
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
folder = psync_fstask_get_or_create_folder_tasks_locked(folderid);
|
||||
psync_fstask_insert_into_tree(
|
||||
&folder->mkdirs, offsetof(psync_fstask_mkdir_t, name), &mk->tree);
|
||||
|
|
@ -2135,7 +2135,7 @@ void psync_fstask_add_banned_folder(psync_fsfolderid_t folderid,
|
|||
&folder->rmdirs, offsetof(psync_fstask_rmdir_t, name), &rm->tree);
|
||||
folder->taskscnt += 2;
|
||||
psync_fstask_release_folder_tasks_locked(folder);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
void psync_fstask_add_banned_folders() {
|
||||
|
|
@ -2146,15 +2146,15 @@ void psync_fstask_init() {
|
|||
unsigned long tp;
|
||||
psync_sql_res *res;
|
||||
psync_variant_row row;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE fstask SET status=0 WHERE status IN (1, 2)");
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET status=11 WHERE status=12");
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_query(
|
||||
psql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET status=11 WHERE status=12");
|
||||
psql_run_free(res);
|
||||
res = psql_query(
|
||||
"SELECT id, type, folderid, fileid, text1, text2, int1, int2, sfolderid "
|
||||
"FROM fstask WHERE status NOT IN (3) ORDER BY id");
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
tp = psync_get_number(row[1]);
|
||||
if (!tp || tp >= ARRAY_SIZE(psync_init_task_func)) {
|
||||
pdbg_logf(D_BUG, "invalid fstask type %lu", (long unsigned)tp);
|
||||
|
|
@ -2162,7 +2162,7 @@ void psync_fstask_init() {
|
|||
}
|
||||
psync_init_task_func[tp](row);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_fsupload_init();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,15 +128,15 @@ static void handle_mkdir_api_error(uint64_t result, fsupload_task_t *task) {
|
|||
case 2003: /* access denied */
|
||||
case 2075: /* not a member of a business account */
|
||||
case 2344: /* can't create folders in backup folder */
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET folderid=0 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, task->id);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET folderid=0 WHERE id=?");
|
||||
psql_bind_uint(res, 1, task->id);
|
||||
psql_run_free(res);
|
||||
break;
|
||||
case 2001: /* invalid name */
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE fstask SET text1=\"Invalid Name Requested\" WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, task->id);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, task->id);
|
||||
psql_run_free(res);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -165,11 +165,11 @@ static int psync_process_task_mkdir(fsupload_task_t *task) {
|
|||
enckey = psync_base64_decode((const unsigned char *)task->text2,
|
||||
strlen(task->text2), &enckeylen);
|
||||
if (pdbg_likely(enckey)) {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO cryptofolderkey (folderid, enckey) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_blob(res, 2, (char *)enckey, enckeylen);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_blob(res, 2, (char *)enckey, enckeylen);
|
||||
psql_run_free(res);
|
||||
free(enckey);
|
||||
}
|
||||
}
|
||||
|
|
@ -300,10 +300,10 @@ static int clean_uploads_for_task(psock_t *api, psync_uploadid_t taskid) {
|
|||
uint32_t i;
|
||||
int ret;
|
||||
ret = 0;
|
||||
sql = psync_sql_query_rdlock(
|
||||
sql = psql_query_rdlock(
|
||||
"SELECT uploadid FROM fstaskupload WHERE fstaskid=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
fr = psync_sql_fetchall_int(sql);
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
fr = psql_fetchall_int(sql);
|
||||
for (i = 0; i < fr->rows; i++) {
|
||||
binparam params[] = {PAPI_STR("auth", psync_my_auth),
|
||||
PAPI_NUM("uploadid", psync_get_result_cell(fr, i, 0))};
|
||||
|
|
@ -314,9 +314,9 @@ static int clean_uploads_for_task(psock_t *api, psync_uploadid_t taskid) {
|
|||
} else
|
||||
free(res);
|
||||
}
|
||||
sql = psync_sql_prep_statement("DELETE FROM fstaskupload WHERE fstaskid=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_run_free(sql);
|
||||
sql = psql_prepare("DELETE FROM fstaskupload WHERE fstaskid=?");
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_run_free(sql);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -359,32 +359,32 @@ static int handle_upload_api_error_taskid(uint64_t result, uint64_t taskid) {
|
|||
case 2003: /* access denied */
|
||||
case 2075: /* are not a member of a business account */
|
||||
case 2346: /* backup folder */
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET folderid=0 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET folderid=0 WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
psync_fsupload_wake();
|
||||
return -1;
|
||||
case 2001: /* invalid filename */
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE fstask SET text1=\"Invalid Name Requested\" WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
psync_fsupload_wake();
|
||||
return -1;
|
||||
case 2008: { /* overquota */
|
||||
int locked = psync_sql_islocked();
|
||||
int locked = psql_locked();
|
||||
if (locked)
|
||||
psync_sql_commit_transaction();
|
||||
pdbg_assert(!psync_sql_islocked());
|
||||
psql_commit();
|
||||
pdbg_assert(!psql_locked());
|
||||
psys_sleep_milliseconds(PSYNC_SLEEP_ON_DISK_FULL);
|
||||
if (locked)
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
return -1;
|
||||
}
|
||||
case 2124: /* crypto expired */
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET status=1 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET status=1 WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
return -1;
|
||||
default:
|
||||
return -1;
|
||||
|
|
@ -405,12 +405,12 @@ static void set_key_for_fileid(psync_fileid_t fileid, uint64_t hash,
|
|||
enckey =
|
||||
psync_base64_decode((const unsigned char *)key, strlen(key), &enckeylen);
|
||||
if (pdbg_likely(enckey)) {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO cryptofilekey (fileid, hash, enckey) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
psync_sql_bind_uint(res, 2, hash);
|
||||
psync_sql_bind_blob(res, 3, (char *)enckey, enckeylen);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
psql_bind_uint(res, 2, hash);
|
||||
psql_bind_blob(res, 3, (char *)enckey, enckeylen);
|
||||
psql_run_free(res);
|
||||
free(enckey);
|
||||
}
|
||||
psync_get_string_id(buff, "DKEY", fileid);
|
||||
|
|
@ -429,23 +429,23 @@ static int save_meta(const binresult *meta, psync_folderid_t folderid,
|
|||
hash = papi_find_result2(meta, "hash", PARAM_NUM)->num;
|
||||
size = papi_find_result2(meta, "size", PARAM_NUM)->num;
|
||||
deleted = 0;
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
if (psync_fs_update_openfile(
|
||||
taskid, writeid, fileid, hash, size,
|
||||
papi_find_result2(meta, "created", PARAM_NUM)->num)) {
|
||||
sql = psync_sql_query_nolock("SELECT status FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
row = psync_sql_fetch_rowint(sql);
|
||||
sql = psql_query_nolock("SELECT status FROM fstask WHERE id=?");
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
row = psql_fetch_int(sql);
|
||||
if (row && row[0] == 11) {
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
deleted = 1;
|
||||
pdbg_logf(D_NOTICE,
|
||||
"detected cancel of upload of %s too late, processing normally, "
|
||||
"delete will come",
|
||||
name);
|
||||
} else {
|
||||
psync_sql_free_result(sql);
|
||||
psync_sql_rollback_transaction();
|
||||
psql_free(sql);
|
||||
psql_rollback();
|
||||
pdbg_logf(D_NOTICE, "upload of %s task %lu cancelled due to writeid mismatch",
|
||||
name, (unsigned long)taskid);
|
||||
return -1;
|
||||
|
|
@ -465,40 +465,40 @@ static int save_meta(const binresult *meta, psync_folderid_t folderid,
|
|||
}
|
||||
if (key)
|
||||
set_key_for_fileid(fileid, hash, key);
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"DELETE FROM fstaskdepend WHERE dependfstaskid=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_run_free(sql);
|
||||
if (psync_sql_affected_rows())
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_run_free(sql);
|
||||
if (psql_affected())
|
||||
psync_fsupload_wake();
|
||||
sql = psync_sql_prep_statement("DELETE FROM fstaskupload WHERE fstaskid=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_run_free(sql);
|
||||
sql = psync_sql_prep_statement("UPDATE fstask SET fileid=? WHERE fileid=?");
|
||||
psync_sql_bind_uint(sql, 1, fileid);
|
||||
psync_sql_bind_int(sql, 2, -(psync_fsfileid_t)taskid);
|
||||
psync_sql_run_free(sql);
|
||||
sql = psql_prepare("DELETE FROM fstaskupload WHERE fstaskid=?");
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_run_free(sql);
|
||||
sql = psql_prepare("UPDATE fstask SET fileid=? WHERE fileid=?");
|
||||
psql_bind_uint(sql, 1, fileid);
|
||||
psql_bind_int(sql, 2, -(psync_fsfileid_t)taskid);
|
||||
psql_run_free(sql);
|
||||
if (deleted) {
|
||||
sql = psync_sql_prep_statement("DELETE FROM fstask WHERE id=? AND int1=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_bind_uint(sql, 2, writeid);
|
||||
psync_sql_run_free(sql);
|
||||
sql = psql_prepare("DELETE FROM fstask WHERE id=? AND int1=?");
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_bind_uint(sql, 2, writeid);
|
||||
psql_run_free(sql);
|
||||
} else {
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"UPDATE fstask SET status=3 WHERE id=? AND int1=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_bind_uint(sql, 2, writeid);
|
||||
psync_sql_run_free(sql);
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_bind_uint(sql, 2, writeid);
|
||||
psql_run_free(sql);
|
||||
}
|
||||
if (!psync_sql_affected_rows()) {
|
||||
if (!psql_affected()) {
|
||||
pdbg_logf(D_BUG,
|
||||
"upload of %s cancelled due to writeid mismatch, writeid %lu, "
|
||||
"psync_fs_update_openfile should have catched that",
|
||||
name, (long unsigned)writeid);
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
return -1;
|
||||
}
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
pdbg_logf(D_NOTICE, "file %lu/%s uploaded (mtime=%lu, size=%lu)",
|
||||
(unsigned long)folderid, name,
|
||||
(unsigned long)papi_find_result2(meta, "modified", PARAM_NUM)->num,
|
||||
|
|
@ -585,21 +585,21 @@ static int large_upload_save(psock_t *api, uint64_t uploadid,
|
|||
static void perm_fail_upload_task(uint64_t taskid) {
|
||||
psync_sql_res *sql;
|
||||
pdbg_logf(D_WARNING, "failed task %lu", (unsigned long)taskid);
|
||||
psync_sql_start_transaction();
|
||||
sql = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
sql = psql_prepare(
|
||||
"DELETE FROM fstaskdepend WHERE dependfstaskid=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_run_free(sql);
|
||||
if (psync_sql_affected_rows())
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_run_free(sql);
|
||||
if (psql_affected())
|
||||
psync_fsupload_wake();
|
||||
sql = psync_sql_prep_statement("DELETE FROM fstask WHERE fileid=?");
|
||||
psync_sql_bind_int(sql, 1, -(psync_fsfileid_t)taskid);
|
||||
psync_sql_run_free(sql);
|
||||
sql = psync_sql_prep_statement("DELETE FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_run_free(sql);
|
||||
sql = psql_prepare("DELETE FROM fstask WHERE fileid=?");
|
||||
psql_bind_int(sql, 1, -(psync_fsfileid_t)taskid);
|
||||
psql_run_free(sql);
|
||||
sql = psql_prepare("DELETE FROM fstask WHERE id=?");
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_run_free(sql);
|
||||
psync_fs_task_deleted(taskid);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
pstatus_upload_recalc_async();
|
||||
}
|
||||
|
||||
|
|
@ -775,11 +775,11 @@ static int large_upload_creat(uint64_t taskid, psync_folderid_t folderid,
|
|||
}
|
||||
uploadid = papi_find_result2(res, "uploadid", PARAM_NUM)->num;
|
||||
free(res);
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"INSERT INTO fstaskupload (fstaskid, uploadid) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_bind_uint(sql, 2, uploadid);
|
||||
psync_sql_run_free(sql);
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_bind_uint(sql, 2, uploadid);
|
||||
psql_run_free(sql);
|
||||
}
|
||||
fd = pfile_open(filename, O_RDONLY, 0);
|
||||
if (pdbg_unlikely(fd == INVALID_HANDLE_VALUE))
|
||||
|
|
@ -1029,11 +1029,11 @@ int upload_modify(uint64_t taskid, psync_folderid_t folderid, const char *name,
|
|||
}
|
||||
uploadid = papi_find_result2(res, "uploadid", PARAM_NUM)->num;
|
||||
free(res);
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"INSERT INTO fstaskupload (fstaskid, uploadid) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(sql, 1, taskid);
|
||||
psync_sql_bind_uint(sql, 2, uploadid);
|
||||
psync_sql_run_free(sql);
|
||||
psql_bind_uint(sql, 1, taskid);
|
||||
psql_bind_uint(sql, 2, uploadid);
|
||||
psql_run_free(sql);
|
||||
fd = pfile_open(filename, O_RDONLY, 0);
|
||||
if (unlikely(fd == INVALID_HANDLE_VALUE)) {
|
||||
err = errno;
|
||||
|
|
@ -1146,15 +1146,15 @@ static void large_upload() {
|
|||
pdbg_logf(D_NOTICE, "started");
|
||||
while (1) {
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
res = psync_sql_query("SELECT id, type, folderid, text1, text2, int1, "
|
||||
res = psql_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(
|
||||
PSYNC_FS_TASK_MODIFY) ") ORDER BY id LIMIT 1");
|
||||
row = psync_sql_fetch_row(res);
|
||||
row = psql_fetch(res);
|
||||
if (!row) {
|
||||
large_upload_running = 0;
|
||||
current_upload_taskid = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
break;
|
||||
}
|
||||
taskid = psync_get_number(row[0]);
|
||||
|
|
@ -1177,7 +1177,7 @@ static void large_upload() {
|
|||
memcpy(name, cname, len);
|
||||
current_upload_taskid = taskid;
|
||||
stop_current_upload = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_binhex(fileidhex, &taskid, sizeof(psync_fsfileid_t));
|
||||
fileidhex[sizeof(psync_fsfileid_t)] = 'd';
|
||||
fileidhex[sizeof(psync_fsfileid_t) + 1] = 0;
|
||||
|
|
@ -1185,14 +1185,14 @@ static void large_upload() {
|
|||
filename = psync_strcat(cname, "/", fileidhex, NULL);
|
||||
fileidhex[sizeof(psync_fsfileid_t)] = 'i';
|
||||
indexname = psync_strcat(cname, "/", fileidhex, NULL);
|
||||
res = psync_sql_query_rdlock("SELECT uploadid FROM fstaskupload WHERE "
|
||||
res = psql_query_rdlock("SELECT uploadid FROM fstaskupload WHERE "
|
||||
"fstaskid=? ORDER BY uploadid DESC LIMIT 1");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
if ((urow = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
if ((urow = psql_fetch_int(res)))
|
||||
uploadid = urow[0];
|
||||
else
|
||||
uploadid = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pupload_inc();
|
||||
if (type == PSYNC_FS_TASK_CREAT)
|
||||
ret = large_upload_creat(taskid, folderid, name, filename, uploadid,
|
||||
|
|
@ -1204,22 +1204,22 @@ static void large_upload() {
|
|||
ret = 0;
|
||||
pdbg_logf(D_BUG, "wrong type %lu for task %lu", (unsigned long)type,
|
||||
(unsigned long)taskid);
|
||||
res = psync_sql_prep_statement("DELETE FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
pstatus_upload_recalc_async();
|
||||
}
|
||||
pupload_dec();
|
||||
if (ret) {
|
||||
res = psync_sql_query_rdlock("SELECT type FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
if ((urow = psync_sql_fetch_rowint(res)))
|
||||
res = psql_query_rdlock("SELECT type FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
if ((urow = psql_fetch_int(res)))
|
||||
uploadid = urow[0];
|
||||
else
|
||||
uploadid = 2;
|
||||
if (uploadid != 2)
|
||||
current_upload_taskid = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (uploadid != 2)
|
||||
psync_fsupload_wake();
|
||||
psys_sleep_milliseconds(PSYNC_SLEEP_ON_FAILED_UPLOAD);
|
||||
|
|
@ -1234,15 +1234,15 @@ static void large_upload() {
|
|||
|
||||
static int psync_sent_task_creat_upload_large(fsupload_task_t *task) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE fstask SET status=2 WHERE id=? AND status=0");
|
||||
psync_sql_bind_uint(res, 1, task->id);
|
||||
psql_bind_uint(res, 1, task->id);
|
||||
// psync_fs_uploading_openfile(task->id);
|
||||
if (!large_upload_running) {
|
||||
large_upload_running = 1;
|
||||
prun_thread("large file fs upload", large_upload);
|
||||
}
|
||||
psync_sql_run_free(res);
|
||||
psql_run_free(res);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1250,10 +1250,10 @@ void psync_fsupload_stop_upload_locked(uint64_t taskid) {
|
|||
psync_sql_res *res;
|
||||
if (current_upload_taskid == taskid)
|
||||
stop_current_upload = 1;
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET status=1 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
pdbg_assertw(psync_sql_affected_rows());
|
||||
res = psql_prepare("UPDATE fstask SET status=1 WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
pdbg_assertw(psql_affected());
|
||||
}
|
||||
|
||||
int psync_fsupload_in_current_small_uploads_batch_locked(uint64_t taskid) {
|
||||
|
|
@ -1362,9 +1362,9 @@ static int psync_process_task_creat(fsupload_task_t *task) {
|
|||
task->int2 = fileid;
|
||||
pdbg_logf(D_NOTICE, "file %lu/%s uploaded", (unsigned long)task->folderid,
|
||||
task->text1);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
ppagecache_creat(task->id, hash, 1);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1468,13 +1468,13 @@ static int psync_process_task_set_fl_mod(fsupload_task_t *task) {
|
|||
if (result)
|
||||
return 0;
|
||||
meta = papi_find_result2(task->res, "metadata", PARAM_HASH);
|
||||
res = psync_sql_prep_statement("UPDATE file SET ctime=?, mtime=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1,
|
||||
res = psql_prepare("UPDATE file SET ctime=?, mtime=? WHERE id=?");
|
||||
psql_bind_uint(res, 1,
|
||||
papi_find_result2(meta, "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(res, 2,
|
||||
psql_bind_uint(res, 2,
|
||||
papi_find_result2(meta, "modified", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(res, 3, task->fileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 3, task->fileid);
|
||||
psql_run_free(res);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1508,10 +1508,10 @@ static int psync_send_task_rename_folder(psock_t *api,
|
|||
psync_variant_row row;
|
||||
char *end;
|
||||
size_t size;
|
||||
res=psync_sql_query("SELECT id, type, folderid, fileid, text1, text2, int1,
|
||||
int2, sfolderid FROM fstask WHERE id=?"); psync_sql_bind_uint(res, 1, id);
|
||||
res=psql_query("SELECT id, type, folderid, fileid, text1, text2, int1,
|
||||
int2, sfolderid FROM fstask WHERE id=?"); psql_bind_uint(res, 1, id);
|
||||
task=NULL;
|
||||
if ((row=psync_sql_fetch_row(res))){
|
||||
if ((row=psql_fetch(res))){
|
||||
size=sizeof(fsupload_task_t);
|
||||
if (row[4].type==PSYNC_TSTRING)
|
||||
size+=row[4].length+1;
|
||||
|
|
@ -1541,7 +1541,7 @@ int2, sfolderid FROM fstask WHERE id=?"); psync_sql_bind_uint(res, 1, id);
|
|||
task->int1=psync_get_snumber_or_null(row[6]);
|
||||
task->int2=psync_get_snumber_or_null(row[7]);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return task;
|
||||
}*/
|
||||
|
||||
|
|
@ -1601,10 +1601,10 @@ static void change_folder_name(fsupload_task_t *task) {
|
|||
if (!nn) {
|
||||
nn = psync_strcat(task->text1, "(1)", NULL);
|
||||
}
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET text1=? WHERE id=?");
|
||||
psync_sql_bind_string(res, 1, nn);
|
||||
psync_sql_bind_uint(res, 2, task->id);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET text1=? WHERE id=?");
|
||||
psql_bind_str(res, 1, nn);
|
||||
psql_bind_uint(res, 2, task->id);
|
||||
psql_run_free(res);
|
||||
pdbg_logf(D_NOTICE, "changed target name of task %lu from %s to %s",
|
||||
(unsigned long)task->id, task->text1, nn);
|
||||
free(nn);
|
||||
|
|
@ -1698,22 +1698,22 @@ static int psync_cancel_task_creat(fsupload_task_t *task) {
|
|||
psync_fileid_t fileid;
|
||||
psync_delete_write_cache_file(task->id, 0);
|
||||
psync_fstask_file_created(task->folderid, task->id, task->text1, 0);
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT fileid FROM fstaskfileid WHERE fstaskid=?");
|
||||
psync_sql_bind_uint(res, 1, task->id);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, task->id);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
fileid = row[0];
|
||||
else
|
||||
fileid = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (fileid) {
|
||||
pdbg_logf(D_NOTICE,
|
||||
"cancelled creat task %lu for file %s, changed to fileid %lu",
|
||||
(unsigned long)task->id, task->text1, (unsigned long)fileid);
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET fileid=? WHERE fileid=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
psync_sql_bind_int(res, 2, -(psync_fsfileid_t)task->id);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET fileid=? WHERE fileid=?");
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
psql_bind_int(res, 2, -(psync_fsfileid_t)task->id);
|
||||
psql_run_free(res);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1729,10 +1729,10 @@ static int psync_cancel_task_modify(fsupload_task_t *task) {
|
|||
psync_sql_res *res;
|
||||
psync_delete_write_cache_file(task->id, 1);
|
||||
psync_fstask_file_modified(task->folderid, task->id, task->text1, 0);
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET fileid=? WHERE fileid=?");
|
||||
psync_sql_bind_uint(res, 1, task->fileid);
|
||||
psync_sql_bind_int(res, 2, -(psync_fsfileid_t)task->id);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET fileid=? WHERE fileid=?");
|
||||
psql_bind_uint(res, 1, task->fileid);
|
||||
psql_bind_int(res, 2, -(psync_fsfileid_t)task->id);
|
||||
psql_run_free(res);
|
||||
pdbg_logf(D_NOTICE,
|
||||
"cancelled modify task %lu for file %s, changed to fileid %lu",
|
||||
(unsigned long)task->id, task->text1, (unsigned long)task->fileid);
|
||||
|
|
@ -1743,10 +1743,10 @@ static int psync_cancel_task_unlink(fsupload_task_t *task) {
|
|||
psync_sql_res *res;
|
||||
// psync_uint_row row;
|
||||
if (pdbg_unlikely((psync_fsfileid_t)task->fileid > 0)) {
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET status=0 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, task->id);
|
||||
res = psql_prepare("UPDATE fstask SET status=0 WHERE id=?");
|
||||
psql_bind_uint(res, 1, task->id);
|
||||
upload_wakes++;
|
||||
psync_sql_run_free(res);
|
||||
psql_run_free(res);
|
||||
return -1;
|
||||
}
|
||||
if (task->int2) {
|
||||
|
|
@ -1754,11 +1754,11 @@ static int psync_cancel_task_unlink(fsupload_task_t *task) {
|
|||
"requested cancel of delete of a modified file, deleting fileid %ld "
|
||||
"instead for file %s",
|
||||
(long)task->int2, task->text1);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE fstask SET status=0, fileid=int2 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, task->id);
|
||||
psql_bind_uint(res, 1, task->id);
|
||||
upload_wakes++;
|
||||
psync_sql_run_free(res);
|
||||
psql_run_free(res);
|
||||
return -1;
|
||||
}
|
||||
psync_fstask_file_deleted(task->folderid, task->id, task->text1);
|
||||
|
|
@ -1772,12 +1772,12 @@ static int psync_cancel_task_unlink_set_rev(fsupload_task_t *task) {
|
|||
"converting cancelled unlink_set_rev task %lu to a normal unlink "
|
||||
"task for file %s",
|
||||
(unsigned long)task->id, task->text1);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE fstask SET fileid=int2, status=0, type=" NTO_STR(
|
||||
PSYNC_FS_TASK_UNLINK) " WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, task->id);
|
||||
psql_bind_uint(res, 1, task->id);
|
||||
upload_wakes++;
|
||||
psync_sql_run_free(res);
|
||||
psql_run_free(res);
|
||||
return -1;
|
||||
}
|
||||
psync_fstask_file_deleted(task->folderid, task->id, task->text1);
|
||||
|
|
@ -1835,55 +1835,55 @@ static psync_cancel_task_ptr psync_cancel_task_func[] = {
|
|||
|
||||
static void pr_del_dep(uint64_t taskid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"DELETE FROM fstaskdepend WHERE dependfstaskid=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
if (psync_sql_affected_rows())
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
if (psql_affected())
|
||||
upload_wakes++;
|
||||
}
|
||||
|
||||
static void pr_del_task(uint64_t taskid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("DELETE FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
/*static void pr_set_task_status3(uint64_t taskid){
|
||||
psync_sql_res *res;
|
||||
res=psync_sql_prep_statement("UPDATE fstask SET status=3 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res=psql_prepare("UPDATE fstask SET status=3 WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
}*/
|
||||
|
||||
static void pr_update_folderid(psync_folderid_t newfolderid,
|
||||
psync_fsfolderid_t oldfolderid) {
|
||||
psync_sql_res *res;
|
||||
res =
|
||||
psync_sql_prep_statement("UPDATE fstask SET folderid=? WHERE folderid=?");
|
||||
psync_sql_bind_uint(res, 1, newfolderid);
|
||||
psync_sql_bind_int(res, 2, oldfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_prepare("UPDATE fstask SET folderid=? WHERE folderid=?");
|
||||
psql_bind_uint(res, 1, newfolderid);
|
||||
psql_bind_int(res, 2, oldfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void pr_update_sfolderid(psync_folderid_t newfolderid,
|
||||
psync_fsfolderid_t oldfolderid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE fstask SET sfolderid=? WHERE sfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, newfolderid);
|
||||
psync_sql_bind_int(res, 2, oldfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, newfolderid);
|
||||
psql_bind_int(res, 2, oldfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void pr_update_fileid(psync_fileid_t newfileid,
|
||||
psync_fsfileid_t oldfileid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("UPDATE fstask SET fileid=? WHERE fileid=?");
|
||||
psync_sql_bind_uint(res, 1, newfileid);
|
||||
psync_sql_bind_int(res, 2, oldfileid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE fstask SET fileid=? WHERE fileid=?");
|
||||
psql_bind_uint(res, 1, newfileid);
|
||||
psql_bind_int(res, 2, oldfileid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void psync_fsupload_process_tasks(psync_list *tasks) {
|
||||
|
|
@ -1892,7 +1892,7 @@ static void psync_fsupload_process_tasks(psync_list *tasks) {
|
|||
creats = 0;
|
||||
cancels = 0;
|
||||
dels = 0;
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
psync_list_for_each_element(task, tasks, fsupload_task_t, list) {
|
||||
if (task->ccreat)
|
||||
creats++;
|
||||
|
|
@ -1926,7 +1926,7 @@ static void psync_fsupload_process_tasks(psync_list *tasks) {
|
|||
}
|
||||
}
|
||||
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
|
||||
if (creats) {
|
||||
pupload_dec_by(creats);
|
||||
|
|
@ -1991,12 +1991,12 @@ static void psync_fsupload_run_tasks(psync_list *tasks) {
|
|||
papi_rdr_free(&reader);
|
||||
psync_fsupload_process_tasks(tasks);
|
||||
if (np) {
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
psync_list_for_each_element(task, tasks, fsupload_task_t,
|
||||
list) if (task->needprocessing &&
|
||||
task->status != 11)
|
||||
psync_send_task_func[task->type](NULL, task);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
return;
|
||||
err0:
|
||||
|
|
@ -2018,10 +2018,10 @@ static void clean_stuck_tasks() {
|
|||
uint32_t i;
|
||||
char fileidhex[sizeof(psync_fsfileid_t) * 2 + 2];
|
||||
cachepath = psync_setting_get_string(_PS(fscachepath));
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT f.id FROM fstask f LEFT JOIN pagecachetask p ON f.id=p.taskid "
|
||||
"WHERE f.status=3");
|
||||
fr = psync_sql_fetchall_int(res);
|
||||
fr = psql_fetchall_int(res);
|
||||
for (i = 0; i < fr->rows; i++) {
|
||||
taskid = psync_get_result_cell(fr, i, 0);
|
||||
psync_binhex(fileidhex, &taskid, sizeof(psync_fsfileid_t));
|
||||
|
|
@ -2036,15 +2036,15 @@ static void clean_stuck_tasks() {
|
|||
psync_strcat(cachepath, "/", fileidhex, NULL);
|
||||
pfile_delete(filename);
|
||||
free(filename);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"DELETE FROM fstaskdepend WHERE dependfstaskid=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement("DELETE FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
psql_commit();
|
||||
}
|
||||
free(fr);
|
||||
}
|
||||
|
|
@ -2060,20 +2060,20 @@ static void psync_fsupload_check_tasks() {
|
|||
psync_list_init(&tasks);
|
||||
cnt = 0;
|
||||
if (pstatus_get(PSTATUS_TYPE_ACCFULL) == PSTATUS_ACCFULL_QUOTAOK)
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_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"
|
||||
" LEFT JOIN fstaskdepend d ON f.id=d.fstaskid"
|
||||
" WHERE d.fstaskid IS NULL AND status IN (0, 11) ORDER BY id "
|
||||
"LIMIT " NTO_STR(PSYNC_FSUPLOAD_NUM_TASKS_PER_RUN));
|
||||
else
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_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"
|
||||
" LEFT JOIN fstaskdepend d ON f.id=d.fstaskid WHERE d.fstaskid IS NULL "
|
||||
"AND status IN (0, 11) AND f.type NOT IN (" NTO_STR(PSYNC_FS_TASK_CREAT) ", " NTO_STR(
|
||||
PSYNC_FS_TASK_MODIFY) ") ORDER BY id LIMIT " NTO_STR(PSYNC_FSUPLOAD_NUM_TASKS_PER_RUN));
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
cnt++;
|
||||
if (psync_get_number(row[0]) == current_upload_taskid)
|
||||
continue;
|
||||
|
|
@ -2109,14 +2109,14 @@ static void psync_fsupload_check_tasks() {
|
|||
// pdbg_logf(D_NOTICE, "will process taskid %lu", (unsigned long)task->id);
|
||||
}
|
||||
current_upload_batch = &tasks;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (cnt == PSYNC_FSUPLOAD_NUM_TASKS_PER_RUN)
|
||||
upload_wakes++;
|
||||
if (!psync_list_isempty(&tasks))
|
||||
psync_fsupload_run_tasks(&tasks);
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
current_upload_batch = NULL;
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
psync_list_for_each_element_call(&tasks, fsupload_task_t, list, free);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,9 +85,9 @@ enum {
|
|||
|
||||
static void delete_object_id(uint64_t oid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("DELETE FROM fsxattr WHERE objectid=?");
|
||||
psync_sql_bind_uint(res, 1, oid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM fsxattr WHERE objectid=?");
|
||||
psql_bind_uint(res, 1, oid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_fs_file_deleted(psync_fileid_t fileid) {
|
||||
|
|
@ -104,11 +104,11 @@ void psync_fs_task_deleted(uint64_t taskid) {
|
|||
|
||||
static void update_object_id(uint64_t ooid, uint64_t noid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE OR REPLACE fsxattr SET objectid=? WHERE objectid=?");
|
||||
psync_sql_bind_uint(res, 1, noid);
|
||||
psync_sql_bind_uint(res, 2, ooid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, noid);
|
||||
psql_bind_uint(res, 2, ooid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_fs_task_to_file(uint64_t taskid, psync_fileid_t fileid) {
|
||||
|
|
@ -165,10 +165,10 @@ static int64_t xattr_get_object_id_locked(const char *path) {
|
|||
else if (cr->fileid == 0)
|
||||
return static_taskid_to_objid(cr->taskid);
|
||||
else {
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT type, fileid FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, -cr->fileid);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, -cr->fileid);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
if (row[0] == PSYNC_FS_TASK_CREAT)
|
||||
ret = taskid_to_objid(-cr->fileid);
|
||||
else {
|
||||
|
|
@ -181,7 +181,7 @@ static int64_t xattr_get_object_id_locked(const char *path) {
|
|||
path, (unsigned long)(-cr->fileid));
|
||||
ret = -1;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -194,30 +194,30 @@ static int64_t xattr_get_object_id_locked(const char *path) {
|
|||
return -1;
|
||||
}
|
||||
if (checkfolder) {
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT id FROM folder WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, fspath->folderid);
|
||||
psync_sql_bind_string(res, 2, fspath->name);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, fspath->folderid);
|
||||
psql_bind_str(res, 2, fspath->name);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
ret = folderid_to_objid(row[0]);
|
||||
else
|
||||
ret = -1;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (ret != -1) {
|
||||
free(fspath);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (checkfile) {
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT id FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, fspath->folderid);
|
||||
psync_sql_bind_string(res, 2, fspath->name);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, fspath->folderid);
|
||||
psql_bind_str(res, 2, fspath->name);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
ret = fileid_to_objid(row[0]);
|
||||
else
|
||||
ret = -1;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (ret != -1) {
|
||||
free(fspath);
|
||||
return ret;
|
||||
|
|
@ -230,20 +230,20 @@ static int64_t xattr_get_object_id_locked(const char *path) {
|
|||
|
||||
#define LOCK_AND_LOOKUP() \
|
||||
do { \
|
||||
psync_sql_lock(); \
|
||||
psql_lock(); \
|
||||
oid = xattr_get_object_id_locked(path); \
|
||||
if (unlikely(oid == -1)) { \
|
||||
psync_sql_unlock(); \
|
||||
psql_unlock(); \
|
||||
return -pdbg_return_const(ENOENT); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOCK_AND_LOOKUPRD() \
|
||||
do { \
|
||||
psync_sql_rdlock(); \
|
||||
psql_rdlock(); \
|
||||
oid = xattr_get_object_id_locked(path); \
|
||||
if (unlikely(oid == -1)) { \
|
||||
psync_sql_rdunlock(); \
|
||||
psql_rdunlock(); \
|
||||
return -pdbg_return_const(ENOENT); \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
@ -257,37 +257,37 @@ int psync_fs_setxattr(const char *path, const char *name, const char *value,
|
|||
pdbg_logf(D_NOTICE, "setting attribute %s of %s", name, path);
|
||||
LOCK_AND_LOOKUP();
|
||||
if (flags & XATTR_CREATE) {
|
||||
res = psync_sql_prep_statement("INSERT OR IGNORE INTO fsxattr (objectid, "
|
||||
res = psql_prepare("INSERT OR IGNORE INTO fsxattr (objectid, "
|
||||
"name, value) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, oid);
|
||||
psync_sql_bind_string(res, 2, name);
|
||||
psync_sql_bind_blob(res, 3, value, size);
|
||||
psync_sql_run_free(res);
|
||||
if (psync_sql_affected_rows())
|
||||
psql_bind_uint(res, 1, oid);
|
||||
psql_bind_str(res, 2, name);
|
||||
psql_bind_blob(res, 3, value, size);
|
||||
psql_run_free(res);
|
||||
if (psql_affected())
|
||||
ret = 0;
|
||||
else
|
||||
ret = -pdbg_return_const(EEXIST);
|
||||
} else if (flags & XATTR_REPLACE) {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE fsxattr SET value=? WHERE objectid=? AND name=?");
|
||||
psync_sql_bind_blob(res, 1, value, size);
|
||||
psync_sql_bind_uint(res, 2, oid);
|
||||
psync_sql_bind_string(res, 3, name);
|
||||
psync_sql_run_free(res);
|
||||
if (psync_sql_affected_rows())
|
||||
psql_bind_blob(res, 1, value, size);
|
||||
psql_bind_uint(res, 2, oid);
|
||||
psql_bind_str(res, 3, name);
|
||||
psql_run_free(res);
|
||||
if (psql_affected())
|
||||
ret = 0;
|
||||
else
|
||||
ret = -pdbg_return_const(ENOATTR);
|
||||
} else {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO fsxattr (objectid, name, value) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, oid);
|
||||
psync_sql_bind_string(res, 2, name);
|
||||
psync_sql_bind_blob(res, 3, value, size);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, oid);
|
||||
psql_bind_str(res, 2, name);
|
||||
psql_bind_blob(res, 3, value, size);
|
||||
psql_run_free(res);
|
||||
ret = 0;
|
||||
}
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -302,11 +302,11 @@ int psync_fs_getxattr(const char *path, const char *name, char *value,
|
|||
psync_variant_row row;
|
||||
const char *str;
|
||||
size_t len;
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT value FROM fsxattr WHERE objectid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, oid);
|
||||
psync_sql_bind_string(res, 2, name);
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, oid);
|
||||
psql_bind_str(res, 2, name);
|
||||
if ((row = psql_fetch(res))) {
|
||||
str = psync_get_lstring(row[0], &len);
|
||||
if (size >= len) {
|
||||
pdbg_logf(D_NOTICE, "returning attribute %s of %s", name, path);
|
||||
|
|
@ -320,14 +320,14 @@ int psync_fs_getxattr(const char *path, const char *name, char *value,
|
|||
ret = -ENOATTR;
|
||||
// pdbg_logf(D_NOTICE, "attribute %s not found for %s", name, path);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
} else {
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT LENGTH(value) FROM fsxattr WHERE objectid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, oid);
|
||||
psync_sql_bind_string(res, 2, name);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, oid);
|
||||
psql_bind_str(res, 2, name);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
ret = row[0];
|
||||
pdbg_logf(D_NOTICE, "returning length of attribute %s of %s = %d", name, path,
|
||||
ret);
|
||||
|
|
@ -335,9 +335,9 @@ int psync_fs_getxattr(const char *path, const char *name, char *value,
|
|||
ret = -ENOATTR;
|
||||
// pdbg_logf(D_NOTICE, "attribute %s not found for %s", name, path);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -352,9 +352,9 @@ int psync_fs_listxattr(const char *path, char *list, size_t size) {
|
|||
if (size && list) {
|
||||
psync_variant_row row;
|
||||
ret = 0;
|
||||
res = psync_sql_query_nolock("SELECT name FROM fsxattr WHERE objectid=?");
|
||||
psync_sql_bind_uint(res, 1, oid);
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query_nolock("SELECT name FROM fsxattr WHERE objectid=?");
|
||||
psql_bind_uint(res, 1, oid);
|
||||
while ((row = psql_fetch(res))) {
|
||||
str = psync_get_lstring(row[0], &len);
|
||||
len++;
|
||||
if (ret + len > size) {
|
||||
|
|
@ -364,21 +364,21 @@ int psync_fs_listxattr(const char *path, char *list, size_t size) {
|
|||
memcpy(list + ret, str, len);
|
||||
ret += len;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE, "returning list of attributes of %s = %d", path, ret);
|
||||
} else {
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT SUM(LENGTH(name)+1) FROM fsxattr WHERE objectid=?");
|
||||
psync_sql_bind_uint(res, 1, oid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, oid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
ret = row[0];
|
||||
else
|
||||
ret = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE, "returning length of attributes of %s = %d", path, ret);
|
||||
}
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -388,13 +388,13 @@ int psync_fs_removexattr(const char *path, const char *name) {
|
|||
uint32_t aff;
|
||||
psync_fs_set_thread_name();
|
||||
LOCK_AND_LOOKUP();
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"DELETE FROM fsxattr WHERE objectid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, oid);
|
||||
psync_sql_bind_string(res, 2, name);
|
||||
psync_sql_run_free(res);
|
||||
aff = psync_sql_affected_rows();
|
||||
psync_sql_unlock();
|
||||
psql_bind_uint(res, 1, oid);
|
||||
psql_bind_str(res, 2, name);
|
||||
psql_run_free(res);
|
||||
aff = psql_affected();
|
||||
psql_unlock();
|
||||
if (aff) {
|
||||
pdbg_logf(D_NOTICE, "attribute %s deleted for %s", name, path);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ static const uint8_t __hex_lookupl[513] = {"000102030405060708090a0b0c0d0e0f"
|
|||
|
||||
uint16_t const *__hex_lookup = (uint16_t *)__hex_lookupl;
|
||||
|
||||
|
||||
char psync_my_auth[64] = "", psync_my_2fa_code[32], *psync_my_user = NULL,
|
||||
*psync_my_pass = NULL, *psync_my_2fa_token = NULL,
|
||||
*psync_my_verify_token = NULL;
|
||||
|
|
|
|||
|
|
@ -58,52 +58,52 @@ extern "C" {
|
|||
#define psync_get_number(v) \
|
||||
(likely((v).type == PSYNC_TNUMBER) \
|
||||
? (v).num \
|
||||
: psync_err_number_expected(__FILE__, __FUNCTION__, __LINE__, &(v)))
|
||||
: psql_expect_num(__FILE__, __FUNCTION__, __LINE__, &(v)))
|
||||
#define psync_get_snumber(v) \
|
||||
(likely((v).type == PSYNC_TNUMBER) \
|
||||
? (int64_t)((v).num) \
|
||||
: (int64_t)psync_err_number_expected(__FILE__, __FUNCTION__, __LINE__, \
|
||||
: (int64_t)psql_expect_num(__FILE__, __FUNCTION__, __LINE__, \
|
||||
&(v)))
|
||||
#define psync_get_number_or_null(v) \
|
||||
(((v).type == PSYNC_TNUMBER) \
|
||||
? (v).num \
|
||||
: (likely((v).type == PSYNC_TNULL) \
|
||||
? 0 \
|
||||
: psync_err_number_expected(__FILE__, __FUNCTION__, __LINE__, \
|
||||
: psql_expect_num(__FILE__, __FUNCTION__, __LINE__, \
|
||||
&(v))))
|
||||
#define psync_get_snumber_or_null(v) \
|
||||
(((v).type == PSYNC_TNUMBER) \
|
||||
? (int64_t)(v).num \
|
||||
: (likely((v).type == PSYNC_TNULL) \
|
||||
? 0 \
|
||||
: (int64_t)psync_err_number_expected(__FILE__, __FUNCTION__, \
|
||||
: (int64_t)psql_expect_num(__FILE__, __FUNCTION__, \
|
||||
__LINE__, &(v))))
|
||||
#define psync_get_string(v) \
|
||||
(likely((v).type == PSYNC_TSTRING) \
|
||||
? (v).str \
|
||||
: psync_err_string_expected(__FILE__, __FUNCTION__, __LINE__, &(v)))
|
||||
: psql_expect_str(__FILE__, __FUNCTION__, __LINE__, &(v)))
|
||||
#define psync_get_string_or_null(v) \
|
||||
(((v).type == PSYNC_TSTRING) \
|
||||
? (v).str \
|
||||
: (likely((v).type == PSYNC_TNULL) \
|
||||
? NULL \
|
||||
: psync_err_string_expected(__FILE__, __FUNCTION__, __LINE__, \
|
||||
: psql_expect_str(__FILE__, __FUNCTION__, __LINE__, \
|
||||
&(v))))
|
||||
#define psync_dup_string(v) \
|
||||
(likely((v).type == PSYNC_TSTRING) \
|
||||
? psync_strndup((v).str, (v).length) \
|
||||
: psync_strdup(psync_err_string_expected(__FILE__, __FUNCTION__, \
|
||||
: psync_strdup(psql_expect_str(__FILE__, __FUNCTION__, \
|
||||
__LINE__, &(v))))
|
||||
#define psync_get_lstring(v, l) \
|
||||
psync_lstring_expected(__FILE__, __FUNCTION__, __LINE__, &(v), l)
|
||||
psql_lstring_expected(__FILE__, __FUNCTION__, __LINE__, &(v), l)
|
||||
#define psync_get_lstring_or_null(v, l) \
|
||||
((v).type == PSYNC_TNULL \
|
||||
? NULL \
|
||||
: psync_lstring_expected(__FILE__, __FUNCTION__, __LINE__, &(v), l))
|
||||
: psql_lstring_expected(__FILE__, __FUNCTION__, __LINE__, &(v), l))
|
||||
#define psync_get_real(v) \
|
||||
(likely((v).type == PSYNC_TREAL) \
|
||||
? (v).real \
|
||||
: psync_err_real_expected(__FILE__, __FUNCTION__, __LINE__, &(v)))
|
||||
: psql_expect_real(__FILE__, __FUNCTION__, __LINE__, &(v)))
|
||||
|
||||
#if D_WARNING <= DEBUG_LEVEL
|
||||
#if defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP)
|
||||
|
|
@ -144,7 +144,6 @@ extern "C" {
|
|||
typedef void (*psync_run_after_t)(void *);
|
||||
|
||||
extern int psync_do_run;
|
||||
extern int psync_recache_contacts;
|
||||
extern pstatus_t psync_status;
|
||||
extern char psync_my_auth[64], psync_my_2fa_code[32], *psync_my_user,
|
||||
*psync_my_pass, *psync_my_2fa_token, *psync_my_verify_token;
|
||||
|
|
|
|||
|
|
@ -136,17 +136,17 @@ static void add_syncid(psync_syncid_t syncid) {
|
|||
const char *str;
|
||||
size_t len;
|
||||
struct epoll_event e;
|
||||
res = psync_sql_query("SELECT localpath FROM syncfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
if (likely(row = psync_sql_fetch_row(res))) {
|
||||
res = psql_query("SELECT localpath FROM syncfolder WHERE id=?");
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
if (likely(row = psql_fetch(res))) {
|
||||
str = psync_get_lstring(row[0], &len);
|
||||
len++;
|
||||
dir =
|
||||
(localnotify_dir *)malloc(offsetof(localnotify_dir, path) + len);
|
||||
memcpy(dir->path, str, len);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_ERROR, "could not find syncfolder with id %u",
|
||||
(unsigned int)syncid);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -144,11 +144,11 @@ static void scanner_set_syncs_to_list(psync_list *lst,
|
|||
psync_list_init(lst);
|
||||
psync_list_init(lst_deviceid_full);
|
||||
syncmp = psync_fs_getmountpoint();
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, folderid, localpath, synctype, deviceid, inode FROM "
|
||||
"syncfolder WHERE synctype&" NTO_STR(PSYNC_UPLOAD_ONLY) "=" NTO_STR(
|
||||
PSYNC_UPLOAD_ONLY));
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
lp = psync_get_lstring(row[2], &lplen);
|
||||
if (unlikely(stat(lp, &st))) {
|
||||
pdbg_logf(D_WARNING, "could not stat local folder %s, ignoring sync", lp);
|
||||
|
|
@ -183,7 +183,7 @@ static void scanner_set_syncs_to_list(psync_list *lst,
|
|||
memcpy(l_full_deviceid->localpath, lp, lplen + 1);
|
||||
psync_list_add_tail(lst_deviceid_full, &l_full_deviceid->list);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
free(syncmp);
|
||||
}
|
||||
|
||||
|
|
@ -314,20 +314,20 @@ static int scanner_local_folder_to_list(const char *localpath,
|
|||
static void delete_local_folder_rec(psync_folderid_t localfolderid);
|
||||
|
||||
static void try_delete_localfolder(psync_folderid_t localfolderid) {
|
||||
if (psync_sql_tryupgradelock())
|
||||
if (psql_tryupgradeLock())
|
||||
return;
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
delete_local_folder_rec(localfolderid);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
|
||||
static void try_delete_localfile(psync_fileid_t localfileid) {
|
||||
psync_sql_res *res;
|
||||
if (psync_sql_tryupgradelock())
|
||||
if (psql_tryupgradeLock())
|
||||
return;
|
||||
res = psync_sql_prep_statement("DELETE FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM localfile WHERE id=?");
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void scanner_db_folder_to_list(psync_syncid_t syncid,
|
||||
|
|
@ -339,13 +339,13 @@ static void scanner_db_folder_to_list(psync_syncid_t syncid,
|
|||
const char *name;
|
||||
size_t namelen;
|
||||
psync_list_init(lst);
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, folderid, inode, deviceid, mtimenative, name FROM "
|
||||
"localfolder WHERE localparentfolderid=? AND syncid=? AND mtimenative IS "
|
||||
"NOT NULL");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
while ((row = psql_fetch(res))) {
|
||||
name = psync_get_lstring(row[5], &namelen);
|
||||
if (unlikely(psync_is_lname_to_ignore(name, namelen))) {
|
||||
pdbg_logf(D_NOTICE,
|
||||
|
|
@ -368,13 +368,13 @@ static void scanner_db_folder_to_list(psync_syncid_t syncid,
|
|||
memcpy(e->name, name, namelen);
|
||||
psync_list_add_tail(lst, &e->list);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query_rdlock(
|
||||
psql_free(res);
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, fileid, inode, mtimenative, size, name FROM localfile WHERE "
|
||||
"localparentfolderid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
while ((row = psql_fetch(res))) {
|
||||
name = psync_get_lstring(row[5], &namelen);
|
||||
if (unlikely(psync_is_lname_to_ignore(name, namelen))) {
|
||||
pdbg_logf(D_NOTICE,
|
||||
|
|
@ -397,7 +397,7 @@ static void scanner_db_folder_to_list(psync_syncid_t syncid,
|
|||
memcpy(e->name, name, namelen);
|
||||
psync_list_add_tail(lst, &e->list);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
static int folderlist_cmp(const psync_list *l1, const psync_list *l2) {
|
||||
|
|
@ -623,34 +623,34 @@ static void scan_rename_file(sync_folderlist *rnfr, sync_folderlist *rnto) {
|
|||
psync_syncid_t old_syncid;
|
||||
int filetoupload;
|
||||
pdbg_logf(D_NOTICE, "file renamed from %s to %s", rnfr->name, rnto->name);
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT syncid, localparentfolderid FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, rnfr->localid);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, rnfr->localid);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
old_syncid = row[0];
|
||||
old_parentfolderid = row[1];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (rnto->syncid != old_syncid ||
|
||||
rnto->localparentfolderid != old_parentfolderid) {
|
||||
res = psync_sql_query_nolock("SELECT 1 FROM task WHERE type=" NTO_STR(
|
||||
res = psql_query_nolock("SELECT 1 FROM task WHERE type=" NTO_STR(
|
||||
PSYNC_UPLOAD_FILE) " AND localitemid=?");
|
||||
psync_sql_bind_uint(res, 1, rnfr->localid);
|
||||
filetoupload = !!psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, rnfr->localid);
|
||||
filetoupload = !!psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
} else {
|
||||
filetoupload = 0;
|
||||
}
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return;
|
||||
}
|
||||
res = psync_sql_prep_statement("UPDATE localfile SET localparentfolderid=?, "
|
||||
res = psql_prepare("UPDATE localfile SET localparentfolderid=?, "
|
||||
"syncid=?, name=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, rnto->localparentfolderid);
|
||||
psync_sql_bind_uint(res, 2, rnto->syncid);
|
||||
psync_sql_bind_string(res, 3, rnto->name);
|
||||
psync_sql_bind_uint(res, 4, rnfr->localid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, rnto->localparentfolderid);
|
||||
psql_bind_uint(res, 2, rnto->syncid);
|
||||
psql_bind_str(res, 3, rnto->name);
|
||||
psql_bind_uint(res, 4, rnfr->localid);
|
||||
psql_run_free(res);
|
||||
ptask_rfile_rename(rnfr->syncid, rnto->syncid, rnfr->localid,
|
||||
rnto->localparentfolderid, rnto->name);
|
||||
if (filetoupload) {
|
||||
|
|
@ -669,21 +669,21 @@ static void scan_upload_file(sync_folderlist *fl) {
|
|||
* -- is it? when? how? and with what localid?
|
||||
pupload_del_tasks(fl->localid);
|
||||
*/
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT OR IGNORE INTO localfile (localparentfolderid, syncid, size, "
|
||||
"inode, mtime, mtimenative, name)"
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, fl->localparentfolderid);
|
||||
psync_sql_bind_uint(res, 2, fl->syncid);
|
||||
psync_sql_bind_uint(res, 3, fl->size);
|
||||
psync_sql_bind_uint(res, 4, fl->inode);
|
||||
psync_sql_bind_uint(res, 5, psys_native_to_mtime(fl->mtimenat));
|
||||
psync_sql_bind_uint(res, 6, fl->mtimenat);
|
||||
psync_sql_bind_string(res, 7, fl->name);
|
||||
psync_sql_run_free(res);
|
||||
if (pdbg_unlikely(!psync_sql_affected_rows()))
|
||||
psql_bind_uint(res, 1, fl->localparentfolderid);
|
||||
psql_bind_uint(res, 2, fl->syncid);
|
||||
psql_bind_uint(res, 3, fl->size);
|
||||
psql_bind_uint(res, 4, fl->inode);
|
||||
psql_bind_uint(res, 5, psys_native_to_mtime(fl->mtimenat));
|
||||
psql_bind_uint(res, 6, fl->mtimenat);
|
||||
psql_bind_str(res, 7, fl->name);
|
||||
psql_run_free(res);
|
||||
if (pdbg_unlikely(!psql_affected()))
|
||||
return;
|
||||
localfileid = psync_sql_insertid();
|
||||
localfileid = psql_insertid();
|
||||
ptask_upload_q(fl->syncid, localfileid, fl->name);
|
||||
ppath_syncfldr_task_added(fl->syncid, fl->localparentfolderid);
|
||||
}
|
||||
|
|
@ -693,14 +693,14 @@ static void scan_upload_modified_file(sync_folderlist *fl) {
|
|||
pdbg_logf(D_NOTICE, "file modified %s (%lu)", fl->name,
|
||||
(unsigned long)fl->localid);
|
||||
pupload_del_tasks(fl->localid);
|
||||
res = psync_sql_prep_statement("UPDATE localfile SET size=?, inode=?, "
|
||||
res = psql_prepare("UPDATE localfile SET size=?, inode=?, "
|
||||
"mtime=?, mtimenative=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fl->size);
|
||||
psync_sql_bind_uint(res, 2, fl->inode);
|
||||
psync_sql_bind_uint(res, 3, psys_native_to_mtime(fl->mtimenat));
|
||||
psync_sql_bind_uint(res, 4, fl->mtimenat);
|
||||
psync_sql_bind_uint(res, 5, fl->localid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, fl->size);
|
||||
psql_bind_uint(res, 2, fl->inode);
|
||||
psql_bind_uint(res, 3, psys_native_to_mtime(fl->mtimenat));
|
||||
psql_bind_uint(res, 4, fl->mtimenat);
|
||||
psql_bind_uint(res, 5, fl->localid);
|
||||
psql_run_free(res);
|
||||
ptask_upload_q(fl->syncid, fl->localid, fl->name);
|
||||
ppath_syncfldr_task_added(fl->syncid, fl->localparentfolderid);
|
||||
}
|
||||
|
|
@ -714,22 +714,22 @@ static void scan_delete_file(sync_folderlist *fl) {
|
|||
pdbg_logf(D_NOTICE, "file deleted %s", fl->name);
|
||||
// it is also possible to use fl->remoteid, but the file might have just been
|
||||
// uploaded by the upload thread
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT fileid, syncid, localparentfolderid FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fl->localid);
|
||||
if (pdbg_likely(row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, fl->localid);
|
||||
if (pdbg_likely(row = psql_fetch_int(res))) {
|
||||
fileid = row[0];
|
||||
syncid = row[1];
|
||||
localparentfolderid = row[2];
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pupload_del_tasks(fl->localid);
|
||||
res = psync_sql_prep_statement("DELETE FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fl->localid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM localfile WHERE id=?");
|
||||
psql_bind_uint(res, 1, fl->localid);
|
||||
psql_run_free(res);
|
||||
if (fileid)
|
||||
ptask_rfile_rm(fl->syncid, fileid);
|
||||
ppathstatus_syncfldr_task_completed(syncid, localparentfolderid);
|
||||
|
|
@ -739,56 +739,56 @@ static void scan_create_folder(sync_folderlist *fl) {
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
psync_folderid_t localfolderid;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT OR IGNORE INTO localfolder (localparentfolderid, syncid, inode, "
|
||||
"deviceid, mtime, mtimenative, flags, name) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, 0, ?)");
|
||||
psync_sql_bind_uint(res, 1, fl->localparentfolderid);
|
||||
psync_sql_bind_uint(res, 2, fl->syncid);
|
||||
psync_sql_bind_uint(res, 3, fl->inode);
|
||||
psync_sql_bind_uint(res, 4, pdevice_id_short(fl->deviceid));
|
||||
psync_sql_bind_uint(res, 5, psys_native_to_mtime(fl->mtimenat));
|
||||
psync_sql_bind_uint(res, 6, fl->mtimenat);
|
||||
psync_sql_bind_string(res, 7, fl->name);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, fl->localparentfolderid);
|
||||
psql_bind_uint(res, 2, fl->syncid);
|
||||
psql_bind_uint(res, 3, fl->inode);
|
||||
psql_bind_uint(res, 4, pdevice_id_short(fl->deviceid));
|
||||
psql_bind_uint(res, 5, psys_native_to_mtime(fl->mtimenat));
|
||||
psql_bind_uint(res, 6, fl->mtimenat);
|
||||
psql_bind_str(res, 7, fl->name);
|
||||
psql_run_free(res);
|
||||
/* it is OK to use affected rows after run_free as we are in transaction */
|
||||
if (!psync_sql_affected_rows()) {
|
||||
res = psync_sql_query("SELECT id FROM localfolder WHERE syncid=? AND "
|
||||
if (!psql_affected()) {
|
||||
res = psql_query("SELECT id FROM localfolder WHERE syncid=? AND "
|
||||
"localparentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, fl->syncid);
|
||||
psync_sql_bind_uint(res, 2, fl->localparentfolderid);
|
||||
psync_sql_bind_string(res, 3, fl->name);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, fl->syncid);
|
||||
psql_bind_uint(res, 2, fl->localparentfolderid);
|
||||
psql_bind_str(res, 3, fl->name);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
localfolderid = row[0];
|
||||
pdbg_logf(D_NOTICE, "folder created %s, exists in localfolder, localid %lu",
|
||||
fl->name, (unsigned long)localfolderid);
|
||||
} else
|
||||
pdbg_logf(D_NOTICE, "folder created %s, exists in localfolder", fl->name);
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare(
|
||||
"UPDATE localfolder SET inode=?, deviceid=?, mtime=?, mtimenative=?, "
|
||||
"flags=0 WHERE syncid=? AND localparentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, fl->inode);
|
||||
psync_sql_bind_uint(res, 2, pdevice_id_short(fl->deviceid));
|
||||
psync_sql_bind_uint(res, 3, psys_native_to_mtime(fl->mtimenat));
|
||||
psync_sql_bind_uint(res, 4, fl->mtimenat);
|
||||
psync_sql_bind_uint(res, 5, fl->syncid);
|
||||
psync_sql_bind_uint(res, 6, fl->localparentfolderid);
|
||||
psync_sql_bind_string(res, 7, fl->name);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, fl->inode);
|
||||
psql_bind_uint(res, 2, pdevice_id_short(fl->deviceid));
|
||||
psql_bind_uint(res, 3, psys_native_to_mtime(fl->mtimenat));
|
||||
psql_bind_uint(res, 4, fl->mtimenat);
|
||||
psql_bind_uint(res, 5, fl->syncid);
|
||||
psql_bind_uint(res, 6, fl->localparentfolderid);
|
||||
psql_bind_str(res, 7, fl->name);
|
||||
psql_run_free(res);
|
||||
goto hasfolder;
|
||||
}
|
||||
localfolderid = psync_sql_insertid();
|
||||
localfolderid = psql_insertid();
|
||||
pdbg_logf(D_NOTICE, "folder created %s localid %lu", fl->name,
|
||||
(unsigned long)localfolderid);
|
||||
fl->localid = localfolderid;
|
||||
res = psync_sql_prep_statement("REPLACE INTO syncedfolder (syncid, "
|
||||
res = psql_prepare("REPLACE INTO syncedfolder (syncid, "
|
||||
"localfolderid, synctype) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, fl->syncid);
|
||||
psync_sql_bind_uint(res, 2, localfolderid);
|
||||
psync_sql_bind_uint(res, 3, fl->synctype);
|
||||
psync_sql_run_free(res);
|
||||
if (pdbg_unlikely(!psync_sql_affected_rows()))
|
||||
psql_bind_uint(res, 1, fl->syncid);
|
||||
psql_bind_uint(res, 2, localfolderid);
|
||||
psql_bind_uint(res, 3, fl->synctype);
|
||||
psql_run_free(res);
|
||||
if (pdbg_unlikely(!psql_affected()))
|
||||
return;
|
||||
ptask_rdir_mk(fl->syncid, localfolderid, fl->name);
|
||||
return;
|
||||
|
|
@ -816,21 +816,21 @@ static void update_syncid_rec(psync_folderid_t localfolderid,
|
|||
psync_syncid_t syncid) {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_prep_statement("UPDATE localfolder SET syncid=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare("UPDATE localfolder SET syncid=? WHERE id=?");
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, localfolderid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare(
|
||||
"UPDATE syncedfolder SET syncid=? WHERE localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_query_nolock(
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, localfolderid);
|
||||
psql_run_free(res);
|
||||
res = psql_query_nolock(
|
||||
"SELECT id FROM localfolder WHERE localparentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
update_syncid_rec(row[0], syncid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
static void scan_rename_folder(sync_folderlist *rnfr, sync_folderlist *rnto) {
|
||||
|
|
@ -838,15 +838,15 @@ static void scan_rename_folder(sync_folderlist *rnfr, sync_folderlist *rnto) {
|
|||
psync_uint_row row;
|
||||
// char *localpath;
|
||||
pdbg_logf(D_NOTICE, "folder renamed from %s to %s", rnfr->name, rnto->name);
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT syncid, localparentfolderid FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, rnfr->localid);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, rnfr->localid);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
ppathstatus_syncfldr_moved(
|
||||
rnfr->localid, row[0], row[1], rnto->syncid, rnto->localparentfolderid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE, "localfolderid %u not found in localfolder",
|
||||
(unsigned)rnfr->localid);
|
||||
// This can prorably happen if we race with a task to delete the folder that
|
||||
|
|
@ -855,19 +855,19 @@ static void scan_rename_folder(sync_folderlist *rnfr, sync_folderlist *rnto) {
|
|||
return;
|
||||
}
|
||||
res =
|
||||
psync_sql_prep_statement("UPDATE localfolder SET localparentfolderid=?, "
|
||||
psql_prepare("UPDATE localfolder SET localparentfolderid=?, "
|
||||
"syncid=?, name=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, rnto->localparentfolderid);
|
||||
psync_sql_bind_uint(res, 2, rnto->syncid);
|
||||
psync_sql_bind_string(res, 3, rnto->name);
|
||||
psync_sql_bind_uint(res, 4, rnfr->localid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_bind_uint(res, 1, rnto->localparentfolderid);
|
||||
psql_bind_uint(res, 2, rnto->syncid);
|
||||
psql_bind_str(res, 3, rnto->name);
|
||||
psql_bind_uint(res, 4, rnfr->localid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare(
|
||||
"UPDATE syncedfolder SET syncid=?, synctype=? WHERE localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, rnto->syncid);
|
||||
psync_sql_bind_uint(res, 2, rnto->synctype);
|
||||
psync_sql_bind_uint(res, 3, rnfr->localid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, rnto->syncid);
|
||||
psql_bind_uint(res, 2, rnto->synctype);
|
||||
psql_bind_uint(res, 3, rnfr->localid);
|
||||
psql_run_free(res);
|
||||
if (unlikely(rnfr->syncid != rnto->syncid)) {
|
||||
pdbg_logf(D_NOTICE, "folder %s moved from syncid %u to syncid %u", rnfr->name,
|
||||
(unsigned)rnfr->syncid, (unsigned)rnto->syncid);
|
||||
|
|
@ -881,32 +881,32 @@ static void delete_local_folder_rec(psync_folderid_t localfolderid) {
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res =
|
||||
psync_sql_query("SELECT id FROM localfolder WHERE localparentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_query("SELECT id FROM localfolder WHERE localparentfolderid=?");
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
delete_local_folder_rec(row[0]);
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query("SELECT id FROM localfile WHERE localparentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_free(res);
|
||||
res = psql_query("SELECT id FROM localfile WHERE localparentfolderid=?");
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
pupload_del_tasks(row[0]);
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM localfile WHERE localparentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_query("SELECT syncid FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
res = psql_query("SELECT syncid FROM localfolder WHERE id=?");
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
if (row)
|
||||
ppathstatus_syncfldr_deleted(row[0], localfolderid);
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement("DELETE FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare("DELETE FROM localfolder WHERE id=?");
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM syncedfolder WHERE localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void scan_delete_folder(sync_folderlist *fl) {
|
||||
|
|
@ -917,30 +917,30 @@ static void scan_delete_folder(sync_folderlist *fl) {
|
|||
tries = 0;
|
||||
retry:
|
||||
pdbg_logf(D_NOTICE, "folder deleted %s", fl->name);
|
||||
res = psync_sql_query("SELECT folderid FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fl->localid);
|
||||
if (pdbg_likely(row = psync_sql_fetch_rowint(res)))
|
||||
res = psql_query("SELECT folderid FROM localfolder WHERE id=?");
|
||||
psql_bind_uint(res, 1, fl->localid);
|
||||
if (pdbg_likely(row = psql_fetch_int(res)))
|
||||
folderid = row[0];
|
||||
else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (pdbg_unlikely(!folderid)) {
|
||||
/* folder is not yet created, folderid is not 0 but NULL actually */
|
||||
if (tries >= 50) {
|
||||
res = psync_sql_query("DELETE FROM task WHERE type=" NTO_STR(
|
||||
res = psql_query("DELETE FROM task WHERE type=" NTO_STR(
|
||||
PSYNC_CREATE_REMOTE_FOLDER) " AND syncid=? AND localitemid=?");
|
||||
psync_sql_bind_uint(res, 1, fl->syncid);
|
||||
psync_sql_bind_uint(res, 2, fl->localid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, fl->syncid);
|
||||
psql_bind_uint(res, 2, fl->localid);
|
||||
psql_run_free(res);
|
||||
} else {
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
if (tries == 10)
|
||||
ptimer_notify_exception();
|
||||
tries++;
|
||||
psys_sleep_milliseconds(20 + tries * 20);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
|
@ -953,9 +953,9 @@ retry:
|
|||
do { \
|
||||
if (unlikely(++trn > 1000)) { \
|
||||
trn = 0; \
|
||||
psync_sql_commit_transaction(); \
|
||||
psql_commit(); \
|
||||
psys_sleep_milliseconds(20); \
|
||||
psync_sql_start_transaction(); \
|
||||
psql_start(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
|
@ -968,7 +968,7 @@ static void scanner_scan(int first) {
|
|||
if (first)
|
||||
localsleepperfolder = 0;
|
||||
else {
|
||||
i = psync_sql_cellint("SELECT COUNT(*) FROM localfolder", 100);
|
||||
i = psql_cellint("SELECT COUNT(*) FROM localfolder", 100);
|
||||
if (!i)
|
||||
i = 1;
|
||||
localsleepperfolder = PSYNC_LOCALSCAN_SLEEPSEC_PER_SCAN * 1000 / i;
|
||||
|
|
@ -1062,7 +1062,7 @@ restart:
|
|||
trn = 0;
|
||||
if (!psync_list_isempty(&scan_lists[SCAN_LIST_RENFOLDERSROM]) ||
|
||||
!psync_list_isempty(&scan_lists[SCAN_LIST_NEWFOLDERS])) {
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
l2 = &scan_lists[SCAN_LIST_RENFOLDERSTO];
|
||||
psync_list_for_each(l1, &scan_lists[SCAN_LIST_RENFOLDERSROM]) {
|
||||
l2 = l2->next;
|
||||
|
|
@ -1084,7 +1084,7 @@ restart:
|
|||
check_for_query_cnt();
|
||||
}
|
||||
movedfolders = 1;
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
psync_list_init(&newtmp);
|
||||
psync_list_for_each_safe(l1, l2, &scan_lists[SCAN_LIST_NEWFOLDERS]) {
|
||||
psync_list_del(l1);
|
||||
|
|
@ -1119,7 +1119,7 @@ restart:
|
|||
l2 = &scan_lists[SCAN_LIST_RENFILESTO];
|
||||
trn = 0;
|
||||
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
psync_list_for_each(l1, &scan_lists[SCAN_LIST_RENFILESFROM]) {
|
||||
l2 = l2->next;
|
||||
scan_rename_file(psync_list_element(l1, sync_folderlist, list),
|
||||
|
|
@ -1153,7 +1153,7 @@ restart:
|
|||
}
|
||||
ppathstatus_clear_sync_cache();
|
||||
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
|
||||
if (w) {
|
||||
pupload_wake();
|
||||
|
|
@ -1333,14 +1333,14 @@ void psync_localscan_init() {
|
|||
ptimer_exception_handler(psync_wake_localscan_noscan);
|
||||
prun_thread("localscan", scanner_thread);
|
||||
localnotify = psync_localnotify_init();
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, localpath FROM syncfolder WHERE synctype&" NTO_STR(
|
||||
PSYNC_UPLOAD_ONLY) "=" NTO_STR(PSYNC_UPLOAD_ONLY));
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
syncid = psync_get_number(row[0]);
|
||||
localpath = psync_get_string(row[1]);
|
||||
psync_localnotify_add_sync(syncid);
|
||||
psync_restat_sync_folders_add(syncid, localpath);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ void *pmem_mmap(size_t size) {
|
|||
PSYNC_NOINLINE static void *psync_mmap_anon_emergency(size_t size) {
|
||||
void *ret;
|
||||
pdbg_logf(D_WARNING, "could not allocate %lu bytes", size);
|
||||
psync_try_free_memory();
|
||||
psql_try_free();
|
||||
ret = pmem_mmap(size);
|
||||
if (likely(ret))
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -417,11 +417,11 @@ int psync_get_remote_file_checksum(psync_fileid_t fileid, unsigned char *hexsum,
|
|||
psync_variant_row row;
|
||||
uint64_t result, h;
|
||||
binparam params[] = {PAPI_STR("auth", psync_my_auth), PAPI_NUM("fileid", fileid)};
|
||||
sres = psync_sql_query_rdlock(
|
||||
sres = psql_query_rdlock(
|
||||
"SELECT h.checksum, f.size, f.hash FROM hashchecksum h, file f WHERE "
|
||||
"f.id=? AND f.hash=h.hash AND f.size=h.size");
|
||||
psync_sql_bind_uint(sres, 1, fileid);
|
||||
row = psync_sql_fetch_row(sres);
|
||||
psql_bind_uint(sres, 1, fileid);
|
||||
row = psql_fetch(sres);
|
||||
if (row) {
|
||||
pdbg_assertw(row[0].length == PSYNC_HASH_DIGEST_HEXLEN);
|
||||
memcpy(hexsum, psync_get_string(row[0]), PSYNC_HASH_DIGEST_HEXLEN);
|
||||
|
|
@ -429,10 +429,10 @@ int psync_get_remote_file_checksum(psync_fileid_t fileid, unsigned char *hexsum,
|
|||
*fsize = psync_get_number(row[1]);
|
||||
if (hash)
|
||||
*hash = psync_get_number(row[2]);
|
||||
psync_sql_free_result(sres);
|
||||
psql_free(sres);
|
||||
return PSYNC_NET_OK;
|
||||
}
|
||||
psync_sql_free_result(sres);
|
||||
psql_free(sres);
|
||||
res = psync_api_run_command("checksumfile", params);
|
||||
if (!res)
|
||||
return PSYNC_NET_TEMPFAIL;
|
||||
|
|
@ -450,12 +450,12 @@ int psync_get_remote_file_checksum(psync_fileid_t fileid, unsigned char *hexsum,
|
|||
*fsize = result;
|
||||
if (hash)
|
||||
*hash = h;
|
||||
sres = psync_sql_prep_statement(
|
||||
sres = psql_prepare(
|
||||
"REPLACE INTO hashchecksum (hash, size, checksum) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(sres, 1, h);
|
||||
psync_sql_bind_uint(sres, 2, result);
|
||||
psync_sql_bind_lstring(sres, 3, checksum->str, checksum->length);
|
||||
psync_sql_run_free(sres);
|
||||
psql_bind_uint(sres, 1, h);
|
||||
psql_bind_uint(sres, 2, result);
|
||||
psql_bind_lstr(sres, 3, checksum->str, checksum->length);
|
||||
psql_run_free(sres);
|
||||
memcpy(hexsum, checksum->str, checksum->length);
|
||||
free(res);
|
||||
return PSYNC_NET_OK;
|
||||
|
|
@ -2412,15 +2412,15 @@ static int is_revision_local(const unsigned char *localhashhex,
|
|||
// listrevisions does not return zero sized revisions, so do we
|
||||
if (filesize == 0)
|
||||
return 1;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT f.fileid FROM filerevision f, hashchecksum h WHERE f.fileid=? "
|
||||
"AND f.hash=h.hash AND h.size=? AND h.checksum=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
psync_sql_bind_uint(res, 2, filesize);
|
||||
psync_sql_bind_lstring(res, 3, (const char *)localhashhex,
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
psql_bind_uint(res, 2, filesize);
|
||||
psql_bind_lstr(res, 3, (const char *)localhashhex,
|
||||
PSYNC_HASH_DIGEST_HEXLEN);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
return row ? 1 : 0;
|
||||
}
|
||||
|
||||
|
|
@ -2452,42 +2452,42 @@ static int download_file_revisions(psync_fileid_t fileid) {
|
|||
}
|
||||
revs = papi_find_result2(res, "revisions", PARAM_ARRAY);
|
||||
meta = papi_find_result2(res, "metadata", PARAM_HASH);
|
||||
psync_sql_start_transaction();
|
||||
fr = psync_sql_prep_statement("REPLACE INTO filerevision (fileid, hash, "
|
||||
psql_start();
|
||||
fr = psql_prepare("REPLACE INTO filerevision (fileid, hash, "
|
||||
"ctime, size) VALUES (?, ?, ?, ?)");
|
||||
hc = psync_sql_prep_statement(
|
||||
hc = psql_prepare(
|
||||
"REPLACE INTO hashchecksum (hash, size, checksum) VALUES (?, ?, ?)");
|
||||
for (i = 0; i < revs->length; i++) {
|
||||
hash = papi_find_result2(revs->array[i], "hash", PARAM_NUM)->num;
|
||||
size = papi_find_result2(revs->array[i], "size", PARAM_NUM)->num;
|
||||
psync_sql_bind_uint(fr, 1, fileid);
|
||||
psync_sql_bind_uint(fr, 2, hash);
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(fr, 1, fileid);
|
||||
psql_bind_uint(fr, 2, hash);
|
||||
psql_bind_uint(
|
||||
fr, 3, papi_find_result2(revs->array[i], "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(fr, 4, size);
|
||||
psync_sql_run(fr);
|
||||
psync_sql_bind_uint(hc, 1, hash);
|
||||
psync_sql_bind_uint(hc, 2, size);
|
||||
psync_sql_bind_lstring(
|
||||
psql_bind_uint(fr, 4, size);
|
||||
psql_run(fr);
|
||||
psql_bind_uint(hc, 1, hash);
|
||||
psql_bind_uint(hc, 2, size);
|
||||
psql_bind_lstr(
|
||||
hc, 3,
|
||||
papi_find_result2(revs->array[i], PSYNC_CHECKSUM, PARAM_STR)->str,
|
||||
PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psync_sql_run(hc);
|
||||
psql_run(hc);
|
||||
}
|
||||
hash = papi_find_result2(meta, "hash", PARAM_NUM)->num;
|
||||
psync_sql_bind_uint(fr, 1, fileid);
|
||||
psync_sql_bind_uint(fr, 2, hash);
|
||||
psync_sql_bind_uint(fr, 3,
|
||||
psql_bind_uint(fr, 1, fileid);
|
||||
psql_bind_uint(fr, 2, hash);
|
||||
psql_bind_uint(fr, 3,
|
||||
papi_find_result2(meta, "modified", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(fr, 4, papi_find_result2(meta, "size", PARAM_NUM)->num);
|
||||
psync_sql_run_free(fr);
|
||||
psync_sql_bind_uint(hc, 1, hash);
|
||||
psync_sql_bind_uint(hc, 2, papi_find_result2(meta, "size", PARAM_NUM)->num);
|
||||
psync_sql_bind_lstring(hc, 3,
|
||||
psql_bind_uint(fr, 4, papi_find_result2(meta, "size", PARAM_NUM)->num);
|
||||
psql_run_free(fr);
|
||||
psql_bind_uint(hc, 1, hash);
|
||||
psql_bind_uint(hc, 2, papi_find_result2(meta, "size", PARAM_NUM)->num);
|
||||
psql_bind_lstr(hc, 3,
|
||||
papi_find_result2(res, PSYNC_CHECKSUM, PARAM_STR)->str,
|
||||
PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psync_sql_run_free(hc);
|
||||
psync_sql_commit_transaction();
|
||||
psql_run_free(hc);
|
||||
psql_commit();
|
||||
free(res);
|
||||
return PSYNC_NET_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,11 +156,11 @@ static psync_fileid_t has_file(const unsigned char *hashstart,
|
|||
like[PSYNC_P2P_HEXHASH_BYTES] = '%';
|
||||
memcpy(hashsource + PSYNC_HASH_DIGEST_HEXLEN, rand,
|
||||
PSYNC_HASH_BLOCK_SIZE - PSYNC_HASH_DIGEST_HEXLEN);
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, checksum FROM localfile WHERE checksum LIKE ? AND size=?");
|
||||
psync_sql_bind_lstring(res, 1, like, PSYNC_P2P_HEXHASH_BYTES + 1);
|
||||
psync_sql_bind_uint(res, 2, filesize);
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_lstr(res, 1, like, PSYNC_P2P_HEXHASH_BYTES + 1);
|
||||
psql_bind_uint(res, 2, filesize);
|
||||
while ((row = psql_fetch(res))) {
|
||||
pdbg_assertw(row[1].type == PSYNC_TSTRING &&
|
||||
row[1].length == PSYNC_HASH_DIGEST_HEXLEN);
|
||||
memcpy(hashsource, row[1].str, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
|
|
@ -170,11 +170,11 @@ static psync_fileid_t has_file(const unsigned char *hashstart,
|
|||
if (realhash)
|
||||
memcpy(realhash, row[1].str, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
ret = psync_get_number(row[0]);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -794,14 +794,14 @@ static unsigned char *has_pages_in_db(uint64_t hash, uint64_t pageid,
|
|||
memset(ret, 0, pagecnt);
|
||||
fromid = 0;
|
||||
fcnt = 0;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT pageid, id FROM pagecache WHERE type=+" NTO_STR(
|
||||
PAGE_TYPE_READ) " AND hash=? AND pageid>=? AND pageid<? ORDER BY "
|
||||
"pageid");
|
||||
psync_sql_bind_uint(res, 1, hash);
|
||||
psync_sql_bind_uint(res, 2, pageid);
|
||||
psync_sql_bind_uint(res, 3, pageid + pagecnt);
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, hash);
|
||||
psql_bind_uint(res, 2, pageid);
|
||||
psql_bind_uint(res, 3, pageid + pagecnt);
|
||||
while ((row = psql_fetch_int(res))) {
|
||||
ret[row[0] - pageid] = 1;
|
||||
if (row[1] == fromid + fcnt)
|
||||
fcnt++;
|
||||
|
|
@ -813,7 +813,7 @@ static unsigned char *has_pages_in_db(uint64_t hash, uint64_t pageid,
|
|||
fcnt = 1;
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (fcnt && readahead)
|
||||
pfile_readahead(readcache, fromid * PSYNC_FS_PAGE_SIZE,
|
||||
fcnt * PSYNC_FS_PAGE_SIZE);
|
||||
|
|
@ -823,13 +823,13 @@ static unsigned char *has_pages_in_db(uint64_t hash, uint64_t pageid,
|
|||
static int has_page_in_db(uint64_t hash, uint64_t pageid) {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT pageid FROM pagecache WHERE type=+" NTO_STR(
|
||||
PAGE_TYPE_READ) " AND hash=? AND pageid=?");
|
||||
psync_sql_bind_uint(res, 1, hash);
|
||||
psync_sql_bind_uint(res, 2, pageid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, hash);
|
||||
psql_bind_uint(res, 2, pageid);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
return row != NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1349,25 +1349,25 @@ static void clean_cache() {
|
|||
return;
|
||||
}
|
||||
}
|
||||
cnt = psync_sql_cellint("SELECT MAX(id) FROM pagecache", 0);
|
||||
cnt = psql_cellint("SELECT MAX(id) FROM pagecache", 0);
|
||||
if (!cnt) {
|
||||
pthread_mutex_unlock(&clean_cache_mutex);
|
||||
pdbg_logf(D_NOTICE, "no entries in pagecache, cancelling cache clean");
|
||||
return;
|
||||
}
|
||||
clean_cache_in_progress = 1;
|
||||
psync_sql_sync();
|
||||
psql_sync();
|
||||
entries = (pagecache_entry *)malloc(cnt * sizeof(pagecache_entry));
|
||||
i = 0;
|
||||
e = 0;
|
||||
while (i < cnt) {
|
||||
res =
|
||||
psync_sql_query_rdlock("SELECT id, pageid, lastuse, usecnt, type FROM "
|
||||
psql_query_rdlock("SELECT id, pageid, lastuse, usecnt, type FROM "
|
||||
"pagecache WHERE id>? ORDER BY id LIMIT 50000");
|
||||
psync_sql_bind_uint(res, 1, e);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, e);
|
||||
row = psql_fetch_int(res);
|
||||
if (unlikely(!row)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
break;
|
||||
}
|
||||
do {
|
||||
|
|
@ -1384,12 +1384,12 @@ static void clean_cache() {
|
|||
entries[i].isfirst = row[2] < PSYNC_FS_FIRST_PAGES_UNDER_ID;
|
||||
entries[i].isxfirst = row[2] < PSYNC_FS_XFIRST_PAGES_UNDER_ID;
|
||||
i++;
|
||||
if ((i & 0x3ff) == 0x3ff && psync_sql_has_waiters())
|
||||
if ((i & 0x3ff) == 0x3ff && psql_waiting())
|
||||
break;
|
||||
}
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
row = psql_fetch_int(res);
|
||||
} while (row);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (free_db_pages)
|
||||
psys_sleep_milliseconds(1);
|
||||
}
|
||||
|
|
@ -1471,36 +1471,36 @@ static void clean_cache() {
|
|||
pagecache_entry_cmp_id);
|
||||
pdbg_logf(D_NOTICE, "sorted entries to delete by id to help the SQL");
|
||||
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement("UPDATE pagecache SET type=" NTO_STR(
|
||||
psql_start();
|
||||
res = psql_prepare("UPDATE pagecache SET type=" NTO_STR(
|
||||
PAGE_TYPE_FREE) ", hash=NULL, pageid=NULL, crc=NULL WHERE id=?");
|
||||
for (i = 0; i < cnt; i++) {
|
||||
psync_sql_bind_uint(res, 1, entries[i].id);
|
||||
psync_sql_run(res);
|
||||
psql_bind_uint(res, 1, entries[i].id);
|
||||
psql_run(res);
|
||||
free_db_pages++;
|
||||
if ((i & 0x1f) == 0x1f && psync_sql_has_waiters()) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_commit_transaction();
|
||||
if ((i & 0x1f) == 0x1f && psql_waiting()) {
|
||||
psql_free(res);
|
||||
psql_commit();
|
||||
pdbg_logf(D_NOTICE, "got waiters for sql lock, pausing for a while");
|
||||
psys_sleep_milliseconds(5);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement("UPDATE pagecache SET type=" NTO_STR(
|
||||
psql_start();
|
||||
res = psql_prepare("UPDATE pagecache SET type=" NTO_STR(
|
||||
PAGE_TYPE_FREE) ", hash=NULL, pageid=NULL, crc=NULL WHERE id=?");
|
||||
} else if ((i & 0xfff) == 0xfff) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_commit_transaction();
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement("UPDATE pagecache SET type=" NTO_STR(
|
||||
psql_free(res);
|
||||
psql_commit();
|
||||
psql_start();
|
||||
res = psql_prepare("UPDATE pagecache SET type=" NTO_STR(
|
||||
PAGE_TYPE_FREE) ", hash=NULL, pageid=NULL, crc=NULL WHERE id=?");
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_free(res);
|
||||
psql_commit();
|
||||
clean_cache_in_progress = 0;
|
||||
pthread_mutex_unlock(&clean_cache_mutex);
|
||||
free(oentries);
|
||||
pdbg_logf(D_NOTICE, "syncing database");
|
||||
psync_sql_sync();
|
||||
psql_sync();
|
||||
pdbg_logf(D_NOTICE, "finished cleaning cache, free cache pages %u",
|
||||
(unsigned)free_db_pages);
|
||||
}
|
||||
|
|
@ -1537,7 +1537,7 @@ static int check_disk_full() {
|
|||
int64_t filesize, freespace;
|
||||
uint64_t minlocal, maxpage, addspc;
|
||||
psync_sql_res *res;
|
||||
db_cache_max_page = psync_sql_cellint("SELECT MAX(id) FROM pagecache", 0);
|
||||
db_cache_max_page = psql_cellint("SELECT MAX(id) FROM pagecache", 0);
|
||||
filesize = pfile_size(readcache);
|
||||
if (pdbg_unlikely(filesize == -1))
|
||||
return 0;
|
||||
|
|
@ -1561,10 +1561,10 @@ static int check_disk_full() {
|
|||
maxpage = filesize / PSYNC_FS_PAGE_SIZE;
|
||||
else
|
||||
maxpage = (filesize + freespace - minlocal) / PSYNC_FS_PAGE_SIZE;
|
||||
res = psync_sql_prep_statement("DELETE FROM pagecache WHERE id>?");
|
||||
psync_sql_bind_uint(res, 1, maxpage);
|
||||
psync_sql_run_free(res);
|
||||
free_db_pages = psync_sql_cellint(
|
||||
res = psql_prepare("DELETE FROM pagecache WHERE id>?");
|
||||
psql_bind_uint(res, 1, maxpage);
|
||||
psql_run_free(res);
|
||||
free_db_pages = psql_cellint(
|
||||
"SELECT COUNT(*) FROM pagecache WHERE type=" NTO_STR(PAGE_TYPE_FREE), 0);
|
||||
db_cache_max_page = maxpage;
|
||||
pdbg_logf(D_NOTICE, "free_db_pages=%u, db_cache_max_page=%lu",
|
||||
|
|
@ -1648,12 +1648,12 @@ static int flush_pages(int nosleep) {
|
|||
pdbg_logf(D_NOTICE, "cache_pages_in_hash=%u", (unsigned)pagecnt);
|
||||
psync_list_sort(&pages_to_flush, cmp_flush_pages);
|
||||
res =
|
||||
psync_sql_query_rdlock("SELECT id FROM pagecache WHERE type=" NTO_STR(
|
||||
psql_query_rdlock("SELECT id FROM pagecache WHERE type=" NTO_STR(
|
||||
PAGE_TYPE_FREE) " ORDER BY id LIMIT ?");
|
||||
psync_sql_bind_uint(res, 1, pagecnt);
|
||||
psql_bind_uint(res, 1, pagecnt);
|
||||
psync_list_for_each_element(page, &pages_to_flush, psync_cache_page_t,
|
||||
flushlist) {
|
||||
if (unlikely(!(row = psync_sql_fetch_rowint(res)))) {
|
||||
if (unlikely(!(row = psql_fetch_int(res)))) {
|
||||
psync_list *l1, *l2;
|
||||
l1 = &page->flushlist;
|
||||
do {
|
||||
|
|
@ -1665,7 +1665,7 @@ static int flush_pages(int nosleep) {
|
|||
}
|
||||
page->flushpageid = row[0];
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
i = 0;
|
||||
psync_list_for_each_element(page, &pages_to_flush, psync_cache_page_t,
|
||||
flushlist) {
|
||||
|
|
@ -1706,31 +1706,31 @@ static int flush_pages(int nosleep) {
|
|||
}
|
||||
}
|
||||
pthread_mutex_unlock(&cache_mutex);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
pthread_mutex_lock(&cache_mutex);
|
||||
if (db_cache_max_page < db_cache_in_pages && cache_pages_in_hash &&
|
||||
!diskfull) {
|
||||
i = 0;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO pagecache (type) VALUES (" NTO_STR(PAGE_TYPE_FREE) ")");
|
||||
while (db_cache_max_page + i < db_cache_in_pages && i < CACHE_PAGES &&
|
||||
i < cache_pages_in_hash) {
|
||||
psync_sql_run(res);
|
||||
psql_run(res);
|
||||
i++;
|
||||
if (i % 64 == 0) {
|
||||
pthread_mutex_unlock(&cache_mutex);
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_free(res);
|
||||
psql_commit();
|
||||
if (!nosleep && !free_page_waiters)
|
||||
psys_sleep_milliseconds(1);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
pthread_mutex_lock(&cache_mutex);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO pagecache (type) VALUES (" NTO_STR(
|
||||
PAGE_TYPE_FREE) ")");
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
free_db_pages += i;
|
||||
db_cache_max_page += i;
|
||||
pdbg_logf(D_NOTICE,
|
||||
|
|
@ -1743,21 +1743,21 @@ static int flush_pages(int nosleep) {
|
|||
cpih = cache_pages_in_hash;
|
||||
if (!psync_list_isempty(&pages_to_flush)) {
|
||||
pagecnt = 0;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE OR IGNORE pagecache SET hash=?, pageid=?, type=" NTO_STR(
|
||||
PAGE_TYPE_READ) ", lastuse=?, usecnt=?, size=?, crc=? WHERE id=?");
|
||||
psync_list_for_each_element(page, &pages_to_flush, psync_cache_page_t,
|
||||
flushlist) {
|
||||
psync_list_del(&page->list);
|
||||
psync_sql_bind_uint(res, 1, page->hash);
|
||||
psync_sql_bind_uint(res, 2, page->pageid);
|
||||
psync_sql_bind_uint(res, 3, page->lastuse);
|
||||
psync_sql_bind_uint(res, 4, page->usecnt);
|
||||
psync_sql_bind_uint(res, 5, page->size);
|
||||
psync_sql_bind_uint(res, 6, page->crc);
|
||||
psync_sql_bind_uint(res, 7, page->flushpageid);
|
||||
psync_sql_run(res);
|
||||
if (likely(psync_sql_affected_rows())) {
|
||||
psql_bind_uint(res, 1, page->hash);
|
||||
psql_bind_uint(res, 2, page->pageid);
|
||||
psql_bind_uint(res, 3, page->lastuse);
|
||||
psql_bind_uint(res, 4, page->usecnt);
|
||||
psql_bind_uint(res, 5, page->size);
|
||||
psql_bind_uint(res, 6, page->crc);
|
||||
psql_bind_uint(res, 7, page->flushpageid);
|
||||
psql_run(res);
|
||||
if (likely(psql_affected())) {
|
||||
updates++;
|
||||
pagecnt++;
|
||||
free_db_pages--;
|
||||
|
|
@ -1768,20 +1768,20 @@ static int flush_pages(int nosleep) {
|
|||
if (free_page_waiters)
|
||||
pthread_cond_broadcast(&free_page_cond);
|
||||
pthread_mutex_unlock(&cache_mutex);
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_free(res);
|
||||
psql_commit();
|
||||
if (!free_page_waiters) // it is ok if we read a stale value, because we
|
||||
// don't hold cache_mutex any more
|
||||
psys_sleep_milliseconds(1);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
pthread_mutex_lock(&cache_mutex);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE OR IGNORE pagecache SET hash=?, pageid=?, type=" NTO_STR(
|
||||
PAGE_TYPE_READ) ", lastuse=?, usecnt=?, size=?, crc=? WHERE "
|
||||
"id=?");
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE,
|
||||
"flushed %u pages to cache file, free db pages %u, "
|
||||
"cache_pages_in_hash=%u",
|
||||
|
|
@ -1792,29 +1792,29 @@ static int flush_pages(int nosleep) {
|
|||
if (cachepages_to_update_cnt &&
|
||||
(cpih || cachepages_to_update_cnt >= DB_CACHE_UPDATE_HASH / 4 ||
|
||||
lastflush + 300 < ctime)) {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE pagecache SET lastuse=?, usecnt=usecnt+? WHERE id=?");
|
||||
for (i = 0; i < DB_CACHE_UPDATE_HASH; i++)
|
||||
if (cachepages_to_update[i].pagecacheid) {
|
||||
psync_sql_bind_uint(res, 1, cachepages_to_update[i].lastuse);
|
||||
psync_sql_bind_uint(res, 2, cachepages_to_update[i].usecnt);
|
||||
psync_sql_bind_uint(res, 3, cachepages_to_update[i].pagecacheid);
|
||||
psync_sql_run(res);
|
||||
psql_bind_uint(res, 1, cachepages_to_update[i].lastuse);
|
||||
psql_bind_uint(res, 2, cachepages_to_update[i].usecnt);
|
||||
psql_bind_uint(res, 3, cachepages_to_update[i].pagecacheid);
|
||||
psql_run(res);
|
||||
memset(&cachepages_to_update[i], 0, sizeof(psync_cachepage_to_update));
|
||||
updates++;
|
||||
if (!nosleep && updates % 128 == 0) {
|
||||
pthread_mutex_unlock(&cache_mutex);
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_free(res);
|
||||
psql_commit();
|
||||
if (!free_page_waiters)
|
||||
psys_sleep_milliseconds(1);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
pthread_mutex_lock(&cache_mutex);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE pagecache SET lastuse=?, usecnt=usecnt+? WHERE id=?");
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE, "flushed %u access records to database",
|
||||
(unsigned)cachepages_to_update_cnt);
|
||||
cachepages_to_update_cnt = 0;
|
||||
|
|
@ -1833,14 +1833,14 @@ static int flush_pages(int nosleep) {
|
|||
}
|
||||
if (updates) {
|
||||
pthread_mutex_unlock(&cache_mutex);
|
||||
ret = psync_sql_commit_transaction();
|
||||
ret = psql_commit();
|
||||
pthread_mutex_unlock(&flush_cache_mutex);
|
||||
if (free_db_pages <= CACHE_PAGES * 2)
|
||||
prun_thread("clean cache", clean_cache);
|
||||
return ret;
|
||||
} else {
|
||||
pthread_mutex_unlock(&cache_mutex);
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
pthread_mutex_unlock(&flush_cache_mutex);
|
||||
if (free_db_pages == 0)
|
||||
prun_thread("clean cache", clean_cache);
|
||||
|
|
@ -1946,10 +1946,10 @@ static void mark_pagescache_used(uint64_t first_page_id, unsigned long pagecnt,
|
|||
|
||||
PSYNC_NOINLINE static void mark_page_free(uint64_t pagecacheid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("UPDATE pagecache SET type=" NTO_STR(
|
||||
res = psql_prepare("UPDATE pagecache SET type=" NTO_STR(
|
||||
PAGE_TYPE_FREE) ", pageid=NULL, hash=NULL WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, pagecacheid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, pagecacheid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static long check_page_in_database_by_hash(uint64_t hash,
|
||||
|
|
@ -1964,12 +1964,12 @@ static long check_page_in_database_by_hash(uint64_t hash,
|
|||
uint64_t pagecacheid;
|
||||
uint32_t crc;
|
||||
ret = -1;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, size, crc FROM pagecache WHERE type=+" NTO_STR(
|
||||
PAGE_TYPE_READ) " AND hash=? AND pageid=?");
|
||||
psync_sql_bind_uint(res, 1, hash);
|
||||
psync_sql_bind_uint(res, 2, pageid);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, hash);
|
||||
psql_bind_uint(res, 2, pageid);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
pagecacheid = row[0];
|
||||
dsize = row[1];
|
||||
crc = row[2];
|
||||
|
|
@ -1981,7 +1981,7 @@ static long check_page_in_database_by_hash(uint64_t hash,
|
|||
}
|
||||
ret = size;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (ret != -1) {
|
||||
readret = pfile_pread(readcache, buff, size,
|
||||
pagecacheid * PSYNC_FS_PAGE_SIZE + off);
|
||||
|
|
@ -2018,14 +2018,14 @@ static void check_pages_in_database_by_hash(uint64_t hash,
|
|||
uint64_t cid, cpid;
|
||||
ssize_t readret;
|
||||
uint32_t i, j, cnt;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, pageid, size, crc FROM pagecache WHERE type=+" NTO_STR(
|
||||
PAGE_TYPE_READ) " AND hash=? AND pageid>=? AND pageid<? ORDER BY "
|
||||
"pageid");
|
||||
psync_sql_bind_uint(res, 1, hash);
|
||||
psync_sql_bind_uint(res, 2, first_page_id);
|
||||
psync_sql_bind_uint(res, 3, first_page_id + pagecnt);
|
||||
fres = psync_sql_fetchall_int(res);
|
||||
psql_bind_uint(res, 1, hash);
|
||||
psql_bind_uint(res, 2, first_page_id);
|
||||
psql_bind_uint(res, 3, first_page_id + pagecnt);
|
||||
fres = psql_fetchall_int(res);
|
||||
cnt = 1;
|
||||
for (i = 0; i < fres->rows; i += cnt) {
|
||||
if (psync_get_result_cell(fres, i, 2) != PSYNC_FS_PAGE_SIZE)
|
||||
|
|
@ -2085,12 +2085,12 @@ static long check_page_in_database_by_hash_and_cache(uint64_t hash,
|
|||
uint64_t pagecacheid;
|
||||
uint32_t crc, ccrc;
|
||||
ret = -1;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, size, crc FROM pagecache WHERE type=+" NTO_STR(
|
||||
PAGE_TYPE_READ) " AND hash=? AND pageid=?");
|
||||
psync_sql_bind_uint(res, 1, hash);
|
||||
psync_sql_bind_uint(res, 2, pageid);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, hash);
|
||||
psql_bind_uint(res, 2, pageid);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
pagecacheid = row[0];
|
||||
dsize = row[1];
|
||||
crc = row[2];
|
||||
|
|
@ -2102,7 +2102,7 @@ static long check_page_in_database_by_hash_and_cache(uint64_t hash,
|
|||
}
|
||||
ret = size;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (ret != -1) {
|
||||
page = psync_pagecache_get_free_page(0);
|
||||
readret = pfile_pread(readcache, page->page, dsize,
|
||||
|
|
@ -3574,20 +3574,20 @@ static void switch_pageids(uint64_t hash, uint64_t oldhash, uint64_t *pageids,
|
|||
unsigned long pageidcnt) {
|
||||
psync_sql_res *res;
|
||||
unsigned long i;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE OR IGNORE pagecache SET hash=?, lastuse=? WHERE hash=? AND "
|
||||
"type=? AND pageid=?");
|
||||
psync_sql_start_transaction();
|
||||
psync_sql_bind_uint(res, 1, hash);
|
||||
psync_sql_bind_uint(res, 2, ptimer_time());
|
||||
psync_sql_bind_uint(res, 3, oldhash);
|
||||
psync_sql_bind_uint(res, 4, PAGE_TYPE_READ);
|
||||
psql_start();
|
||||
psql_bind_uint(res, 1, hash);
|
||||
psql_bind_uint(res, 2, ptimer_time());
|
||||
psql_bind_uint(res, 3, oldhash);
|
||||
psql_bind_uint(res, 4, PAGE_TYPE_READ);
|
||||
for (i = 0; i < pageidcnt; i++) {
|
||||
psync_sql_bind_uint(res, 5, pageids[i]);
|
||||
psync_sql_run(res);
|
||||
psql_bind_uint(res, 5, pageids[i]);
|
||||
psql_run(res);
|
||||
}
|
||||
psync_sql_commit_transaction();
|
||||
psync_sql_free_result(res);
|
||||
psql_commit();
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
static void psync_pagecache_modify_to_cache(uint64_t taskid, uint64_t hash,
|
||||
|
|
@ -3826,12 +3826,12 @@ static void psync_pagecache_upload_to_cache() {
|
|||
uint64_t id, type, taskid, hash, oldhash;
|
||||
uint32_t wake;
|
||||
while (1) {
|
||||
res = psync_sql_query("SELECT id, type, taskid, hash, oldhash FROM "
|
||||
res = psql_query("SELECT id, type, taskid, hash, oldhash FROM "
|
||||
"pagecachetask ORDER BY id LIMIT 1");
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row) {
|
||||
upload_to_cache_thread_run = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
break;
|
||||
}
|
||||
id = row[0];
|
||||
|
|
@ -3839,22 +3839,22 @@ static void psync_pagecache_upload_to_cache() {
|
|||
taskid = row[2];
|
||||
hash = row[3];
|
||||
oldhash = row[4];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (type == PAGE_TASK_TYPE_CREAT)
|
||||
psync_pagecache_new_upload_to_cache(taskid, hash, 1);
|
||||
else if (type == PAGE_TASK_TYPE_MODIFY)
|
||||
psync_pagecache_modify_to_cache(taskid, hash, oldhash);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"DELETE FROM fstaskdepend WHERE dependfstaskid=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
wake = psync_sql_affected_rows();
|
||||
res = psync_sql_prep_statement("DELETE FROM fstask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
wake = psql_affected();
|
||||
res = psql_prepare("DELETE FROM fstask WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
if (IS_DEBUG) {
|
||||
if (psync_sql_affected_rows())
|
||||
if (psql_affected())
|
||||
pdbg_logf(D_NOTICE, "deleted taskid %lu from fstask",
|
||||
(unsigned long)taskid);
|
||||
else
|
||||
|
|
@ -3862,10 +3862,10 @@ static void psync_pagecache_upload_to_cache() {
|
|||
"no affected rows for deletion of taskid %lu from fstask",
|
||||
(unsigned long)taskid);
|
||||
}
|
||||
res = psync_sql_prep_statement("DELETE FROM pagecachetask WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, id);
|
||||
psync_sql_run_free(res);
|
||||
psync_sql_commit_transaction();
|
||||
res = psql_prepare("DELETE FROM pagecachetask WHERE id=?");
|
||||
psql_bind_uint(res, 1, id);
|
||||
psql_run_free(res);
|
||||
psql_commit();
|
||||
if (wake)
|
||||
psync_fsupload_wake();
|
||||
psync_pagecache_check_free_space();
|
||||
|
|
@ -3877,17 +3877,17 @@ static void psync_pagecache_add_task(uint32_t type, uint64_t taskid,
|
|||
psync_sql_res *res;
|
||||
int run;
|
||||
run = 0;
|
||||
res = psync_sql_prep_statement("INSERT INTO pagecachetask (type, taskid, "
|
||||
res = psql_prepare("INSERT INTO pagecachetask (type, taskid, "
|
||||
"hash, oldhash) VALUES (?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, type);
|
||||
psync_sql_bind_uint(res, 2, taskid);
|
||||
psync_sql_bind_uint(res, 3, hash);
|
||||
psync_sql_bind_uint(res, 4, oldhash);
|
||||
psql_bind_uint(res, 1, type);
|
||||
psql_bind_uint(res, 2, taskid);
|
||||
psql_bind_uint(res, 3, hash);
|
||||
psql_bind_uint(res, 4, oldhash);
|
||||
if (!upload_to_cache_thread_run) {
|
||||
upload_to_cache_thread_run = 1;
|
||||
run = 1;
|
||||
}
|
||||
psync_sql_run_free(res);
|
||||
psql_run_free(res);
|
||||
if (run)
|
||||
prun_thread("upload to cache", psync_pagecache_upload_to_cache);
|
||||
}
|
||||
|
|
@ -3962,13 +3962,13 @@ void ppagecache_resize() {
|
|||
pthread_mutex_lock(&flush_cache_mutex);
|
||||
db_cache_in_pages =
|
||||
psync_setting_get_uint(_PS(fscachesize)) / PSYNC_FS_PAGE_SIZE;
|
||||
db_cache_max_page = psync_sql_cellint("SELECT MAX(id) FROM pagecache", 0);
|
||||
db_cache_max_page = psql_cellint("SELECT MAX(id) FROM pagecache", 0);
|
||||
if (db_cache_max_page > db_cache_in_pages) {
|
||||
psync_sql_res *res;
|
||||
struct stat st;
|
||||
res = psync_sql_prep_statement("DELETE FROM pagecache WHERE id>?");
|
||||
psync_sql_bind_uint(res, 1, db_cache_in_pages);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM pagecache WHERE id>?");
|
||||
psql_bind_uint(res, 1, db_cache_in_pages);
|
||||
psql_run_free(res);
|
||||
db_cache_max_page = db_cache_in_pages;
|
||||
if (!fstat(readcache, &st) &&
|
||||
pfile_stat_size(&st) > db_cache_in_pages * PSYNC_FS_PAGE_SIZE) {
|
||||
|
|
@ -4007,9 +4007,9 @@ static int psync_pagecache_free_page_from_read_cache() {
|
|||
if (unlikely(db_cache_max_page > sizeinpages)) {
|
||||
pdbg_logf(D_NOTICE, "there are %lu unallocated pages in db, deleting",
|
||||
(unsigned long)(db_cache_max_page - sizeinpages));
|
||||
res = psync_sql_prep_statement("DELETE FROM pagecache WHERE id>?");
|
||||
psync_sql_bind_uint(res, 1, sizeinpages);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM pagecache WHERE id>?");
|
||||
psql_bind_uint(res, 1, sizeinpages);
|
||||
psql_run_free(res);
|
||||
db_cache_max_page = sizeinpages;
|
||||
} else if (pdbg_unlikely(db_cache_max_page < sizeinpages))
|
||||
sizeinpages = db_cache_max_page;
|
||||
|
|
@ -4025,12 +4025,12 @@ static int psync_pagecache_free_page_from_read_cache() {
|
|||
pdbg_logf(D_NOTICE, "read from read cache failed");
|
||||
break;
|
||||
}
|
||||
res = psync_sql_query_rdlock("SELECT type, hash, pageid, lastuse, usecnt, "
|
||||
res = psql_query_rdlock("SELECT type, hash, pageid, lastuse, usecnt, "
|
||||
"size, crc FROM pagecache WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, sizeinpages);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, sizeinpages);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row || row[0] == PAGE_TYPE_FREE) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_pagecache_return_free_page(page);
|
||||
} else {
|
||||
page->hash = row[1];
|
||||
|
|
@ -4039,7 +4039,7 @@ static int psync_pagecache_free_page_from_read_cache() {
|
|||
page->size = row[5];
|
||||
page->usecnt = row[4];
|
||||
page->crc = row[6];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (unlikely(pcrc32c_compute(PSYNC_CRC_INITIAL, page->page, page->size) !=
|
||||
page->crc)) {
|
||||
pdbg_logf(
|
||||
|
|
@ -4054,9 +4054,9 @@ static int psync_pagecache_free_page_from_read_cache() {
|
|||
}
|
||||
}
|
||||
db_cache_max_page = sizeinpages - 1;
|
||||
res = psync_sql_prep_statement("DELETE FROM pagecache WHERE id>?");
|
||||
psync_sql_bind_uint(res, 1, db_cache_max_page);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM pagecache WHERE id>?");
|
||||
psql_bind_uint(res, 1, db_cache_max_page);
|
||||
psql_run_free(res);
|
||||
if (pfile_seek(readcache, sizeinpages * PSYNC_FS_PAGE_SIZE,
|
||||
SEEK_SET) != -1 &&
|
||||
pfile_truncate(readcache) == 0)
|
||||
|
|
@ -4112,29 +4112,29 @@ void ppagecache_init() {
|
|||
cache_file = psync_strcat(cache_dir, "/",
|
||||
PSYNC_DEFAULT_READ_CACHE_FILE, NULL);
|
||||
if (stat(cache_file, &st))
|
||||
psync_sql_statement("DELETE FROM pagecache");
|
||||
psql_statement("DELETE FROM pagecache");
|
||||
else {
|
||||
res = psync_sql_prep_statement("DELETE FROM pagecache WHERE id>?");
|
||||
psync_sql_bind_uint(res, 1, pfile_stat_size(&st) / PSYNC_FS_PAGE_SIZE);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM pagecache WHERE id>?");
|
||||
psql_bind_uint(res, 1, pfile_stat_size(&st) / PSYNC_FS_PAGE_SIZE);
|
||||
psql_run_free(res);
|
||||
}
|
||||
db_cache_in_pages =
|
||||
psync_setting_get_uint(_PS(fscachesize)) / PSYNC_FS_PAGE_SIZE;
|
||||
db_cache_max_page = psync_sql_cellint("SELECT MAX(id) FROM pagecache", 0);
|
||||
free_db_pages = psync_sql_cellint(
|
||||
db_cache_max_page = psql_cellint("SELECT MAX(id) FROM pagecache", 0);
|
||||
free_db_pages = psql_cellint(
|
||||
"SELECT COUNT(*) FROM pagecache WHERE type=" NTO_STR(PAGE_TYPE_FREE), 0);
|
||||
if (db_cache_max_page < db_cache_in_pages &&
|
||||
free_db_pages < CACHE_PAGES * 2) {
|
||||
i = 0;
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"INSERT INTO pagecache (type) VALUES (" NTO_STR(PAGE_TYPE_FREE) ")");
|
||||
while (db_cache_max_page + i < db_cache_in_pages && i < CACHE_PAGES * 2) {
|
||||
psync_sql_run(res);
|
||||
psql_run(res);
|
||||
i++;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_free(res);
|
||||
psql_commit();
|
||||
free_db_pages += i;
|
||||
db_cache_max_page += i;
|
||||
pdbg_logf(D_NOTICE,
|
||||
|
|
@ -4154,12 +4154,12 @@ void ppagecache_init() {
|
|||
pthread_mutex_lock(&flush_cache_mutex);
|
||||
check_disk_full();
|
||||
pthread_mutex_unlock(&flush_cache_mutex);
|
||||
psync_sql_lock();
|
||||
if (psync_sql_cellint("SELECT COUNT(*) FROM pagecachetask", 0)) {
|
||||
psql_lock();
|
||||
if (psql_cellint("SELECT COUNT(*) FROM pagecachetask", 0)) {
|
||||
prun_thread("upload to cache", psync_pagecache_upload_to_cache);
|
||||
upload_to_cache_thread_run = 1;
|
||||
}
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
ptimer_register(ppagecache_flush_timer, PSYNC_FS_DISK_FLUSH_SEC,
|
||||
NULL);
|
||||
}
|
||||
|
|
@ -4204,7 +4204,7 @@ void ppagecache_clean_read() {
|
|||
pdbg_logf(D_NOTICE, "start");
|
||||
pthread_mutex_lock(&clean_cache_mutex);
|
||||
pthread_mutex_lock(&flush_cache_mutex);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
pdbg_logf(D_NOTICE, "aquired locks");
|
||||
db_cache_in_pages =
|
||||
psync_setting_get_uint(_PS(fscachesize)) / PSYNC_FS_PAGE_SIZE;
|
||||
|
|
@ -4215,19 +4215,19 @@ void ppagecache_clean_read() {
|
|||
pfile_seek(readcache, cnt * PSYNC_FS_PAGE_SIZE, SEEK_SET);
|
||||
pdbg_assertw(pfile_truncate(readcache) == 0);
|
||||
pdbg_logf(D_NOTICE, "truncated cache file");
|
||||
res = psync_sql_prep_statement("DELETE FROM pagecache");
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM pagecache");
|
||||
psql_run_free(res);
|
||||
pdbg_logf(D_NOTICE, "deleted entries from pagecache");
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO pagecache (type) VALUES (" NTO_STR(PAGE_TYPE_FREE) ")");
|
||||
for (i = 0; i < cnt; i++)
|
||||
psync_sql_run(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_run(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE,
|
||||
"re-inserted some free pages into database, commiting transaction");
|
||||
free_db_pages = cnt;
|
||||
db_cache_max_page = cnt;
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
pthread_mutex_unlock(&flush_cache_mutex);
|
||||
pthread_mutex_unlock(&clean_cache_mutex);
|
||||
pdbg_logf(D_NOTICE, "end");
|
||||
|
|
@ -4254,21 +4254,21 @@ int ppagecache_move(const char *path) {
|
|||
opath = psync_strdup(psync_setting_get_string(_PS(fscachepath)));
|
||||
pthread_mutex_lock(&clean_cache_mutex);
|
||||
pthread_mutex_lock(&flush_cache_mutex);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
pdbg_logf(D_NOTICE, "aquired locks");
|
||||
if (psync_sql_cellint("SELECT COUNT(*) FROM fstask", 0) != 0) {
|
||||
if (psql_cellint("SELECT COUNT(*) FROM fstask", 0) != 0) {
|
||||
if (IS_DEBUG) {
|
||||
psync_variant_row row;
|
||||
pdbg_logf(D_NOTICE, "the following tasks are preventing the cache move:");
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT id, type, status, folderid, text1 FROM fstask LIMIT 10");
|
||||
while ((row = psync_sql_fetch_row(res)))
|
||||
while ((row = psql_fetch(res)))
|
||||
pdbg_logf(D_NOTICE, "%u %u %u %u %s", (unsigned)psync_get_number(row[0]),
|
||||
(unsigned)psync_get_number(row[1]),
|
||||
(unsigned)psync_get_number(row[2]),
|
||||
(unsigned)psync_get_number(row[3]), psync_get_string(row[4]));
|
||||
}
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
pthread_mutex_unlock(&flush_cache_mutex);
|
||||
pthread_mutex_unlock(&clean_cache_mutex);
|
||||
pfile_close(newrdcache);
|
||||
|
|
@ -4289,19 +4289,19 @@ int ppagecache_move(const char *path) {
|
|||
pfile_seek(readcache, cnt * PSYNC_FS_PAGE_SIZE, SEEK_SET);
|
||||
pdbg_assertw(pfile_truncate(readcache) == 0);
|
||||
pdbg_logf(D_NOTICE, "truncated cache file");
|
||||
res = psync_sql_prep_statement("DELETE FROM pagecache");
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM pagecache");
|
||||
psql_run_free(res);
|
||||
pdbg_logf(D_NOTICE, "deleted entries from pagecache");
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO pagecache (type) VALUES (" NTO_STR(PAGE_TYPE_FREE) ")");
|
||||
for (i = 0; i < cnt; i++)
|
||||
psync_sql_run(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_run(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE,
|
||||
"re-inserted some free pages into database, commiting transaction");
|
||||
free_db_pages = cnt;
|
||||
db_cache_max_page = cnt;
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
pthread_mutex_unlock(&flush_cache_mutex);
|
||||
pthread_mutex_unlock(&clean_cache_mutex);
|
||||
pdbg_logf(D_NOTICE, "released locks");
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ char *ppath_default_db() {
|
|||
|
||||
if (oldp) {
|
||||
if (!stat(oldp, &st)) {
|
||||
if (psync_sql_reopen(oldp)) {
|
||||
if (psql_reopen(oldp)) {
|
||||
free(dbp);
|
||||
return oldp;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ static inline int psync_crypto_to_error(const void *ptr) {
|
|||
|
||||
void ppathstatus_init() {
|
||||
size_t i;
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
psync_list_init(&cache_free);
|
||||
psync_list_init(&path_cache_lru);
|
||||
psync_list_init(&parent_cache_lru);
|
||||
|
|
@ -169,7 +169,7 @@ void ppathstatus_init() {
|
|||
ppathstatus_reload_syncs();
|
||||
ppathstatus_clear_cache();
|
||||
load_sync_tasks();
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
static int create_sync_list_entry(psync_list_builder_t *builder, void *element,
|
||||
|
|
@ -193,17 +193,17 @@ void ppathstatus_reload_syncs() {
|
|||
psync_list_builder_t *builder;
|
||||
psync_sql_res *res;
|
||||
path_sync_list_t *old;
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
builder = psync_list_builder_create(sizeof(path_sync_list_entry_t),
|
||||
offsetof(path_sync_list_t, syncs));
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT sf.localpath, sf.id, sf.folderid, f.flags FROM syncfolder sf, "
|
||||
"folder f WHERE sf.folderid=f.id");
|
||||
psync_list_bulder_add_sql(builder, res, create_sync_list_entry);
|
||||
psql_list_add(builder, res, create_sync_list_entry);
|
||||
old = syncs;
|
||||
syncs = (path_sync_list_t *)psync_list_builder_finalize(builder);
|
||||
ppathstatus_clear_sync_cache();
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
if (old)
|
||||
psync_free_after_sec(old, 30);
|
||||
}
|
||||
|
|
@ -215,10 +215,10 @@ void ppathstatus_clear_cache() {
|
|||
sizeof(ndrv_hash_seed));
|
||||
} while (unlikely(!ndrv_hash_seed));
|
||||
nsync_hash_seed = 0x49916a8e891d1dafULL * ndrv_hash_seed;
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
drv_hash_seed = ndrv_hash_seed;
|
||||
sync_hash_seed = nsync_hash_seed;
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
void ppathstatus_clear_sync_cache() {
|
||||
|
|
@ -227,9 +227,9 @@ void ppathstatus_clear_sync_cache() {
|
|||
pssl_rand_strong((unsigned char *)&nsync_hash_seed,
|
||||
sizeof(nsync_hash_seed));
|
||||
} while (unlikely(nsync_hash_seed == drv_hash_seed));
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
sync_hash_seed = nsync_hash_seed;
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
static uint32_t hash_folderid(psync_folderid_t folderid) {
|
||||
|
|
@ -314,13 +314,13 @@ static psync_folderid_t get_parent_folder(psync_folderid_t folderid) {
|
|||
psync_list_add_tail(&parent_cache_lru, &p->list_lru);
|
||||
return p->parentfolderid;
|
||||
}
|
||||
res = psync_sql_query_nolock("SELECT parentfolderid FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
res = psql_query_nolock("SELECT parentfolderid FROM folder WHERE id=?");
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
row = psql_fetch_int(res);
|
||||
if (unlikely(!row)) {
|
||||
pdbg_logf(D_WARNING, "can not find parent folder for folderid %lu",
|
||||
(unsigned long)folderid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return PSYNC_INVALID_FOLDERID;
|
||||
}
|
||||
p = psync_list_remove_head_element(&parent_cache_lru, parent_cache_entry_t,
|
||||
|
|
@ -330,7 +330,7 @@ static psync_folderid_t get_parent_folder(psync_folderid_t folderid) {
|
|||
p->parentfolderid = row[0];
|
||||
psync_list_add_head(&parent_cache_hash[h], &p->list_hash);
|
||||
psync_list_add_tail(&parent_cache_lru, &p->list_lru);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return p->parentfolderid;
|
||||
}
|
||||
|
||||
|
|
@ -338,7 +338,7 @@ void ppathstatus_drive_fldr_changed(psync_folderid_t folderid) {
|
|||
psync_fstask_folder_t *folder;
|
||||
folder_tasks_t *ft;
|
||||
int changed;
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
folder = psync_fstask_get_folder_tasks_rdlocked(folderid);
|
||||
changed = folder && (folder->creats || folder->mkdirs);
|
||||
ft = get_folder_tasks(folderid, changed);
|
||||
|
|
@ -348,7 +348,7 @@ void ppathstatus_drive_fldr_changed(psync_folderid_t folderid) {
|
|||
ft->own_tasks = 1;
|
||||
else if (!changed && ft && ft->own_tasks)
|
||||
ft->own_tasks = 0;
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
return;
|
||||
}
|
||||
if (changed) {
|
||||
|
|
@ -376,7 +376,7 @@ void ppathstatus_drive_fldr_changed(psync_folderid_t folderid) {
|
|||
free_folder_tasks(ft);
|
||||
}
|
||||
}
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
static void folder_moved(psync_folderid_t folderid,
|
||||
|
|
@ -424,7 +424,7 @@ void ppathstatus_fldr_moved(psync_folderid_t folderid,
|
|||
mp->folderid = folderid;
|
||||
mp->old_parent_folderid = old_parent_folderid;
|
||||
mp->new_parent_folderid = new_parent_folderid;
|
||||
psync_sql_transation_add_callbacks(folder_moved_commit, free, mp);
|
||||
psql_translation_add_cb(folder_moved_commit, free, mp);
|
||||
}
|
||||
|
||||
void ppathstatus_fldr_deleted(psync_folderid_t folderid) {
|
||||
|
|
@ -555,14 +555,14 @@ static psync_folderid_t get_sync_parent_folder(sync_data_t *sd,
|
|||
psync_list_add_tail(&sd->parent_cache_lru, &p->list_lru);
|
||||
return p->parentfolderid;
|
||||
}
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT localparentfolderid FROM localfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
row = psql_fetch_int(res);
|
||||
if (unlikely(!row)) {
|
||||
pdbg_logf(D_WARNING, "can not find parent folder for localfolderid %lu",
|
||||
(unsigned long)folderid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return PSYNC_INVALID_FOLDERID;
|
||||
}
|
||||
p = psync_list_remove_head_element(&sd->parent_cache_lru,
|
||||
|
|
@ -572,7 +572,7 @@ static psync_folderid_t get_sync_parent_folder(sync_data_t *sd,
|
|||
p->parentfolderid = row[0];
|
||||
psync_list_add_head(&sd->parent_cache_hash[h], &p->list_hash);
|
||||
psync_list_add_tail(&sd->parent_cache_lru, &p->list_lru);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return p->parentfolderid;
|
||||
}
|
||||
|
||||
|
|
@ -600,53 +600,53 @@ void ppath_syncfldr_task_added_locked(
|
|||
|
||||
void ppath_syncfldr_task_added(psync_syncid_t syncid,
|
||||
psync_folderid_t localfolderid) {
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
ppathstatus_clear_sync_cache();
|
||||
ppath_syncfldr_task_added_locked(syncid, localfolderid);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
static void load_sync_tasks() {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT syncid, localitemid FROM task WHERE type=?");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
ppath_syncfldr_task_added_locked(row[0], row[1]);
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query_nolock(
|
||||
psql_free(res);
|
||||
res = psql_query_nolock(
|
||||
"SELECT lf.syncid, lf.localparentfolderid FROM task t, localfile lf "
|
||||
"WHERE t.type=? AND t.localitemid=lf.id AND t.syncid=lf.syncid");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
ppath_syncfldr_task_added_locked(row[0], row[1]);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
static int local_folder_has_tasks(psync_syncid_t syncid,
|
||||
psync_folderid_t localfolderid) {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT 1 FROM task WHERE type=? AND syncid=? AND localitemid=?");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, localfolderid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, localfolderid);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
if (row)
|
||||
return 1;
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT 1 FROM localfile lf, task t WHERE lf.syncid=? AND "
|
||||
"lf.localparentfolderid=? AND lf.id=t.localitemid AND "
|
||||
"t.syncid=? AND t.type=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, localfolderid);
|
||||
psync_sql_bind_uint(res, 3, syncid);
|
||||
psync_sql_bind_uint(res, 4, PSYNC_UPLOAD_FILE);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, localfolderid);
|
||||
psql_bind_uint(res, 3, syncid);
|
||||
psql_bind_uint(res, 4, PSYNC_UPLOAD_FILE);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
if (row)
|
||||
return 1;
|
||||
return 0;
|
||||
|
|
@ -666,12 +666,12 @@ void ppathstatus_syncfldr_task_completed(
|
|||
// pdbg_logf(D_NOTICE, "syncid %u localfolderid %lu lfht %d", (unsigned)syncid,
|
||||
// (unsigned long)localfolderid, local_folder_has_tasks(syncid,
|
||||
// localfolderid));
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
ppathstatus_clear_sync_cache();
|
||||
if (local_folder_has_tasks(syncid, localfolderid) ||
|
||||
!(sd = get_sync_data(syncid, 0)) ||
|
||||
!(ft = get_sync_folder_tasks(sd, localfolderid, 0))) {
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
return;
|
||||
}
|
||||
ft->own_tasks = 0;
|
||||
|
|
@ -685,16 +685,16 @@ void ppathstatus_syncfldr_task_completed(
|
|||
pdbg_assert(ft->child_task_cnt);
|
||||
ft->child_task_cnt--;
|
||||
}
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
void ppathstatus_syncfldr_delete(psync_syncid_t syncid) {
|
||||
sync_data_t *sd;
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
sd = get_sync_data(syncid, 0);
|
||||
if (sd)
|
||||
ptree_del(&sync_data, &sd->tree);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
if (sd)
|
||||
sync_data_free(sd);
|
||||
}
|
||||
|
|
@ -775,7 +775,7 @@ void ppathstatus_syncfldr_moved(psync_folderid_t folderid,
|
|||
mp->new_parent_folderid = new_parent_folderid;
|
||||
mp->old_syncid = old_syncid;
|
||||
mp->new_syncid = new_syncid;
|
||||
psync_sql_transation_add_callbacks(sync_folder_moved_commit, free, mp);
|
||||
psql_translation_add_cb(sync_folder_moved_commit, free, mp);
|
||||
}
|
||||
|
||||
void ppathstatus_syncfldr_deleted(psync_syncid_t syncid,
|
||||
|
|
@ -805,7 +805,7 @@ static inline int is_slash(char ch) { return ch == '/'; }
|
|||
static inline int valid_last_char(char ch) { return is_slash(ch) || ch == 0; }
|
||||
|
||||
static psync_path_status_t rdunlock_return(psync_path_status_t st) {
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
return st;
|
||||
}
|
||||
|
||||
|
|
@ -817,7 +817,7 @@ static psync_path_status_t rdunlock_return_in_prog() {
|
|||
PSTATUS_ONLINE_ONLINE),
|
||||
PSTATUS_COMBINE(PSTATUS_TYPE_ACCFULL, PSTATUS_ACCFULL_QUOTAOK),
|
||||
PSTATUS_COMBINE(PSTATUS_TYPE_DISKFULL, PSTATUS_DISKFULL_OK)};
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
if (pstatus_ok_status_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses)))
|
||||
return PSYNC_PATH_STATUS_IN_PROG;
|
||||
else
|
||||
|
|
@ -828,7 +828,7 @@ static psync_path_status_t
|
|||
psync_path_status_drive_folder_locked(psync_folderid_t folderid) {
|
||||
if (get_folder_tasks(folderid, 0))
|
||||
return rdunlock_return_in_prog();
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
return PSYNC_PATH_STATUS_IN_SYNC;
|
||||
}
|
||||
|
||||
|
|
@ -917,7 +917,7 @@ static psync_path_status_t psync_path_status_drive(const char *path,
|
|||
path_len--;
|
||||
}
|
||||
wrlocked = 0;
|
||||
psync_sql_rdlock();
|
||||
psql_rdlock();
|
||||
if (!get_folder_tasks(0, 0))
|
||||
return rdunlock_return(PSYNC_PATH_STATUS_IN_SYNC);
|
||||
if (!path_len)
|
||||
|
|
@ -970,29 +970,29 @@ restart:
|
|||
if (found)
|
||||
continue;
|
||||
res =
|
||||
psync_sql_query_nolock("SELECT id, permissions, flags, userid FROM "
|
||||
psql_query_nolock("SELECT id, permissions, flags, userid FROM "
|
||||
"folder WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
if (likely((flags & ENTRY_FLAG_ENCRYPTED) == 0)) {
|
||||
psync_sql_bind_lstring(res, 2, path + poff, off - poff);
|
||||
psql_bind_lstr(res, 2, path + poff, off - poff);
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (unlikely(move_encname_to_buff(folderid, buff, sizeof(buff),
|
||||
path + poff, off - poff)))
|
||||
return rdunlock_return(PSYNC_PATH_STATUS_IN_SYNC);
|
||||
psync_sql_bind_string(res, 2, buff);
|
||||
psql_bind_str(res, 2, buff);
|
||||
}
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return rdunlock_return(PSYNC_PATH_STATUS_NOT_FOUND);
|
||||
}
|
||||
if (!wrlocked) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
wrlocked = 1;
|
||||
if (psync_sql_tryupgradelock()) {
|
||||
psync_sql_rdunlock();
|
||||
psync_sql_lock();
|
||||
if (psql_tryupgradeLock()) {
|
||||
psql_rdunlock();
|
||||
psql_lock();
|
||||
}
|
||||
goto restart;
|
||||
}
|
||||
|
|
@ -1000,7 +1000,7 @@ restart:
|
|||
flags = ENTRY_FLAG_FOLDER;
|
||||
if (row[2] & PSYNC_FOLDER_FLAG_ENCRYPTED)
|
||||
flags |= ENTRY_FLAG_ENCRYPTED;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
ce = psync_list_remove_head_element(&path_cache_lru, path_cache_entry_t,
|
||||
list_lru);
|
||||
psync_list_add_tail(&path_cache_lru, &ce->list_lru);
|
||||
|
|
@ -1068,36 +1068,36 @@ restart:
|
|||
name = buff;
|
||||
namelen = strlen(buff);
|
||||
}
|
||||
res = psync_sql_query_nolock("SELECT id, permissions, flags, userid FROM "
|
||||
res = psql_query_nolock("SELECT id, permissions, flags, userid FROM "
|
||||
"folder WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, name, namelen);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, name, namelen);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row || (folder && psync_fstask_find_rmdir(folder, path + poff, 0))) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (folder && psync_fstask_find_unlink(folder, path + poff, 0))
|
||||
return rdunlock_return(PSYNC_PATH_STATUS_NOT_FOUND);
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT id FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_lstring(res, 2, name, namelen);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_lstr(res, 2, name, namelen);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return rdunlock_return(PSYNC_PATH_STATUS_NOT_FOUND);
|
||||
}
|
||||
if (!wrlocked) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
wrlocked = 1;
|
||||
if (psync_sql_tryupgradelock()) {
|
||||
psync_sql_rdunlock();
|
||||
psync_sql_lock();
|
||||
if (psql_tryupgradeLock()) {
|
||||
psql_rdunlock();
|
||||
psql_lock();
|
||||
}
|
||||
goto restart;
|
||||
}
|
||||
folderid = row[0];
|
||||
flags &= ~ENTRY_FLAG_FOLDER;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
ce = psync_list_remove_head_element(&path_cache_lru, path_cache_entry_t,
|
||||
list_lru);
|
||||
psync_list_add_tail(&path_cache_lru, &ce->list_lru);
|
||||
|
|
@ -1109,17 +1109,17 @@ restart:
|
|||
return rdunlock_return(PSYNC_PATH_STATUS_IN_SYNC);
|
||||
}
|
||||
if (!wrlocked) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
wrlocked = 1;
|
||||
if (psync_sql_tryupgradelock()) {
|
||||
psync_sql_rdunlock();
|
||||
psync_sql_lock();
|
||||
if (psql_tryupgradeLock()) {
|
||||
psql_rdunlock();
|
||||
psql_lock();
|
||||
}
|
||||
goto restart;
|
||||
}
|
||||
folderid = row[0];
|
||||
flags = ENTRY_FLAG_FOLDER;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
ce = psync_list_remove_head_element(&path_cache_lru, path_cache_entry_t,
|
||||
list_lru);
|
||||
psync_list_add_tail(&path_cache_lru, &ce->list_lru);
|
||||
|
|
@ -1137,7 +1137,7 @@ psync_path_status_sync_folder_locked(psync_syncid_t syncid,
|
|||
sync_data_t *sd = get_sync_data(syncid, 0);
|
||||
if (sd && get_sync_folder_tasks(sd, folderid, 0))
|
||||
return rdunlock_return_in_prog();
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
return PSYNC_PATH_STATUS_IN_SYNC;
|
||||
}
|
||||
|
||||
|
|
@ -1170,23 +1170,23 @@ static int sync_file_in_progress(psync_syncid_t syncid,
|
|||
ft = get_sync_folder_tasks(sd, localfolderid, 0);
|
||||
if (!ft || !ft->own_tasks)
|
||||
return 0;
|
||||
res = psync_sql_query_nolock("SELECT 1 FROM task WHERE type=? AND syncid=? "
|
||||
res = psql_query_nolock("SELECT 1 FROM task WHERE type=? AND syncid=? "
|
||||
"AND localitemid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, localfolderid);
|
||||
psync_sql_bind_lstring(res, 4, name, namelen);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, localfolderid);
|
||||
psql_bind_lstr(res, 4, name, namelen);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
if (row)
|
||||
return 1;
|
||||
res = psync_sql_query_nolock(
|
||||
res = psql_query_nolock(
|
||||
"SELECT 1 FROM task WHERE type=? AND syncid=? AND localitemid=?");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, localfileid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, localfileid);
|
||||
row = psql_fetch_int(res);
|
||||
psql_free(res);
|
||||
if (row)
|
||||
return 1;
|
||||
return 0;
|
||||
|
|
@ -1209,7 +1209,7 @@ static psync_path_status_t psync_path_status_sync(const char *path,
|
|||
path_len--;
|
||||
}
|
||||
wrlocked = 0;
|
||||
psync_sql_rdlock();
|
||||
psql_rdlock();
|
||||
if (!path_len)
|
||||
return psync_path_status_sync_folder_locked(syncid, 0);
|
||||
restart:
|
||||
|
|
@ -1245,28 +1245,28 @@ restart:
|
|||
if (found)
|
||||
continue;
|
||||
res =
|
||||
psync_sql_query_nolock("SELECT id FROM localfolder WHERE syncid=? "
|
||||
psql_query_nolock("SELECT id FROM localfolder WHERE syncid=? "
|
||||
"AND localparentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, extract_localfolderid(folderid));
|
||||
psync_sql_bind_lstring(res, 3, path + poff, off - poff);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, extract_localfolderid(folderid));
|
||||
psql_bind_lstr(res, 3, path + poff, off - poff);
|
||||
row = psql_fetch_int(res);
|
||||
if (!row) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return rdunlock_return_in_prog();
|
||||
}
|
||||
if (!wrlocked) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
wrlocked = 1;
|
||||
if (psync_sql_tryupgradelock()) {
|
||||
psync_sql_rdunlock();
|
||||
psync_sql_lock();
|
||||
if (psql_tryupgradeLock()) {
|
||||
psql_rdunlock();
|
||||
psql_lock();
|
||||
}
|
||||
goto restart;
|
||||
}
|
||||
folderid = combine_syncid_lf(syncid, row[0]);
|
||||
flags = ENTRY_FLAG_FOLDER;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
ce = psync_list_remove_head_element(&path_cache_lru, path_cache_entry_t,
|
||||
list_lru);
|
||||
psync_list_add_tail(&path_cache_lru, &ce->list_lru);
|
||||
|
|
@ -1309,19 +1309,19 @@ restart:
|
|||
else
|
||||
return rdunlock_return(PSYNC_PATH_STATUS_IN_SYNC);
|
||||
}
|
||||
res = psync_sql_query_nolock("SELECT id FROM localfolder WHERE syncid=? AND "
|
||||
res = psql_query_nolock("SELECT id FROM localfolder WHERE syncid=? AND "
|
||||
"localparentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, extract_localfolderid(folderid));
|
||||
psync_sql_bind_lstring(res, 3, path + poff, path_len - poff);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, extract_localfolderid(folderid));
|
||||
psql_bind_lstr(res, 3, path + poff, path_len - poff);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
folderid = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (!wrlocked) {
|
||||
wrlocked = 1;
|
||||
if (psync_sql_tryupgradelock()) {
|
||||
psync_sql_rdunlock();
|
||||
psync_sql_lock();
|
||||
if (psql_tryupgradeLock()) {
|
||||
psql_rdunlock();
|
||||
psql_lock();
|
||||
}
|
||||
goto restart;
|
||||
}
|
||||
|
|
@ -1335,20 +1335,20 @@ restart:
|
|||
ce->flags = ENTRY_FLAG_FOLDER;
|
||||
return psync_path_status_sync_folder_locked(syncid, folderid);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query_nolock("SELECT id FROM localfile WHERE syncid=? AND "
|
||||
psql_free(res);
|
||||
res = psql_query_nolock("SELECT id FROM localfile WHERE syncid=? AND "
|
||||
"localparentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, extract_localfolderid(folderid));
|
||||
psync_sql_bind_lstring(res, 3, path + poff, path_len - poff);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, extract_localfolderid(folderid));
|
||||
psql_bind_lstr(res, 3, path + poff, path_len - poff);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
flags = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (!wrlocked) {
|
||||
wrlocked = 1;
|
||||
if (psync_sql_tryupgradelock()) {
|
||||
psync_sql_rdunlock();
|
||||
psync_sql_lock();
|
||||
if (psql_tryupgradeLock()) {
|
||||
psql_rdunlock();
|
||||
psql_lock();
|
||||
}
|
||||
goto restart;
|
||||
}
|
||||
|
|
@ -1368,7 +1368,7 @@ restart:
|
|||
else
|
||||
return rdunlock_return(PSYNC_PATH_STATUS_IN_SYNC);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return rdunlock_return_in_prog();
|
||||
}
|
||||
|
||||
|
|
@ -1430,12 +1430,12 @@ psync_path_status_t ppathstatus_get(const char *path) {
|
|||
if (dp) {
|
||||
// assign the len before the mutex, so we use it as a barrier
|
||||
drive_path_len = strlen(dp);
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
if (!drive_path) {
|
||||
drive_path = dp;
|
||||
dp = NULL;
|
||||
}
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
free(dp);
|
||||
if (len >= drive_path_len && !memcmp(drive_path, path, drive_path_len) &&
|
||||
valid_last_char(path[drive_path_len]))
|
||||
|
|
@ -1445,9 +1445,9 @@ psync_path_status_t ppathstatus_get(const char *path) {
|
|||
}
|
||||
sn = syncs;
|
||||
if (!sn) {
|
||||
psync_sql_rdlock();
|
||||
psql_rdlock();
|
||||
sn = syncs;
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
if (!sn)
|
||||
goto slower_check;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ static void load_sql(psync_lhash_ctx *hctx, psync_sql_res *res) {
|
|||
psync_variant_row row;
|
||||
struct timespec tm;
|
||||
int i;
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
for (i = 0; i < res->column_count; i++)
|
||||
if (row[i].type == PSYNC_TSTRING)
|
||||
psync_lhash_update(hctx, row[i].str, row[i].length);
|
||||
psync_lhash_update(hctx, row, sizeof(psync_variant) * res->column_count);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
clock_gettime(CLOCK_REALTIME, &tm);
|
||||
psync_lhash_update(hctx, &tm, sizeof(tm));
|
||||
}
|
||||
|
|
@ -140,16 +140,16 @@ void prand_seed(unsigned char *seed, const void *addent, size_t aelen,
|
|||
unsigned char rnd[PSYNC_LHASH_DIGEST_LEN];
|
||||
clock_gettime(CLOCK_REALTIME, &tm);
|
||||
psync_lhash_update(&hctx, &tm, sizeof(tm));
|
||||
res = psync_sql_query_rdlock("SELECT * FROM setting ORDER BY RANDOM()");
|
||||
res = psql_query_rdlock("SELECT * FROM setting ORDER BY RANDOM()");
|
||||
load_sql(&hctx, res);
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT * FROM resolver ORDER BY RANDOM() LIMIT 50");
|
||||
load_sql(&hctx, res);
|
||||
psync_sql_statement(
|
||||
psql_statement(
|
||||
"REPLACE INTO setting (id, value) VALUES ('random', RANDOM())");
|
||||
clock_gettime(CLOCK_REALTIME, &tm);
|
||||
psync_lhash_update(&hctx, &tm, sizeof(tm));
|
||||
psync_sql_sync();
|
||||
psql_sync();
|
||||
clock_gettime(CLOCK_REALTIME, &tm);
|
||||
psync_lhash_update(&hctx, &tm, sizeof(tm));
|
||||
sqlite3_randomness(sizeof(rnd), rnd);
|
||||
|
|
@ -183,20 +183,20 @@ void prand_seed(unsigned char *seed, const void *addent, size_t aelen,
|
|||
memcpy(hashbin, seed, PSYNC_LHASH_DIGEST_LEN);
|
||||
rehash_cnt(hashbin, 2000);
|
||||
psync_binhex(hashhex, hashbin, PSYNC_LHASH_DIGEST_LEN);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES ('randomhash', ?)");
|
||||
psync_sql_bind_lstring(res, 1, hashhex, PSYNC_LHASH_DIGEST_HEXLEN);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_lstr(res, 1, hashhex, PSYNC_LHASH_DIGEST_HEXLEN);
|
||||
psql_run_free(res);
|
||||
rehash_cnt(hashbin, 2000);
|
||||
psync_binhex(hashhex, hashbin, PSYNC_LHASH_DIGEST_LEN);
|
||||
memcpy(nm, "randomhash", 10);
|
||||
nm[10] = hashhex[0];
|
||||
nm[11] = 0;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
psync_sql_bind_lstring(res, 1, nm, 11);
|
||||
psync_sql_bind_lstring(res, 2, hashhex, PSYNC_LHASH_DIGEST_HEXLEN);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_lstr(res, 1, nm, 11);
|
||||
psql_bind_lstr(res, 2, hashhex, PSYNC_LHASH_DIGEST_HEXLEN);
|
||||
psql_run_free(res);
|
||||
|
||||
pdbg_logf(D_NOTICE, "out");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,8 +207,8 @@ void psync_settings_init() {
|
|||
}
|
||||
free(defaultfs);
|
||||
free(defaultcache);
|
||||
res = psync_sql_query("SELECT id, value FROM setting");
|
||||
while ((row = psync_sql_fetch_rowstr(res))) {
|
||||
res = psql_query("SELECT id, value FROM setting");
|
||||
while ((row = psql_fetch_str(res))) {
|
||||
name = row[0];
|
||||
for (i = 0; i < ARRAY_SIZE(settings); i++)
|
||||
if (!strcmp(name, settings[i].name)) {
|
||||
|
|
@ -231,7 +231,7 @@ void psync_settings_init() {
|
|||
name, settings[i].type);
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
psync_settingid_t psync_setting_getid(const char *name) {
|
||||
|
|
@ -271,11 +271,11 @@ int psync_setting_set_bool(psync_settingid_t settingid, int value) {
|
|||
if (settings[settingid].fix_callback)
|
||||
settings[settingid].fix_callback(&value);
|
||||
settings[settingid].boolean = value;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
psync_sql_bind_string(res, 1, settings[settingid].name);
|
||||
psync_sql_bind_uint(res, 2, value);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_str(res, 1, settings[settingid].name);
|
||||
psql_bind_uint(res, 2, value);
|
||||
psql_run_free(res);
|
||||
if (settings[settingid].change_callback)
|
||||
settings[settingid].change_callback();
|
||||
return 0;
|
||||
|
|
@ -292,11 +292,11 @@ int psync_setting_set_uint(psync_settingid_t settingid, uint64_t value) {
|
|||
if (settings[settingid].fix_callback)
|
||||
settings[settingid].fix_callback(&value);
|
||||
settings[settingid].num = value;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
psync_sql_bind_string(res, 1, settings[settingid].name);
|
||||
psync_sql_bind_uint(res, 2, value);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_str(res, 1, settings[settingid].name);
|
||||
psql_bind_uint(res, 2, value);
|
||||
psql_run_free(res);
|
||||
if (settings[settingid].change_callback)
|
||||
settings[settingid].change_callback();
|
||||
return 0;
|
||||
|
|
@ -313,11 +313,11 @@ int psync_setting_set_int(psync_settingid_t settingid, int64_t value) {
|
|||
if (settings[settingid].fix_callback)
|
||||
settings[settingid].fix_callback(&value);
|
||||
settings[settingid].snum = value;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
psync_sql_bind_string(res, 1, settings[settingid].name);
|
||||
psync_sql_bind_int(res, 2, value);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_str(res, 1, settings[settingid].name);
|
||||
psql_bind_int(res, 2, value);
|
||||
psql_run_free(res);
|
||||
if (settings[settingid].change_callback)
|
||||
settings[settingid].change_callback();
|
||||
return 0;
|
||||
|
|
@ -337,11 +337,11 @@ int psync_setting_set_string(psync_settingid_t settingid, const char *value) {
|
|||
if (settings[settingid].fix_callback)
|
||||
settings[settingid].fix_callback(&newval);
|
||||
settings[settingid].str = newval;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
psync_sql_bind_string(res, 1, settings[settingid].name);
|
||||
psync_sql_bind_string(res, 2, value);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_str(res, 1, settings[settingid].name);
|
||||
psql_bind_str(res, 2, value);
|
||||
psql_run_free(res);
|
||||
if (settings[settingid].change_callback)
|
||||
settings[settingid].change_callback();
|
||||
psync_free_after_sec(oldval, 600);
|
||||
|
|
|
|||
|
|
@ -164,14 +164,14 @@ static struct addrinfo *addr_load(const char *host, const char *port) {
|
|||
const char *str;
|
||||
uint64_t i;
|
||||
size_t len;
|
||||
psync_sql_rdlock();
|
||||
res = psync_sql_query_nolock("SELECT COUNT(*), SUM(LENGTH(data)) FROM "
|
||||
psql_rdlock();
|
||||
res = psql_query_nolock("SELECT COUNT(*), SUM(LENGTH(data)) FROM "
|
||||
"resolver WHERE hostname=? AND port=?");
|
||||
psync_sql_bind_string(res, 1, host);
|
||||
psync_sql_bind_string(res, 2, port);
|
||||
if (!(row = psync_sql_fetch_rowint(res)) || row[0] == 0) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
psql_bind_str(res, 1, host);
|
||||
psql_bind_str(res, 2, port);
|
||||
if (!(row = psql_fetch_int(res)) || row[0] == 0) {
|
||||
psql_free(res);
|
||||
psql_rdunlock();
|
||||
return NULL;
|
||||
}
|
||||
ret = (struct addrinfo *)malloc(sizeof(struct addrinfo) * row[0] +
|
||||
|
|
@ -180,14 +180,14 @@ static struct addrinfo *addr_load(const char *host, const char *port) {
|
|||
for (i = 0; i < row[0] - 1; i++)
|
||||
ret[i].ai_next = &ret[i + 1];
|
||||
ret[i].ai_next = NULL;
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query_nolock(
|
||||
psql_free(res);
|
||||
res = psql_query_nolock(
|
||||
"SELECT family, socktype, protocol, data FROM resolver WHERE hostname=? "
|
||||
"AND port=? ORDER BY prio");
|
||||
psync_sql_bind_string(res, 1, host);
|
||||
psync_sql_bind_string(res, 2, port);
|
||||
psql_bind_str(res, 1, host);
|
||||
psql_bind_str(res, 2, port);
|
||||
i = 0;
|
||||
while ((vrow = psync_sql_fetch_row(res))) {
|
||||
while ((vrow = psql_fetch(res))) {
|
||||
ret[i].ai_family = psync_get_snumber(vrow[0]);
|
||||
ret[i].ai_socktype = psync_get_snumber(vrow[1]);
|
||||
ret[i].ai_protocol = psync_get_snumber(vrow[2]);
|
||||
|
|
@ -198,8 +198,8 @@ static struct addrinfo *addr_load(const char *host, const char *port) {
|
|||
memcpy(data, str, len);
|
||||
data += len;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
psql_free(res);
|
||||
psql_rdunlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -207,36 +207,36 @@ static void addr_save(const char *host, const char *port,
|
|||
struct addrinfo *addr) {
|
||||
psync_sql_res *res;
|
||||
uint64_t id;
|
||||
if (psync_sql_isrdlocked()) {
|
||||
if (psync_sql_tryupgradelock())
|
||||
if (psql_rdlocked()) {
|
||||
if (psql_tryupgradeLock())
|
||||
return;
|
||||
else
|
||||
pdbg_logf(D_NOTICE, "upgraded read to write lock to save data to DB");
|
||||
}
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"DELETE FROM resolver WHERE hostname=? AND port=?");
|
||||
psync_sql_bind_string(res, 1, host);
|
||||
psync_sql_bind_string(res, 2, port);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_bind_str(res, 1, host);
|
||||
psql_bind_str(res, 2, port);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare(
|
||||
"INSERT INTO resolver (hostname, port, prio, created, family, socktype, "
|
||||
"protocol, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_string(res, 1, host);
|
||||
psync_sql_bind_string(res, 2, port);
|
||||
psync_sql_bind_uint(res, 4, ptimer_time());
|
||||
psql_bind_str(res, 1, host);
|
||||
psql_bind_str(res, 2, port);
|
||||
psql_bind_uint(res, 4, ptimer_time());
|
||||
id = 0;
|
||||
do {
|
||||
psync_sql_bind_uint(res, 3, id++);
|
||||
psync_sql_bind_int(res, 5, addr->ai_family);
|
||||
psync_sql_bind_int(res, 6, addr->ai_socktype);
|
||||
psync_sql_bind_int(res, 7, addr->ai_protocol);
|
||||
psync_sql_bind_blob(res, 8, (char *)addr->ai_addr, addr->ai_addrlen);
|
||||
psync_sql_run(res);
|
||||
psql_bind_uint(res, 3, id++);
|
||||
psql_bind_int(res, 5, addr->ai_family);
|
||||
psql_bind_int(res, 6, addr->ai_socktype);
|
||||
psql_bind_int(res, 7, addr->ai_protocol);
|
||||
psql_bind_blob(res, 8, (char *)addr->ai_addr, addr->ai_addrlen);
|
||||
psql_run(res);
|
||||
addr = addr->ai_next;
|
||||
} while (addr);
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_free(res);
|
||||
psql_commit();
|
||||
}
|
||||
|
||||
static int connect_res(struct addrinfo *res) {
|
||||
|
|
|
|||
1425
pclsync/psql.c
1425
pclsync/psql.c
File diff suppressed because it is too large
Load Diff
168
pclsync/psql.h
168
pclsync/psql.h
|
|
@ -47,103 +47,103 @@ typedef const psync_variant *psync_variant_row;
|
|||
typedef int (*psync_list_builder_sql_callback)(psync_list_builder_t *, void *, psync_variant_row);
|
||||
typedef void (*psync_transaction_callback_t)(void *);
|
||||
|
||||
int psync_sql_connect(const char *db) PSYNC_NONNULL(1);
|
||||
int psync_sql_close();
|
||||
int psync_sql_reopen(const char *path);
|
||||
void psync_sql_checkpoint_lock();
|
||||
void psync_sql_checkpoint_unlock();
|
||||
int psql_connect(const char *db) PSYNC_NONNULL(1);
|
||||
int psql_close();
|
||||
int psql_reopen(const char *path);
|
||||
void psql_checkpt_lock();
|
||||
void psql_checkpt_unlock();
|
||||
|
||||
#if IS_DEBUG
|
||||
|
||||
#define psync_sql_trylock() psync_sql_do_trylock(__FILE__, __LINE__)
|
||||
#define psync_sql_lock() psync_sql_do_lock(__FILE__, __LINE__)
|
||||
#define psync_sql_rdlock() psync_sql_do_rdlock(__FILE__, __LINE__)
|
||||
#define psync_sql_statement(sql) psync_sql_do_statement(sql, __FILE__, __LINE__)
|
||||
#define psync_sql_start_transaction() psync_sql_do_start_transaction(__FILE__, __LINE__)
|
||||
#define psync_sql_query_nocache(sql) psync_sql_do_query_nocache(sql, __FILE__, __LINE__)
|
||||
#define psync_sql_query(sql) psync_sql_do_query(sql, __FILE__, __LINE__)
|
||||
#define psync_sql_query_rdlock_nocache(sql) psync_sql_do_query_rdlock_nocache(sql, __FILE__, __LINE__)
|
||||
#define psync_sql_query_rdlock(sql) psync_sql_do_query_rdlock(sql, __FILE__, __LINE__)
|
||||
#define psync_sql_query_nolock_nocache(sql) psync_sql_do_query_nolock_nocache(sql, __FILE__, __LINE__)
|
||||
#define psync_sql_query_nolock(sql) psync_sql_do_query_nolock(sql, __FILE__, __LINE__)
|
||||
#define psync_sql_prep_statement_nocache(sql) psync_sql_do_prep_statement_nocache(sql, __FILE__, __LINE__)
|
||||
#define psync_sql_prep_statement(sql) psync_sql_do_prep_statement(sql, __FILE__, __LINE__)
|
||||
#define psql_trylock() psql_do_trylock(__FILE__, __LINE__)
|
||||
#define psql_lock() psql_do_lock(__FILE__, __LINE__)
|
||||
#define psql_rdlock() psql_do_rdlock(__FILE__, __LINE__)
|
||||
#define psql_statement(sql) psql_do_statement(sql, __FILE__, __LINE__)
|
||||
#define psql_start() psql_do_start_transaction(__FILE__, __LINE__)
|
||||
#define psql_query_nocache(sql) psql_do_query_nocache(sql, __FILE__, __LINE__)
|
||||
#define psql_query(sql) psql_do_query(sql, __FILE__, __LINE__)
|
||||
#define psql_rdlock_nocache(sql) psql_do_query_rdlock_nocache(sql, __FILE__, __LINE__)
|
||||
#define psql_query_rdlock(sql) psql_do_query_rdlock(sql, __FILE__, __LINE__)
|
||||
#define psql_query_nolock_nocache(sql) psql_do_query_nolock_nocache(sql, __FILE__, __LINE__)
|
||||
#define psql_query_nolock(sql) psql_do_query_nolock(sql, __FILE__, __LINE__)
|
||||
#define psql_prepare_nocache(sql) psql_do_prepare_nocache(sql, __FILE__, __LINE__)
|
||||
#define psql_prepare(sql) psql_do_prepare(sql, __FILE__, __LINE__)
|
||||
void psql_dump_locks();
|
||||
|
||||
int psync_sql_do_trylock(const char *file, unsigned line);
|
||||
void psync_sql_do_lock(const char *file, unsigned line);
|
||||
void psync_sql_do_rdlock(const char *file, unsigned line);
|
||||
int psync_sql_do_statement(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
int psync_sql_do_start_transaction(const char *file, unsigned line);
|
||||
psync_sql_res *psync_sql_do_query_nocache(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_do_query(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_do_query_rdlock_nocache(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_do_query_rdlock(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_do_query_nolock_nocache(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_do_query_nolock(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_do_prep_statement_nocache(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_do_prep_statement(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
void psync_sql_dump_locks();
|
||||
int psql_do_trylock(const char *file, unsigned line);
|
||||
void psql_do_lock(const char *file, unsigned line);
|
||||
void psql_do_rdlock(const char *file, unsigned line);
|
||||
int psql_do_statement(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
int psql_do_start_transaction(const char *file, unsigned line);
|
||||
psync_sql_res *psql_do_query_nocache(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_do_query(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_do_query_rdlock_nocache(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_do_query_rdlock(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_do_query_nolock_nocache(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_do_query_nolock(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_do_prepare_nocache(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_do_prepare(const char *sql, const char *file, unsigned line) PSYNC_NONNULL(1);
|
||||
|
||||
#else
|
||||
|
||||
int psync_sql_trylock();
|
||||
void psync_sql_lock();
|
||||
void psync_sql_rdlock();
|
||||
int psync_sql_statement(const char *sql) PSYNC_NONNULL(1);
|
||||
int psync_sql_start_transaction();
|
||||
int psql_trylock();
|
||||
void psql_lock();
|
||||
void psql_rdlock();
|
||||
int psql_statement(const char *sql) PSYNC_NONNULL(1);
|
||||
int psql_start();
|
||||
|
||||
psync_sql_res *psync_sql_query_nocache(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_query(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_query_rdlock_nocache(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_query_rdlock(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_query_nolock(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_query_nolock_nocache(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_prep_statement(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psync_sql_prep_statement_nocache(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_query_nocache(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_query(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_rdlock_nocache(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_query_rdlock(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_query_nolock(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_query_nolock_nocache(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_prepare(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_sql_res *psql_prepare_nocache(const char *sql) PSYNC_NONNULL(1);
|
||||
|
||||
#endif
|
||||
|
||||
void psync_sql_unlock();
|
||||
void psync_sql_rdunlock();
|
||||
int psync_sql_has_waiters();
|
||||
int psync_sql_isrdlocked();
|
||||
int psync_sql_islocked();
|
||||
int psync_sql_tryupgradelock();
|
||||
int psync_sql_sync();
|
||||
int psync_sql_commit_transaction();
|
||||
int psync_sql_rollback_transaction();
|
||||
void psql_unlock();
|
||||
void psql_rdunlock();
|
||||
int psql_waiting();
|
||||
int psql_rdlocked();
|
||||
int psql_locked();
|
||||
int psql_tryupgradeLock();
|
||||
int psql_sync();
|
||||
int psql_commit();
|
||||
int psql_rollback();
|
||||
|
||||
void psync_sql_transation_add_callbacks(psync_transaction_callback_t commit_callback, psync_transaction_callback_t rollback_callback, void *ptr);
|
||||
void psql_translation_add_cb(psync_transaction_callback_t commit_callback, psync_transaction_callback_t rollback_callback, void *ptr);
|
||||
|
||||
char *psync_sql_cellstr(const char *sql) PSYNC_NONNULL(1);
|
||||
int64_t psync_sql_cellint(const char *sql, int64_t dflt) PSYNC_NONNULL(1);
|
||||
char **psync_sql_rowstr(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_variant *psync_sql_row(const char *sql) PSYNC_NONNULL(1);
|
||||
int psync_sql_reset(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
int psync_sql_run(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
int psync_sql_run_free(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
int psync_sql_run_free_nocache(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
void psync_sql_bind_uint(psync_sql_res *res, int n, uint64_t val) PSYNC_NONNULL(1);
|
||||
void psync_sql_bind_int(psync_sql_res *res, int n, int64_t val) PSYNC_NONNULL(1);
|
||||
void psync_sql_bind_double(psync_sql_res *res, int n, double val) PSYNC_NONNULL(1);
|
||||
void psync_sql_bind_string(psync_sql_res *res, int n, const char *str) PSYNC_NONNULL(1);
|
||||
void psync_sql_bind_lstring(psync_sql_res *res, int n, const char *str, size_t len) PSYNC_NONNULL(1);
|
||||
void psync_sql_bind_blob(psync_sql_res *res, int n, const char *str, size_t len) PSYNC_NONNULL(1);
|
||||
void psync_sql_bind_null(psync_sql_res *res, int n) PSYNC_NONNULL(1);
|
||||
void psync_sql_free_result(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
void psync_sql_free_result_nocache(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
psync_variant_row psync_sql_fetch_row(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
psync_str_row psync_sql_fetch_rowstr(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
psync_uint_row psync_sql_fetch_rowint(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
psync_full_result_int *psync_sql_fetchall_int(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
uint32_t psync_sql_affected_rows() PSYNC_PURE;
|
||||
uint64_t psync_sql_insertid() PSYNC_PURE;
|
||||
void psync_list_bulder_add_sql(psync_list_builder_t *builder, psync_sql_res *res, psync_list_builder_sql_callback callback);
|
||||
uint64_t psync_err_number_expected(const char *file, const char *function, int unsigned line, const psync_variant *v) PSYNC_COLD;
|
||||
const char *psync_err_string_expected(const char *file, const char *function, int unsigned line, const psync_variant *v) PSYNC_COLD;
|
||||
const char *psync_lstring_expected(const char *file, const char *function, int unsigned line, const psync_variant *v, size_t *len) PSYNC_NONNULL(4, 5);
|
||||
double psync_err_real_expected(const char *file, const char *function, int unsigned line, const psync_variant *v) PSYNC_COLD;
|
||||
void psync_try_free_memory();
|
||||
char *psql_cellstr(const char *sql) PSYNC_NONNULL(1);
|
||||
int64_t psql_cellint(const char *sql, int64_t dflt) PSYNC_NONNULL(1);
|
||||
char **psql_rowstr(const char *sql) PSYNC_NONNULL(1);
|
||||
psync_variant *psql_row(const char *sql) PSYNC_NONNULL(1);
|
||||
int psql_reset(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
int psql_run(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
int psql_run_free(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
int psql_run_free_nocache(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
void psql_bind_uint(psync_sql_res *res, int n, uint64_t val) PSYNC_NONNULL(1);
|
||||
void psql_bind_int(psync_sql_res *res, int n, int64_t val) PSYNC_NONNULL(1);
|
||||
void psql_bind_double(psync_sql_res *res, int n, double val) PSYNC_NONNULL(1);
|
||||
void psql_bind_str(psync_sql_res *res, int n, const char *str) PSYNC_NONNULL(1);
|
||||
void psql_bind_lstr(psync_sql_res *res, int n, const char *str, size_t len) PSYNC_NONNULL(1);
|
||||
void psql_bind_blob(psync_sql_res *res, int n, const char *str, size_t len) PSYNC_NONNULL(1);
|
||||
void psql_bind_null(psync_sql_res *res, int n) PSYNC_NONNULL(1);
|
||||
void psql_free(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
void psql_free_nocache(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
psync_variant_row psql_fetch(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
psync_str_row psql_fetch_str(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
psync_uint_row psql_fetch_int(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
psync_full_result_int *psql_fetchall_int(psync_sql_res *res) PSYNC_NONNULL(1);
|
||||
uint32_t psql_affected() PSYNC_PURE;
|
||||
uint64_t psql_insertid() PSYNC_PURE;
|
||||
void psql_list_add(psync_list_builder_t *builder, psync_sql_res *res, psync_list_builder_sql_callback callback);
|
||||
uint64_t psql_expect_num(const char *file, const char *function, int unsigned line, const psync_variant *v) PSYNC_COLD;
|
||||
const char *psql_expect_str(const char *file, const char *function, int unsigned line, const psync_variant *v) PSYNC_COLD;
|
||||
const char *psql_lstring_expected(const char *file, const char *function, int unsigned line, const psync_variant *v, size_t *len) PSYNC_NONNULL(4, 5);
|
||||
double psql_expect_real(const char *file, const char *function, int unsigned line, const psync_variant *v) PSYNC_COLD;
|
||||
void psql_try_free();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,11 +153,11 @@ static void proc_recalc_upload() {
|
|||
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);
|
||||
psql_cellint("SELECT value FROM setting WHERE id='runstatus'", 0);
|
||||
if (statuses[PSTATUS_TYPE_RUN] < PSTATUS_RUN_RUN ||
|
||||
statuses[PSTATUS_TYPE_RUN] > PSTATUS_RUN_STOP) {
|
||||
statuses[PSTATUS_TYPE_RUN] = PSTATUS_RUN_RUN;
|
||||
psync_sql_statement(
|
||||
psql_statement(
|
||||
"REPLACE INTO setting (id, value) VALUES ('runstatus', " NTO_STR(
|
||||
PSTATUS_RUN_RUN) ")");
|
||||
}
|
||||
|
|
@ -169,17 +169,17 @@ void pstatus_init() {
|
|||
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 "
|
||||
res = psql_query_rdlock("SELECT COUNT(*), SUM(f.size) FROM task t, file "
|
||||
"f WHERE t.type=? AND t.itemid=f.id");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
psync_status.filestodownload = row[0];
|
||||
psync_status.bytestodownload = row[1];
|
||||
} else {
|
||||
psync_status.filestodownload = 0;
|
||||
psync_status.bytestodownload = 0;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (!psync_status.filestodownload) {
|
||||
psync_status.downloadspeed = 0;
|
||||
}
|
||||
|
|
@ -195,24 +195,24 @@ void pstatus_upload_recalc() {
|
|||
struct stat st;
|
||||
uint64_t bytestou;
|
||||
uint32_t filestou;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT COUNT(*), SUM(f.size) FROM task t, localfile f WHERE t.type=? "
|
||||
"AND t.localitemid=f.id");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
filestou = row[0];
|
||||
bytestou = row[1];
|
||||
} else {
|
||||
filestou = 0;
|
||||
bytestou = 0;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
fscpath = psync_setting_get_string(_PS(fscachepath));
|
||||
res = psync_sql_query_rdlock("SELECT id FROM fstask WHERE type IN (" NTO_STR(
|
||||
res = psql_query_rdlock("SELECT id FROM fstask WHERE type IN (" NTO_STR(
|
||||
PSYNC_FS_TASK_CREAT) ", " NTO_STR(PSYNC_FS_TASK_MODIFY) ") AND text1 NOT "
|
||||
"LIKE '.%'"
|
||||
" AND status!=3");
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
while ((row = psql_fetch_int(res))) {
|
||||
psync_binhex(fileidhex, &row[0], sizeof(psync_fsfileid_t));
|
||||
fileidhex[sizeof(psync_fsfileid_t)] = 'd';
|
||||
fileidhex[sizeof(psync_fsfileid_t) + 1] = 0;
|
||||
|
|
@ -224,7 +224,7 @@ void pstatus_upload_recalc() {
|
|||
}
|
||||
free(filename);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_status.filestoupload = filestou;
|
||||
psync_status.bytestoupload = bytestou;
|
||||
if (!filestou)
|
||||
|
|
|
|||
|
|
@ -150,20 +150,20 @@ int psyncer_dl_has_folder(psync_folderid_t folderid) {
|
|||
|
||||
void psyncer_folder_inc_tasks(psync_folderid_t lfolderid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE localfolder SET taskcnt=taskcnt+1 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, lfolderid);
|
||||
psync_sql_run_free(res);
|
||||
pdbg_assertw(psync_sql_affected_rows() == 1);
|
||||
psql_bind_uint(res, 1, lfolderid);
|
||||
psql_run_free(res);
|
||||
pdbg_assertw(psql_affected() == 1);
|
||||
}
|
||||
|
||||
void psyncer_folder_dec_tasks(psync_folderid_t lfolderid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE localfolder SET taskcnt=taskcnt+1 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, lfolderid);
|
||||
psync_sql_run_free(res);
|
||||
pdbg_assertw(psync_sql_affected_rows() == 1);
|
||||
psql_bind_uint(res, 1, lfolderid);
|
||||
psql_run_free(res);
|
||||
pdbg_assertw(psql_affected() == 1);
|
||||
}
|
||||
|
||||
psync_folderid_t psyncer_db_folder_create(
|
||||
|
|
@ -176,16 +176,16 @@ psync_folderid_t psyncer_db_folder_create(
|
|||
char *vname;
|
||||
pdbg_logf(D_NOTICE, "creating local folder in db as %lu/%s for folderid %lu",
|
||||
(unsigned long)localparentfolderid, name, (unsigned long)folderid);
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id FROM localfolder WHERE syncid=? AND folderid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, folderid);
|
||||
row = psql_fetch_int(res);
|
||||
if (row)
|
||||
lfolderid = row[0];
|
||||
else
|
||||
lfolderid = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (lfolderid)
|
||||
return lfolderid;
|
||||
vname = NULL;
|
||||
|
|
@ -198,27 +198,27 @@ psync_folderid_t psyncer_db_folder_create(
|
|||
}
|
||||
if (vname)
|
||||
name = vname;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT OR IGNORE INTO localfolder (localparentfolderid, folderid, "
|
||||
"syncid, flags, taskcnt, name) VALUES (?, ?, ?, 0, 1, ?)");
|
||||
psync_sql_bind_uint(res, 1, localparentfolderid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
psync_sql_bind_uint(res, 3, syncid);
|
||||
psync_sql_bind_string(res, 4, name);
|
||||
psync_sql_run(res);
|
||||
if (psync_sql_affected_rows() > 0) {
|
||||
lfolderid = psync_sql_insertid();
|
||||
psync_sql_free_result(res);
|
||||
psql_bind_uint(res, 1, localparentfolderid);
|
||||
psql_bind_uint(res, 2, folderid);
|
||||
psql_bind_uint(res, 3, syncid);
|
||||
psql_bind_str(res, 4, name);
|
||||
psql_run(res);
|
||||
if (psql_affected() > 0) {
|
||||
lfolderid = psql_insertid();
|
||||
psql_free(res);
|
||||
free(vname);
|
||||
return lfolderid;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query("SELECT id, folderid FROM localfolder WHERE "
|
||||
psql_free(res);
|
||||
res = psql_query("SELECT id, folderid FROM localfolder WHERE "
|
||||
"localparentfolderid=? AND syncid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, localparentfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_string(res, 3, name);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, localparentfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_str(res, 3, name);
|
||||
row = psql_fetch_int(res);
|
||||
if (row) {
|
||||
lfolderid = row[0];
|
||||
dbfolderid = row[1];
|
||||
|
|
@ -227,16 +227,16 @@ psync_folderid_t psyncer_db_folder_create(
|
|||
dbfolderid = 0;
|
||||
pdbg_logf(D_ERROR, "local folder %s not found in the database", name);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (lfolderid && dbfolderid != folderid) {
|
||||
pdbg_logf(D_NOTICE,
|
||||
"local folder %lu does not have folderid associated, setting to %lu",
|
||||
(unsigned long)lfolderid, (unsigned long)folderid);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE localfolder SET folderid=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, lfolderid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, lfolderid);
|
||||
psql_bind_uint(res, 2, folderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
psyncer_folder_inc_tasks(lfolderid);
|
||||
free(vname);
|
||||
|
|
@ -252,18 +252,18 @@ void psyncer_dl_folder_add(psync_syncid_t syncid,
|
|||
const char *name;
|
||||
psync_folderid_t cfolderid, clfolderid;
|
||||
res =
|
||||
psync_sql_prep_statement("REPLACE INTO syncedfolder (syncid, folderid, "
|
||||
psql_prepare("REPLACE INTO syncedfolder (syncid, folderid, "
|
||||
"localfolderid, synctype) VALUES (?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
psync_sql_bind_uint(res, 3, lfoiderid);
|
||||
psync_sql_bind_uint(res, 4, synctype);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, folderid);
|
||||
psql_bind_uint(res, 3, lfoiderid);
|
||||
psql_bind_uint(res, 4, synctype);
|
||||
psql_run_free(res);
|
||||
psyncer_dl_queue_add(folderid);
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id, permissions, name FROM folder WHERE parentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
while ((row = psql_fetch(res))) {
|
||||
if (psync_get_number(row[1]) & PSYNC_PERM_READ) {
|
||||
name = psync_get_string(row[2]);
|
||||
if (psync_is_name_to_ignore(name))
|
||||
|
|
@ -276,17 +276,17 @@ void psyncer_dl_folder_add(psync_syncid_t syncid,
|
|||
clfolderid /*, path*/);
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query("SELECT id, name FROM file WHERE parentfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
psql_free(res);
|
||||
res = psql_query("SELECT id, name FROM file WHERE parentfolderid=?");
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
while ((row = psql_fetch(res))) {
|
||||
name = psync_get_string(row[1]);
|
||||
if (psync_is_name_to_ignore(name))
|
||||
continue;
|
||||
ptask_download_q(syncid, psync_get_number(row[0]), lfoiderid,
|
||||
name);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
static void psync_sync_newsyncedfolder(psync_syncid_t syncid) {
|
||||
|
|
@ -295,38 +295,38 @@ static void psync_sync_newsyncedfolder(psync_syncid_t syncid) {
|
|||
uint64_t folderid;
|
||||
psync_synctype_t synctype;
|
||||
char *localpath;
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_query("SELECT folderid, synctype, localpath FROM syncfolder "
|
||||
psql_start();
|
||||
res = psql_query("SELECT folderid, synctype, localpath FROM syncfolder "
|
||||
"WHERE id=? AND flags=0");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
row = psql_fetch(res);
|
||||
if (pdbg_unlikely(!row)) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rollback_transaction();
|
||||
psql_free(res);
|
||||
psql_rollback();
|
||||
return;
|
||||
}
|
||||
folderid = psync_get_number(row[0]);
|
||||
synctype = psync_get_number(row[1]);
|
||||
localpath =
|
||||
psync_strndup(psync_get_string(row[2]), strlen(psync_get_string(row[2])));
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (synctype & PSYNC_DOWNLOAD_ONLY) {
|
||||
psyncer_dl_folder_add(syncid, synctype, folderid, 0);
|
||||
} else {
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO syncedfolder (syncid, folderid, localfolderid, synctype) "
|
||||
"VALUES (?, ?, 0, ?)");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, folderid);
|
||||
psync_sql_bind_uint(res, 3, synctype);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, folderid);
|
||||
psql_bind_uint(res, 3, synctype);
|
||||
psql_run_free(res);
|
||||
}
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE syncfolder SET flags=1 WHERE flags=0 AND id=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_run_free(res);
|
||||
if (pdbg_likely(psync_sql_affected_rows())) {
|
||||
if (!psync_sql_commit_transaction()) {
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_run_free(res);
|
||||
if (pdbg_likely(psql_affected())) {
|
||||
if (!psql_commit()) {
|
||||
if (synctype & PSYNC_UPLOAD_ONLY)
|
||||
psync_wake_localscan();
|
||||
if (synctype & PSYNC_DOWNLOAD_ONLY) {
|
||||
|
|
@ -338,7 +338,7 @@ static void psync_sync_newsyncedfolder(psync_syncid_t syncid) {
|
|||
psync_restat_sync_folders_add(syncid, localpath);
|
||||
}
|
||||
} else
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
free(localpath);
|
||||
}
|
||||
|
||||
|
|
@ -355,20 +355,20 @@ void psyncer_create(psync_syncid_t syncid) {
|
|||
|
||||
static void psync_syncer_thread() {
|
||||
int64_t syncid;
|
||||
psync_sql_lock();
|
||||
if (psync_sql_cellint("SELECT COUNT(*) FROM task", -1) == 0)
|
||||
psync_sql_statement("DELETE FROM syncfolder WHERE folderid IS NULL");
|
||||
while ((syncid = psync_sql_cellint("SELECT id FROM syncfolder WHERE flags=0",
|
||||
psql_lock();
|
||||
if (psql_cellint("SELECT COUNT(*) FROM task", -1) == 0)
|
||||
psql_statement("DELETE FROM syncfolder WHERE folderid IS NULL");
|
||||
while ((syncid = psql_cellint("SELECT id FROM syncfolder WHERE flags=0",
|
||||
-1)) != -1)
|
||||
psync_sync_newsyncedfolder(syncid);
|
||||
psync_sql_unlock();
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
static void delete_delayed_sync(uint64_t id) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("DELETE FROM syncfolderdelayed WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, id);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM syncfolderdelayed WHERE id=?");
|
||||
psql_bind_uint(res, 1, id);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
int psyncer_str_has_prefix(const char *str1, const char *str2) {
|
||||
|
|
@ -423,9 +423,9 @@ void psyncer_check_delayed() {
|
|||
psync_folderid_t folderid;
|
||||
int unsigned mbedtls_md;
|
||||
re:
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id, localpath, remotepath, synctype FROM syncfolderdelayed");
|
||||
while ((row = psync_sql_fetch_row(res))) {
|
||||
while ((row = psql_fetch(res))) {
|
||||
id = psync_get_number(row[0]);
|
||||
localpath = (char *)psync_get_string(row[1]);
|
||||
remotepath = (char *)psync_get_string(row[2]);
|
||||
|
|
@ -444,8 +444,8 @@ re:
|
|||
continue;
|
||||
}
|
||||
mbedtls_md = 0;
|
||||
res2 = psync_sql_query("SELECT localpath FROM syncfolder");
|
||||
while ((srow = psync_sql_fetch_rowstr(res2)))
|
||||
res2 = psql_query("SELECT localpath FROM syncfolder");
|
||||
while ((srow = psql_fetch_str(res2)))
|
||||
if (psyncer_str_has_prefix(srow[0], localpath)) {
|
||||
pdbg_logf(
|
||||
D_WARNING,
|
||||
|
|
@ -458,7 +458,7 @@ re:
|
|||
localpath, remotepath, srow[0]);
|
||||
mbedtls_md = 1;
|
||||
}
|
||||
psync_sql_free_result(res2);
|
||||
psql_free(res2);
|
||||
if (mbedtls_md) {
|
||||
delete_delayed_sync(id);
|
||||
continue;
|
||||
|
|
@ -466,7 +466,7 @@ re:
|
|||
|
||||
localpath = psync_strdup(localpath);
|
||||
remotepath = psync_strdup(remotepath);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
|
||||
folderid = pfolder_id_create(remotepath);
|
||||
if (unlikely(folderid == PSYNC_INVALID_FOLDERID)) {
|
||||
|
|
@ -479,54 +479,54 @@ re:
|
|||
} else
|
||||
return;
|
||||
}
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
delete_delayed_sync(id);
|
||||
stmt = psync_sql_query_nolock("SELECT id FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(stmt, 1, folderid);
|
||||
urow = psync_sql_fetch_rowint(stmt);
|
||||
psync_sql_free_result(stmt);
|
||||
stmt = psql_query_nolock("SELECT id FROM folder WHERE id=?");
|
||||
psql_bind_uint(stmt, 1, folderid);
|
||||
urow = psql_fetch_int(stmt);
|
||||
psql_free(stmt);
|
||||
if (!urow) {
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
free(localpath);
|
||||
free(remotepath);
|
||||
goto re;
|
||||
}
|
||||
stmt = psync_sql_prep_statement(
|
||||
stmt = psql_prepare(
|
||||
"INSERT OR IGNORE INTO syncfolder (folderid, localpath, synctype, "
|
||||
"flags, inode, deviceid) VALUES (?, ?, ?, 0, ?, ?)");
|
||||
psync_sql_bind_uint(stmt, 1, folderid);
|
||||
psync_sql_bind_string(stmt, 2, localpath);
|
||||
psync_sql_bind_uint(stmt, 3, synctype);
|
||||
psync_sql_bind_uint(stmt, 4, pfile_stat_inode(&st));
|
||||
psync_sql_bind_uint(stmt, 5, pfile_stat_device(&st));
|
||||
psync_sql_run(stmt);
|
||||
if (pdbg_likely(psync_sql_affected_rows()))
|
||||
syncid = psync_sql_insertid();
|
||||
psql_bind_uint(stmt, 1, folderid);
|
||||
psql_bind_str(stmt, 2, localpath);
|
||||
psql_bind_uint(stmt, 3, synctype);
|
||||
psql_bind_uint(stmt, 4, pfile_stat_inode(&st));
|
||||
psql_bind_uint(stmt, 5, pfile_stat_device(&st));
|
||||
psql_run(stmt);
|
||||
if (pdbg_likely(psql_affected()))
|
||||
syncid = psql_insertid();
|
||||
else
|
||||
syncid = -1;
|
||||
psync_sql_free_result(stmt);
|
||||
psql_free(stmt);
|
||||
free(localpath);
|
||||
free(remotepath);
|
||||
if (!psync_sql_commit_transaction() && syncid != -1) {
|
||||
if (!psql_commit() && syncid != -1) {
|
||||
ppathstatus_reload_syncs();
|
||||
psyncer_create(syncid);
|
||||
goto re;
|
||||
}
|
||||
return;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
void psyncer_init() {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT folderid FROM syncedfolder WHERE synctype&" NTO_STR(
|
||||
PSYNC_DOWNLOAD_ONLY) "=" NTO_STR(PSYNC_DOWNLOAD_ONLY));
|
||||
pthread_mutex_lock(&sync_down_mutex);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
while ((row = psql_fetch_int(res)))
|
||||
psync_add_folder_to_downloadlist_locked(row[0]);
|
||||
pthread_mutex_unlock(&sync_down_mutex);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
prun_thread("syncer", psync_syncer_thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ typedef struct {
|
|||
|
||||
PSYNC_THREAD const char *psync_thread_name = "no name";
|
||||
|
||||
extern int psync_recache_contacts;
|
||||
|
||||
const char *psync_database = NULL;
|
||||
|
||||
static int psync_libstate = 0;
|
||||
|
|
@ -173,13 +175,13 @@ int psync_init() {
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
if (psync_sql_connect(psync_database)) {
|
||||
if (psql_connect(psync_database)) {
|
||||
if (IS_DEBUG)
|
||||
pthread_mutex_unlock(&psync_libstate_mutex);
|
||||
psync_error = PERROR_DATABASE_OPEN;
|
||||
return -1;
|
||||
}
|
||||
psync_sql_statement("UPDATE task SET inprogress=0 WHERE inprogress=1");
|
||||
psql_statement("UPDATE task SET inprogress=0 WHERE inprogress=1");
|
||||
ptimer_init();
|
||||
if (pdbg_unlikely(pssl_init())) {
|
||||
if (IS_DEBUG)
|
||||
|
|
@ -261,21 +263,21 @@ void psync_destroy() {
|
|||
ptask_stop_async();
|
||||
ptimer_wake();
|
||||
ptimer_notify_exception();
|
||||
psync_sql_sync();
|
||||
psql_sync();
|
||||
psys_sleep_milliseconds(20);
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
pcache_clean();
|
||||
psync_sql_close();
|
||||
psql_close();
|
||||
}
|
||||
|
||||
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'");
|
||||
return psql_cellstr("SELECT value FROM setting WHERE id='username'");
|
||||
}
|
||||
|
||||
static void clear_db(int save) {
|
||||
psync_sql_statement("DELETE FROM setting WHERE id IN ('pass', 'auth')");
|
||||
psql_statement("DELETE FROM setting WHERE id IN ('pass', 'auth')");
|
||||
psync_setting_set_bool(_PS(saveauth), save);
|
||||
}
|
||||
|
||||
|
|
@ -335,7 +337,7 @@ void psync_logout(uint32_t auth_status, int doinvauth) {
|
|||
tfa = 0;
|
||||
pdbg_logf(D_NOTICE, "logout");
|
||||
|
||||
psync_sql_statement("DELETE FROM setting WHERE id IN ('pass', 'auth', 'saveauth')");
|
||||
psql_statement("DELETE FROM setting WHERE id IN ('pass', 'auth', 'saveauth')");
|
||||
if (doinvauth) {
|
||||
psync_invalidate_auth(psync_my_auth);
|
||||
}
|
||||
|
|
@ -442,7 +444,7 @@ void psync_unlink() {
|
|||
int ret;
|
||||
char *errMsg;
|
||||
|
||||
deviceid = psync_sql_cellstr("SELECT value FROM setting WHERE id='deviceid'");
|
||||
deviceid = psql_cellstr("SELECT value FROM setting WHERE id='deviceid'");
|
||||
pdbg_logf(D_NOTICE, "unlink");
|
||||
|
||||
pdiff_lock();
|
||||
|
|
@ -461,15 +463,15 @@ void psync_unlink() {
|
|||
psync_set_apiserver(PSYNC_API_HOST, PSYNC_LOCATIONID_DEFAULT);
|
||||
psys_sleep_milliseconds(20);
|
||||
psync_stop_localscan();
|
||||
psync_sql_checkpoint_lock();
|
||||
psql_checkpt_lock();
|
||||
pstatus_set(PSTATUS_TYPE_ONLINE, PSTATUS_ONLINE_CONNECTING);
|
||||
pstatus_set(PSTATUS_TYPE_AUTH, PSTATUS_AUTH_REQUIRED);
|
||||
pstatus_set(PSTATUS_TYPE_RUN, PSTATUS_RUN_STOP);
|
||||
ptimer_notify_exception();
|
||||
psync_sql_lock();
|
||||
psql_lock();
|
||||
pdbg_logf(D_NOTICE, "clearing database, locked");
|
||||
pcache_clean();
|
||||
ret = psync_sql_close();
|
||||
ret = psql_close();
|
||||
pfile_delete(psync_database);
|
||||
if (ret) {
|
||||
free(deviceid);
|
||||
|
|
@ -477,11 +479,11 @@ void psync_unlink() {
|
|||
exit(1);
|
||||
}
|
||||
ppagecache_clean();
|
||||
psync_sql_connect(psync_database);
|
||||
psql_connect(psync_database);
|
||||
if (deviceid) {
|
||||
res = psync_sql_prep_statement("REPLACE INTO setting (id, value) VALUES ('deviceid', ?)");
|
||||
psync_sql_bind_string(res, 1, deviceid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("REPLACE INTO setting (id, value) VALUES ('deviceid', ?)");
|
||||
psql_bind_str(res, 1, deviceid);
|
||||
psql_run_free(res);
|
||||
free(deviceid);
|
||||
}
|
||||
pthread_mutex_lock(&psync_my_auth_mutex);
|
||||
|
|
@ -496,8 +498,8 @@ void psync_unlink() {
|
|||
psync_fs_clean_tasks();
|
||||
ppathstatus_init();
|
||||
psyncer_dl_queue_clear();
|
||||
psync_sql_unlock();
|
||||
psync_sql_checkpoint_unlock();
|
||||
psql_unlock();
|
||||
psql_checkpt_unlock();
|
||||
psync_settings_reset();
|
||||
pcache_clean();
|
||||
pnotify_clean();
|
||||
|
|
@ -685,30 +687,30 @@ psync_syncid_t psync_add_sync_by_folderid(const char *localpath,
|
|||
}
|
||||
free(syncmp);
|
||||
}
|
||||
res = psync_sql_query("SELECT localpath FROM syncfolder");
|
||||
res = psql_query("SELECT localpath FROM syncfolder");
|
||||
if (pdbg_unlikely(!res))
|
||||
return_isyncid(PERROR_DATABASE_ERROR);
|
||||
while ((srow = psync_sql_fetch_rowstr(res)))
|
||||
while ((srow = psql_fetch_str(res)))
|
||||
if (psyncer_str_has_prefix(srow[0], localpath)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return_isyncid(PERROR_PARENT_OR_SUBFOLDER_ALREADY_SYNCING);
|
||||
} else if (!strcmp(srow[0], localpath)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return_isyncid(PERROR_FOLDER_ALREADY_SYNCING);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (folderid) {
|
||||
res = psync_sql_query("SELECT permissions FROM folder WHERE id=?");
|
||||
res = psql_query("SELECT permissions FROM folder WHERE id=?");
|
||||
if (pdbg_unlikely(!res))
|
||||
return_isyncid(PERROR_DATABASE_ERROR);
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
row = psql_fetch_int(res);
|
||||
if (pdbg_unlikely(!row)) {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return_isyncid(PERROR_REMOTE_FOLDER_NOT_FOUND);
|
||||
}
|
||||
perms = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
} else
|
||||
perms = PSYNC_PERM_ALL;
|
||||
if (pdbg_unlikely((synctype & PSYNC_DOWNLOAD_ONLY &&
|
||||
|
|
@ -716,25 +718,25 @@ psync_syncid_t psync_add_sync_by_folderid(const char *localpath,
|
|||
(synctype & PSYNC_UPLOAD_ONLY &&
|
||||
(perms & PSYNC_PERM_WRITE) != PSYNC_PERM_WRITE)))
|
||||
return_isyncid(PERROR_REMOTE_FOLDER_ACC_DENIED);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT OR IGNORE INTO syncfolder (folderid, localpath, synctype, flags, "
|
||||
"inode, deviceid) VALUES (?, ?, ?, 0, ?, ?)");
|
||||
if (pdbg_unlikely(!res))
|
||||
return_isyncid(PERROR_DATABASE_ERROR);
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_string(res, 2, localpath);
|
||||
psync_sql_bind_uint(res, 3, synctype);
|
||||
psync_sql_bind_uint(res, 4, pfile_stat_inode(&st));
|
||||
psync_sql_bind_uint(res, 5, pfile_stat_device(&st));
|
||||
psync_sql_run(res);
|
||||
if (pdbg_likely(psync_sql_affected_rows()))
|
||||
ret = psync_sql_insertid();
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_str(res, 2, localpath);
|
||||
psql_bind_uint(res, 3, synctype);
|
||||
psql_bind_uint(res, 4, pfile_stat_inode(&st));
|
||||
psql_bind_uint(res, 5, pfile_stat_device(&st));
|
||||
psql_run(res);
|
||||
if (pdbg_likely(psql_affected()))
|
||||
ret = psql_insertid();
|
||||
else
|
||||
ret = PSYNC_INVALID_SYNCID;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (ret == PSYNC_INVALID_SYNCID)
|
||||
return_isyncid(PERROR_FOLDER_ALREADY_SYNCING);
|
||||
psync_sql_sync();
|
||||
psql_sync();
|
||||
ppathstatus_reload_syncs();
|
||||
psyncer_create(ret);
|
||||
return ret;
|
||||
|
|
@ -764,13 +766,13 @@ int psync_add_sync_by_path_delayed(const char *localpath,
|
|||
psync_error = PERROR_LOCAL_FOLDER_ACC_DENIED;
|
||||
return -1;
|
||||
}
|
||||
res = psync_sql_prep_statement("INSERT INTO syncfolderdelayed (localpath, "
|
||||
res = psql_prepare("INSERT INTO syncfolderdelayed (localpath, "
|
||||
"remotepath, synctype) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_string(res, 1, localpath);
|
||||
psync_sql_bind_string(res, 2, remotepath);
|
||||
psync_sql_bind_uint(res, 3, synctype);
|
||||
psync_sql_run_free(res);
|
||||
psync_sql_sync();
|
||||
psql_bind_str(res, 1, localpath);
|
||||
psql_bind_str(res, 2, remotepath);
|
||||
psql_bind_uint(res, 3, synctype);
|
||||
psql_run_free(res);
|
||||
psql_sync();
|
||||
if (pstatus_get(PSTATUS_TYPE_ONLINE) == PSTATUS_ONLINE_ONLINE)
|
||||
prun_thread("check delayed syncs", psyncer_check_delayed);
|
||||
return 0;
|
||||
|
|
@ -788,87 +790,87 @@ int psync_change_synctype(psync_syncid_t syncid, psync_synctype_t synctype) {
|
|||
if (pdbg_unlikely(synctype < PSYNC_SYNCTYPE_MIN ||
|
||||
synctype > PSYNC_SYNCTYPE_MAX))
|
||||
return_isyncid(PERROR_INVALID_SYNCTYPE);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_query(
|
||||
psql_start();
|
||||
res = psql_query(
|
||||
"SELECT folderid, localpath, synctype FROM syncfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
row = psync_sql_fetch_row(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
row = psql_fetch(res);
|
||||
if (pdbg_unlikely(!row)) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rollback_transaction();
|
||||
psql_free(res);
|
||||
psql_rollback();
|
||||
psync_error = PERROR_INVALID_SYNCID;
|
||||
return -1;
|
||||
}
|
||||
folderid = psync_get_number(row[0]);
|
||||
oldsynctype = psync_get_number(row[2]);
|
||||
if (oldsynctype == synctype) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rollback_transaction();
|
||||
psql_free(res);
|
||||
psql_rollback();
|
||||
return 0;
|
||||
}
|
||||
if (pdbg_unlikely(stat(psync_get_string(row[1]), &st)) ||
|
||||
pdbg_unlikely(!pfile_stat_isfolder(&st))) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rollback_transaction();
|
||||
psql_free(res);
|
||||
psql_rollback();
|
||||
return_isyncid(PERROR_LOCAL_FOLDER_NOT_FOUND);
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (synctype & PSYNC_DOWNLOAD_ONLY)
|
||||
mbedtls_md = 7;
|
||||
else
|
||||
mbedtls_md = 5;
|
||||
if (pdbg_unlikely(!pfile_stat_mode_ok(&st, mbedtls_md))) {
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
return_isyncid(PERROR_LOCAL_FOLDER_ACC_DENIED);
|
||||
}
|
||||
if (folderid) {
|
||||
res = psync_sql_query("SELECT permissions FROM folder WHERE id=?");
|
||||
res = psql_query("SELECT permissions FROM folder WHERE id=?");
|
||||
if (pdbg_unlikely(!res))
|
||||
return_isyncid(PERROR_DATABASE_ERROR);
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
urow = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
urow = psql_fetch_int(res);
|
||||
if (pdbg_unlikely(!urow)) {
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rollback_transaction();
|
||||
psql_free(res);
|
||||
psql_rollback();
|
||||
return_isyncid(PERROR_REMOTE_FOLDER_NOT_FOUND);
|
||||
}
|
||||
perms = urow[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
} else
|
||||
perms = PSYNC_PERM_ALL;
|
||||
if (pdbg_unlikely((synctype & PSYNC_DOWNLOAD_ONLY &&
|
||||
(perms & PSYNC_PERM_READ) != PSYNC_PERM_READ) ||
|
||||
(synctype & PSYNC_UPLOAD_ONLY &&
|
||||
(perms & PSYNC_PERM_WRITE) != PSYNC_PERM_WRITE))) {
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
return_isyncid(PERROR_REMOTE_FOLDER_ACC_DENIED);
|
||||
}
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE syncfolder SET synctype=?, flags=0 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, synctype);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_query("SELECT folderid FROM syncedfolder WHERE syncid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
while ((urow = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, synctype);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_run_free(res);
|
||||
res = psql_query("SELECT folderid FROM syncedfolder WHERE syncid=?");
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
while ((urow = psql_fetch_int(res)))
|
||||
psyncer_dl_queue_del(urow[0]);
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement("DELETE FROM syncedfolder WHERE syncid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement("DELETE FROM localfile WHERE syncid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement("DELETE FROM localfolder WHERE syncid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_run_free(res);
|
||||
psql_free(res);
|
||||
res = psql_prepare("DELETE FROM syncedfolder WHERE syncid=?");
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM localfile WHERE syncid=?");
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM localfolder WHERE syncid=?");
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_run_free(res);
|
||||
ppathstatus_syncfldr_delete(syncid);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
psync_localnotify_del_sync(syncid);
|
||||
psync_restat_sync_folders_del(syncid);
|
||||
pdownload_stop_sync(syncid);
|
||||
pupload_stop_sync(syncid);
|
||||
psync_sql_sync();
|
||||
psql_sync();
|
||||
ppathstatus_reload_syncs();
|
||||
psyncer_create(syncid);
|
||||
return 0;
|
||||
|
|
@ -878,41 +880,41 @@ static void psync_delete_local_recursive(psync_syncid_t syncid,
|
|||
psync_folderid_t localfolderid) {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT id FROM localfolder WHERE localparentfolderid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
psync_delete_local_recursive(syncid, row[0]);
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM localfile WHERE localparentfolderid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement(
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare(
|
||||
"DELETE FROM localfolder WHERE id=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_run_free(res);
|
||||
if (psync_sql_affected_rows()) {
|
||||
res = psync_sql_prep_statement(
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_run_free(res);
|
||||
if (psql_affected()) {
|
||||
res = psql_prepare(
|
||||
"DELETE FROM syncedfolder WHERE localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
}
|
||||
|
||||
int psync_delete_sync(psync_syncid_t syncid) {
|
||||
psync_sql_res *res;
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
|
||||
psync_delete_local_recursive(syncid, 0);
|
||||
res = psync_sql_prep_statement("DELETE FROM syncfolder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM syncfolder WHERE id=?");
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_run_free(res);
|
||||
|
||||
if (psync_sql_commit_transaction())
|
||||
if (psql_commit())
|
||||
return -1;
|
||||
else {
|
||||
pdownload_stop_sync(syncid);
|
||||
|
|
@ -920,7 +922,7 @@ int psync_delete_sync(psync_syncid_t syncid) {
|
|||
psync_localnotify_del_sync(syncid);
|
||||
psync_restat_sync_folders_del(syncid);
|
||||
psync_restart_localscan();
|
||||
psync_sql_sync();
|
||||
psql_sync();
|
||||
ppathstatus_syncfldr_delete(syncid);
|
||||
ppathstatus_reload_syncs();
|
||||
|
||||
|
|
@ -1233,14 +1235,14 @@ int psync_has_value(const char *valuename) {
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
int ret;
|
||||
res = psync_sql_query_rdlock("SELECT COUNT(*) FROM setting WHERE id=?");
|
||||
psync_sql_bind_string(res, 1, valuename);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
res = psql_query_rdlock("SELECT COUNT(*) FROM setting WHERE id=?");
|
||||
psql_bind_str(res, 1, valuename);
|
||||
row = psql_fetch_int(res);
|
||||
if (row)
|
||||
ret = row[0];
|
||||
else
|
||||
ret = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -1264,48 +1266,48 @@ uint64_t psync_get_uint_value(const char *valuename) {
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
uint64_t ret;
|
||||
res = psync_sql_query_rdlock("SELECT value FROM setting WHERE id=?");
|
||||
psync_sql_bind_string(res, 1, valuename);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
res = psql_query_rdlock("SELECT value FROM setting WHERE id=?");
|
||||
psql_bind_str(res, 1, valuename);
|
||||
row = psql_fetch_int(res);
|
||||
if (row)
|
||||
ret = row[0];
|
||||
else
|
||||
ret = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void psync_set_uint_value(const char *valuename, uint64_t value) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
psync_sql_bind_string(res, 1, valuename);
|
||||
psync_sql_bind_uint(res, 2, value);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_str(res, 1, valuename);
|
||||
psql_bind_uint(res, 2, value);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
char *psync_get_string_value(const char *valuename) {
|
||||
psync_sql_res *res;
|
||||
psync_str_row row;
|
||||
char *ret;
|
||||
res = psync_sql_query_rdlock("SELECT value FROM setting WHERE id=?");
|
||||
psync_sql_bind_string(res, 1, valuename);
|
||||
row = psync_sql_fetch_rowstr(res);
|
||||
res = psql_query_rdlock("SELECT value FROM setting WHERE id=?");
|
||||
psql_bind_str(res, 1, valuename);
|
||||
row = psql_fetch_str(res);
|
||||
if (row)
|
||||
ret = psync_strdup(row[0]);
|
||||
else
|
||||
ret = NULL;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void psync_set_string_value(const char *valuename, const char *value) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES (?, ?)");
|
||||
psync_sql_bind_string(res, 1, valuename);
|
||||
psync_sql_bind_string(res, 2, value);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_str(res, 1, valuename);
|
||||
psql_bind_str(res, 2, value);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void psync_network_exception() { ptimer_notify_exception(); }
|
||||
|
|
@ -1354,11 +1356,11 @@ psync_sharerequest_list_t *psync_list_sharerequests(int incoming) {
|
|||
sizeof(psync_sharerequest_t),
|
||||
offsetof(psync_sharerequest_list_t, sharerequests));
|
||||
incoming = !!incoming;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, folderid, ctime, permissions, userid, mail, name, message, "
|
||||
"ifnull(isba, 0) FROM sharerequest WHERE isincoming=? ORDER BY name");
|
||||
psync_sql_bind_uint(res, 1, incoming);
|
||||
psync_list_bulder_add_sql(builder, res, create_request);
|
||||
psql_bind_uint(res, 1, incoming);
|
||||
psql_list_add(builder, res, create_request);
|
||||
return (psync_sharerequest_list_t *)psync_list_builder_finalize(builder);
|
||||
}
|
||||
|
||||
|
|
@ -1416,7 +1418,7 @@ psync_share_list_t *psync_list_shares(int incoming) {
|
|||
offsetof(psync_share_list_t, shares));
|
||||
incoming = !!incoming;
|
||||
if (incoming) {
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, folderid, ctime, permissions, userid, ifnull(mail, ''), "
|
||||
"ifnull(mail, '') as frommail, name, ifnull(bsharedfolderid, 0), 0 "
|
||||
"FROM sharedfolder WHERE isincoming=1 AND id >= 0 "
|
||||
|
|
@ -1430,9 +1432,9 @@ psync_share_list_t *psync_list_shares(int incoming) {
|
|||
" name, id as bsharedfolderid, 0 from bsharedfolder where isincoming = "
|
||||
"1 "
|
||||
" ORDER BY name;");
|
||||
psync_list_bulder_add_sql(builder, res, create_share);
|
||||
psql_list_add(builder, res, create_share);
|
||||
} else {
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT sf.id, sf.folderid, sf.ctime, sf.permissions, sf.userid, "
|
||||
"ifnull(sf.mail, ''), ifnull(sf.mail, '') as frommail, f.name as "
|
||||
"fname, ifnull(sf.bsharedfolderid, 0), 0 "
|
||||
|
|
@ -1451,7 +1453,7 @@ psync_share_list_t *psync_list_shares(int incoming) {
|
|||
" bsf.name as fname, bsf.id, bsf.isteam from bsharedfolder bsf, folder "
|
||||
"f where bsf.isincoming = 0 "
|
||||
" and bsf.folderid = f.id ORDER BY fname ");
|
||||
psync_list_bulder_add_sql(builder, res, create_share);
|
||||
psql_list_add(builder, res, create_share);
|
||||
}
|
||||
|
||||
return (psync_share_list_t *)psync_list_builder_finalize(builder);
|
||||
|
|
@ -1863,19 +1865,19 @@ int psync_crypto_mkdir(psync_folderid_t folderid, const char *name,
|
|||
}
|
||||
|
||||
int psync_crypto_hassubscription() {
|
||||
return psync_sql_cellint(
|
||||
return psql_cellint(
|
||||
"SELECT value FROM setting WHERE id='cryptosubscription'", 0);
|
||||
}
|
||||
|
||||
int psync_crypto_isexpired() {
|
||||
int64_t ce;
|
||||
ce = psync_sql_cellint("SELECT value FROM setting WHERE id='cryptoexpires'",
|
||||
ce = psql_cellint("SELECT value FROM setting WHERE id='cryptoexpires'",
|
||||
0);
|
||||
return ce ? (ce < ptimer_time()) : 0;
|
||||
}
|
||||
|
||||
time_t psync_crypto_expires() {
|
||||
return psync_sql_cellint("SELECT value FROM setting WHERE id='cryptoexpires'",
|
||||
return psql_cellint("SELECT value FROM setting WHERE id='cryptoexpires'",
|
||||
0);
|
||||
}
|
||||
|
||||
|
|
@ -1888,14 +1890,14 @@ int psync_crypto_reset() {
|
|||
|
||||
psync_folderid_t psync_crypto_folderid() {
|
||||
int64_t id;
|
||||
id = psync_sql_cellint(
|
||||
id = psql_cellint(
|
||||
"SELECT id FROM folder WHERE parentfolderid=0 AND "
|
||||
"flags&" NTO_STR(PSYNC_FOLDER_FLAG_ENCRYPTED) "=" NTO_STR(
|
||||
PSYNC_FOLDER_FLAG_ENCRYPTED) " LIMIT 1",
|
||||
0);
|
||||
if (id)
|
||||
return id;
|
||||
id = psync_sql_cellint(
|
||||
id = psql_cellint(
|
||||
"SELECT f1.id FROM folder f1, folder f2 WHERE f1.parentfolderid=f2.id "
|
||||
"AND "
|
||||
"f1.flags&" NTO_STR(PSYNC_FOLDER_FLAG_ENCRYPTED) "=" NTO_STR(
|
||||
|
|
@ -1919,14 +1921,14 @@ psync_folderid_t *psync_crypto_folderids() {
|
|||
alloc = 2;
|
||||
l = 0;
|
||||
ret = malloc(sizeof(psync_folderid_t) * alloc);
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT f1.id FROM folder f1, folder f2 WHERE f1.parentfolderid=f2.id "
|
||||
"AND "
|
||||
"f1.flags&" NTO_STR(PSYNC_FOLDER_FLAG_ENCRYPTED) "=" NTO_STR(
|
||||
PSYNC_FOLDER_FLAG_ENCRYPTED) " AND "
|
||||
"f2.flags&" NTO_STR(
|
||||
PSYNC_FOLDER_FLAG_ENCRYPTED) "=0");
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
while ((row = psql_fetch_int(res))) {
|
||||
ret[l] = row[0];
|
||||
if (++l == alloc) {
|
||||
alloc *= 2;
|
||||
|
|
@ -1934,7 +1936,7 @@ psync_folderid_t *psync_crypto_folderids() {
|
|||
sizeof(psync_folderid_t) * alloc);
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
ret[l] = PSYNC_CRYPTO_INVALID_FOLDERID;
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -2245,21 +2247,21 @@ void psync_get_current_userid(psync_userid_t *ret) {
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
|
||||
res = psync_sql_query_rdlock("SELECT value FROM setting WHERE id= 'userid' ");
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
res = psql_query_rdlock("SELECT value FROM setting WHERE id= 'userid' ");
|
||||
while ((row = psql_fetch_int(res)))
|
||||
*ret = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
void psync_get_folder_ownerid(psync_folderid_t folderid, psync_userid_t *ret) {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
|
||||
res = psync_sql_query_rdlock("SELECT userid FROM folder WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
while ((row = psync_sql_fetch_rowint(res)))
|
||||
res = psql_query_rdlock("SELECT userid FROM folder WHERE id=?");
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
while ((row = psql_fetch_int(res)))
|
||||
*ret = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
int psync_setlanguage(const char *language, char **err) {
|
||||
|
|
@ -2348,15 +2350,15 @@ uint64_t psync_crypto_priv_key_flags() {
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
uint64_t ret = 0;
|
||||
res = psync_sql_query_rdlock_nocache(
|
||||
res = psql_rdlock_nocache(
|
||||
"SELECT value FROM setting WHERE id='crypto_private_flags'");
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
ret = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
} else
|
||||
pdbg_logf(D_NOTICE, "Can't read private key flags from the DB");
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -2364,14 +2366,14 @@ int psync_has_crypto_folders() {
|
|||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
uint64_t cnt = 0;
|
||||
res = psync_sql_query_rdlock_nocache(
|
||||
res = psql_rdlock_nocache(
|
||||
"SELECT count(*) FROM folder WHERE flags&" NTO_STR(
|
||||
PSYNC_FOLDER_FLAG_ENCRYPTED) "");
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
cnt = row[0];
|
||||
} else
|
||||
pdbg_logf(D_NOTICE, "There are no crypto folders in the DB");
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return cnt > 0;
|
||||
}
|
||||
|
||||
|
|
@ -2401,28 +2403,28 @@ int psync_is_folder_syncable(char *localPath, char **errMsg) {
|
|||
pdbg_logf(D_NOTICE, "Check if folder is already synced. LocalPath [%s]",
|
||||
localPath);
|
||||
|
||||
sql = psync_sql_query("SELECT localpath FROM syncfolder");
|
||||
sql = psql_query("SELECT localpath FROM syncfolder");
|
||||
|
||||
if (pdbg_unlikely(!sql)) {
|
||||
return_isyncid(PERROR_DATABASE_ERROR);
|
||||
}
|
||||
|
||||
while ((srow = psync_sql_fetch_rowstr(sql))) {
|
||||
while ((srow = psql_fetch_str(sql))) {
|
||||
if (psyncer_str_has_prefix(srow[0], localPath)) {
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
|
||||
*errMsg = psync_strdup("There is already an active sync or backup for a "
|
||||
"parent of this folder.");
|
||||
return PERROR_PARENT_OR_SUBFOLDER_ALREADY_SYNCING;
|
||||
} else if (!strcmp(srow[0], localPath)) {
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
|
||||
*errMsg = psync_strdup(
|
||||
"There is already an active sync or backup for this folder.");
|
||||
return PERROR_FOLDER_ALREADY_SYNCING;
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
|
||||
pdbg_logf(D_NOTICE, "Check if folder is not on the Drive.");
|
||||
|
||||
|
|
@ -2500,10 +2502,10 @@ psync_folderid_t create_bup_mach_folder(char **msgErr) {
|
|||
(binresult *)papi_find_result2(retData, "folderid", PARAM_NUM);
|
||||
|
||||
// Store the root folder id in the local DB
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES ('BackupRootFoId', ?)");
|
||||
psync_sql_bind_uint(sql, 1, rootFolIdObj->num);
|
||||
psync_sql_run_free(sql);
|
||||
psql_bind_uint(sql, 1, rootFolIdObj->num);
|
||||
psql_run_free(sql);
|
||||
|
||||
free(retData);
|
||||
}
|
||||
|
|
@ -2536,7 +2538,7 @@ int psync_create_backup(char *path, char **errMsg) {
|
|||
return res;
|
||||
}
|
||||
|
||||
bFId = psync_sql_cellint(
|
||||
bFId = psql_cellint(
|
||||
"SELECT value FROM setting WHERE id='BackupRootFoId'", 0);
|
||||
|
||||
if (bFId == 0) {
|
||||
|
|
@ -2593,9 +2595,9 @@ int psync_create_backup(char *path, char **errMsg) {
|
|||
pdbg_logf(D_NOTICE,
|
||||
"Backup folder id is not valid. Delete it and create a new one.");
|
||||
|
||||
psync_sql_start_transaction();
|
||||
psync_sql_statement("DELETE FROM setting WHERE id='BackupRootFoId'");
|
||||
psync_sql_commit_transaction();
|
||||
psql_start();
|
||||
psql_statement("DELETE FROM setting WHERE id='BackupRootFoId'");
|
||||
psql_commit();
|
||||
|
||||
goto retryRootCrt;
|
||||
}
|
||||
|
|
@ -2612,20 +2614,20 @@ int psync_delete_backup(psync_syncid_t syncId, char **errMsg) {
|
|||
int res = 0;
|
||||
|
||||
sqlRes =
|
||||
psync_sql_query_rdlock("SELECT folderid FROM syncfolder WHERE id = ?");
|
||||
psql_query_rdlock("SELECT folderid FROM syncfolder WHERE id = ?");
|
||||
|
||||
psync_sql_bind_uint(sqlRes, 1, syncId);
|
||||
row = psync_sql_fetch_rowint(sqlRes);
|
||||
psql_bind_uint(sqlRes, 1, syncId);
|
||||
row = psql_fetch_int(sqlRes);
|
||||
|
||||
if (unlikely(!row)) {
|
||||
pdbg_logf(D_ERROR, "Failed to find folder id for syncId: [%u]", syncId);
|
||||
psync_sql_free_result(sqlRes);
|
||||
psql_free(sqlRes);
|
||||
|
||||
res = -1;
|
||||
} else {
|
||||
folderId = row[0];
|
||||
|
||||
psync_sql_free_result(sqlRes);
|
||||
psql_free(sqlRes);
|
||||
}
|
||||
|
||||
if (res == 0) {
|
||||
|
|
@ -2656,7 +2658,7 @@ void psync_stop_device(psync_folderid_t folderId, char **errMsg) {
|
|||
int res = 0;
|
||||
|
||||
if (folderId == 0) {
|
||||
bFId = psync_sql_cellint(
|
||||
bFId = psql_cellint(
|
||||
"SELECT value FROM setting WHERE id='BackupRootFoId'", 0);
|
||||
} else {
|
||||
bFId = folderId;
|
||||
|
|
@ -2684,7 +2686,7 @@ void psync_stop_device(psync_folderid_t folderId, char **errMsg) {
|
|||
}
|
||||
|
||||
char *get_backup_root_name() {
|
||||
return psync_sql_cellstr("SELECT name FROM setting s JOIN folder f ON "
|
||||
return psql_cellstr("SELECT name FROM setting s JOIN folder f ON "
|
||||
"s.value = f.id AND s.id = 'BackupRootFoId'");
|
||||
}
|
||||
|
||||
|
|
@ -2723,17 +2725,17 @@ int psync_delete_sync_by_folderid(psync_folderid_t fId) {
|
|||
psync_syncid_t syncId;
|
||||
|
||||
sqlRes =
|
||||
psync_sql_query_rdlock("SELECT id FROM syncfolder WHERE folderid = ?");
|
||||
psync_sql_bind_uint(sqlRes, 1, fId);
|
||||
row = psync_sql_fetch_rowint(sqlRes);
|
||||
psql_query_rdlock("SELECT id FROM syncfolder WHERE folderid = ?");
|
||||
psql_bind_uint(sqlRes, 1, fId);
|
||||
row = psql_fetch_int(sqlRes);
|
||||
if (unlikely(!row)) {
|
||||
pdbg_logf(D_ERROR, "Sync to delete not found!");
|
||||
psync_sql_free_result(sqlRes);
|
||||
psql_free(sqlRes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
syncId = (psync_syncid_t)row[0];
|
||||
psync_sql_free_result(sqlRes);
|
||||
psql_free(sqlRes);
|
||||
|
||||
prun_thread1("psync_async_sync_delete", psync_async_delete_sync,
|
||||
(void *)(uintptr_t)syncId);
|
||||
|
|
@ -2746,15 +2748,15 @@ int psync_delete_backup_device(psync_folderid_t fId) {
|
|||
|
||||
pdbg_logf(D_NOTICE, "Check if the local device was stopped. Id: [%lu]", fId);
|
||||
|
||||
bFId = psync_sql_cellint(
|
||||
bFId = psql_cellint(
|
||||
"SELECT value FROM setting WHERE id='BackupRootFoId'", 0);
|
||||
|
||||
if (bFId == fId) {
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
|
||||
psync_sql_statement("DELETE FROM setting WHERE id='BackupRootFoId'");
|
||||
psql_statement("DELETE FROM setting WHERE id='BackupRootFoId'");
|
||||
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
} else {
|
||||
pdbg_logf(D_NOTICE, "Stop for different device. Id: [%lu]", bFId);
|
||||
}
|
||||
|
|
@ -2878,14 +2880,14 @@ void psync_init_data_event_handler(void *ptr) { ptevent_init(ptr); }
|
|||
|
||||
// moved from pdiff
|
||||
void psync_delete_cached_crypto_keys() {
|
||||
psync_sql_statement(
|
||||
psql_statement(
|
||||
"DELETE FROM setting WHERE id IN ('crypto_public_key', "
|
||||
"'crypto_private_key', 'crypto_private_iter', "
|
||||
"'crypto_private_salt', 'crypto_private_sha1', 'crypto_public_sha1')");
|
||||
if (psync_sql_affected_rows()) {
|
||||
if (psql_affected()) {
|
||||
pdbg_logf(D_NOTICE, "deleted cached crypto keys");
|
||||
pcryptofolder_cache_clean();
|
||||
}
|
||||
psync_sql_statement("DELETE FROM cryptofolderkey");
|
||||
psync_sql_statement("DELETE FROM cryptofilekey");
|
||||
psql_statement("DELETE FROM cryptofolderkey");
|
||||
psql_statement("DELETE FROM cryptofilekey");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ static int psync_gids_cnt;
|
|||
|
||||
static void abort_on_sqllock(uint64_t millisec) {
|
||||
#if IS_DEBUG
|
||||
if (psync_sql_islocked()) {
|
||||
if (psql_locked()) {
|
||||
pdbg_logf(D_CRITICAL, "trying to sleep while holding sql lock, aborting");
|
||||
psync_sql_dump_locks();
|
||||
psql_dump_locks();
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
268
pclsync/ptask.c
268
pclsync/ptask.c
|
|
@ -357,38 +357,38 @@ static int download_process_headers(stream_t *s,
|
|||
"got headers for file %s size %" PRIu64 " hash %" PRIu64
|
||||
" sha1 %.40s",
|
||||
fda->localpath, fda->size, fda->hash, fda->sha1hex);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO hashchecksum (hash, size, checksum) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, r.hash);
|
||||
psync_sql_bind_uint(res, 2, r.size);
|
||||
psync_sql_bind_lstring(res, 3, (const char *)r.sha1hex,
|
||||
psql_bind_uint(res, 1, r.hash);
|
||||
psql_bind_uint(res, 2, r.size);
|
||||
psql_bind_lstr(res, 3, (const char *)r.sha1hex,
|
||||
PSYNC_SHA1_DIGEST_HEXLEN);
|
||||
if (r.oldmtime) {
|
||||
psync_sql_run(res);
|
||||
psync_sql_bind_uint(res, 1, r.oldhash);
|
||||
psync_sql_bind_uint(res, 2, fda->osize);
|
||||
psync_sql_bind_lstring(res, 3, (const char *)fda->osha1hex,
|
||||
psql_run(res);
|
||||
psql_bind_uint(res, 1, r.oldhash);
|
||||
psql_bind_uint(res, 2, fda->osize);
|
||||
psql_bind_lstr(res, 3, (const char *)fda->osha1hex,
|
||||
PSYNC_SHA1_DIGEST_HEXLEN);
|
||||
psync_sql_run_free(res);
|
||||
psql_run_free(res);
|
||||
} else
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement("REPLACE INTO filerevision (fileid, hash, "
|
||||
psql_run_free(res);
|
||||
res = psql_prepare("REPLACE INTO filerevision (fileid, hash, "
|
||||
"ctime, size) VALUES (?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, fda->fileid);
|
||||
psync_sql_bind_uint(res, 2, r.hash);
|
||||
psync_sql_bind_uint(res, 3, r.mtime);
|
||||
psync_sql_bind_uint(res, 4, r.size);
|
||||
psql_bind_uint(res, 1, fda->fileid);
|
||||
psql_bind_uint(res, 2, r.hash);
|
||||
psql_bind_uint(res, 3, r.mtime);
|
||||
psql_bind_uint(res, 4, r.size);
|
||||
if (r.oldmtime) {
|
||||
psync_sql_run(res);
|
||||
psync_sql_bind_uint(res, 1, fda->fileid);
|
||||
psync_sql_bind_uint(res, 2, r.oldhash);
|
||||
psync_sql_bind_uint(res, 3, r.oldmtime);
|
||||
psync_sql_bind_uint(res, 4, fda->osize);
|
||||
psync_sql_run_free(res);
|
||||
psql_run(res);
|
||||
psql_bind_uint(res, 1, fda->fileid);
|
||||
psql_bind_uint(res, 2, r.oldhash);
|
||||
psql_bind_uint(res, 3, r.oldmtime);
|
||||
psql_bind_uint(res, 4, fda->osize);
|
||||
psql_run_free(res);
|
||||
} else
|
||||
psync_sql_run_free(res);
|
||||
psync_sql_commit_transaction();
|
||||
psql_run_free(res);
|
||||
psql_commit();
|
||||
fda->fd = pfile_open(fda->localpath, O_WRONLY, O_CREAT | O_TRUNC);
|
||||
if (fda->fd == INVALID_HANDLE_VALUE) {
|
||||
pdbg_logf(D_WARNING, "could not open file %s, errno %d", fda->localpath,
|
||||
|
|
@ -878,63 +878,63 @@ void ptask_ldir_mk(psync_syncid_t syncid,
|
|||
psync_folderid_t folderid,
|
||||
psync_folderid_t localfolderid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid) VALUES (?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_CREATE_LOCAL_FOLDER);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, folderid);
|
||||
psync_sql_bind_uint(res, 4, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_CREATE_LOCAL_FOLDER);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, folderid);
|
||||
psql_bind_uint(res, 4, localfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_ldir_rm(psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localfolderid, const char *remotepath) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DELETE_LOCAL_FOLDER);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, folderid);
|
||||
psync_sql_bind_uint(res, 4, localfolderid);
|
||||
psync_sql_bind_string(res, 5, remotepath);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_DELETE_LOCAL_FOLDER);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, folderid);
|
||||
psql_bind_uint(res, 4, localfolderid);
|
||||
psql_bind_str(res, 5, remotepath);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_ldir_rm_r(psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localfolderid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid) VALUES (?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DELREC_LOCAL_FOLDER);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, folderid);
|
||||
psync_sql_bind_uint(res, 4, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_DELREC_LOCAL_FOLDER);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, folderid);
|
||||
psql_bind_uint(res, 4, localfolderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_ldir_rename(psync_syncid_t syncid, psync_folderid_t folderid, psync_folderid_t localfolderid, psync_folderid_t newlocalparentfolderid, const char *newname) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO task (type, syncid, itemid, localitemid, newitemid, name) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_RENAME_LOCAL_FOLDER);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, folderid);
|
||||
psync_sql_bind_uint(res, 4, localfolderid);
|
||||
psync_sql_bind_uint(res, 5, newlocalparentfolderid);
|
||||
psync_sql_bind_string(res, 6, newname);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_RENAME_LOCAL_FOLDER);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, folderid);
|
||||
psql_bind_uint(res, 4, localfolderid);
|
||||
psql_bind_uint(res, 5, newlocalparentfolderid);
|
||||
psql_bind_str(res, 6, newname);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_download_q(psync_syncid_t syncid, psync_fileid_t fileid, psync_folderid_t localfolderid, const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, fileid);
|
||||
psync_sql_bind_uint(res, 4, localfolderid);
|
||||
psync_sql_bind_string(res, 5, name);
|
||||
psql_bind_uint(res, 1, PSYNC_DOWNLOAD_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, fileid);
|
||||
psql_bind_uint(res, 4, localfolderid);
|
||||
psql_bind_str(res, 5, name);
|
||||
ppath_syncfldr_task_added_locked(syncid, localfolderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_download(psync_syncid_t syncid, psync_fileid_t fileid, psync_folderid_t localfolderid, const char *name) {
|
||||
|
|
@ -946,124 +946,124 @@ void ptask_download(psync_syncid_t syncid, psync_fileid_t fileid, psync_folderid
|
|||
|
||||
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) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO task (type, syncid, newsyncid, itemid, localitemid, "
|
||||
"newitemid, name) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_RENAME_LOCAL_FILE);
|
||||
psync_sql_bind_uint(res, 2, oldsyncid);
|
||||
psync_sql_bind_uint(res, 3, newsyncid);
|
||||
psync_sql_bind_uint(res, 4, fileid);
|
||||
psync_sql_bind_uint(res, 5, oldlocalfolderid);
|
||||
psync_sql_bind_uint(res, 6, newlocalfolderid);
|
||||
psync_sql_bind_string(res, 7, newname);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_RENAME_LOCAL_FILE);
|
||||
psql_bind_uint(res, 2, oldsyncid);
|
||||
psql_bind_uint(res, 3, newsyncid);
|
||||
psql_bind_uint(res, 4, fileid);
|
||||
psql_bind_uint(res, 5, oldlocalfolderid);
|
||||
psql_bind_uint(res, 6, newlocalfolderid);
|
||||
psql_bind_str(res, 7, newname);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_lfile_rm(psync_fileid_t fileid, const char *remotepath) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO task (type, itemid, localitemid, name) VALUES (?, ?, 0, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DELETE_LOCAL_FILE);
|
||||
psync_sql_bind_uint(res, 2, fileid);
|
||||
psync_sql_bind_string(res, 3, remotepath);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_DELETE_LOCAL_FILE);
|
||||
psql_bind_uint(res, 2, fileid);
|
||||
psql_bind_str(res, 3, remotepath);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_lfile_rm_id(psync_syncid_t syncid, psync_fileid_t fileid, const char *remotepath) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, 0, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DELETE_LOCAL_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, fileid);
|
||||
psync_sql_bind_string(res, 4, remotepath);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_DELETE_LOCAL_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, fileid);
|
||||
psql_bind_str(res, 4, remotepath);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_rdir_mk(psync_syncid_t syncid, psync_folderid_t localfolderid, const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_CREATE_REMOTE_FOLDER);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, 0);
|
||||
psync_sql_bind_uint(res, 4, localfolderid);
|
||||
psync_sql_bind_string(res, 5, name);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_CREATE_REMOTE_FOLDER);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, 0);
|
||||
psql_bind_uint(res, 4, localfolderid);
|
||||
psql_bind_str(res, 5, name);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_upload_q(psync_syncid_t syncid, psync_fileid_t localfileid, const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, 0);
|
||||
psync_sql_bind_uint(res, 4, localfileid);
|
||||
psync_sql_bind_string(res, 5, name);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, 0);
|
||||
psql_bind_uint(res, 4, localfileid);
|
||||
psql_bind_str(res, 5, name);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_upload(psync_syncid_t syncid, psync_fileid_t localfileid, const char *name) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid, name) VALUES (?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, 0);
|
||||
psync_sql_bind_uint(res, 4, localfileid);
|
||||
psync_sql_bind_string(res, 5, name);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, 0);
|
||||
psql_bind_uint(res, 4, localfileid);
|
||||
psql_bind_str(res, 5, name);
|
||||
psql_run_free(res);
|
||||
pupload_wake();
|
||||
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) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO task (type, syncid, newsyncid, localitemid, newitemid, "
|
||||
"name, itemid) VALUES (?, ?, ?, ?, ?, ?, 0)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_RENAME_REMOTE_FILE);
|
||||
psync_sql_bind_uint(res, 2, oldsyncid);
|
||||
psync_sql_bind_uint(res, 3, newsyncid);
|
||||
psync_sql_bind_uint(res, 4, localfileid);
|
||||
psync_sql_bind_uint(res, 5, newlocalparentfolderid);
|
||||
psync_sql_bind_string(res, 6, newname);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_RENAME_REMOTE_FILE);
|
||||
psql_bind_uint(res, 2, oldsyncid);
|
||||
psql_bind_uint(res, 3, newsyncid);
|
||||
psql_bind_uint(res, 4, localfileid);
|
||||
psql_bind_uint(res, 5, newlocalparentfolderid);
|
||||
psql_bind_str(res, 6, newname);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_rdir_rename(psync_syncid_t oldsyncid, psync_syncid_t newsyncid, psync_fileid_t localfileid, psync_folderid_t newlocalparentfolderid, const char *newname) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"INSERT INTO task (type, syncid, newsyncid, localitemid, newitemid, "
|
||||
"name, itemid) VALUES (?, ?, ?, ?, ?, ?, 0)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_RENAME_REMOTE_FOLDER);
|
||||
psync_sql_bind_uint(res, 2, oldsyncid);
|
||||
psync_sql_bind_uint(res, 3, newsyncid);
|
||||
psync_sql_bind_uint(res, 4, localfileid);
|
||||
psync_sql_bind_uint(res, 5, newlocalparentfolderid);
|
||||
psync_sql_bind_string(res, 6, newname);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_RENAME_REMOTE_FOLDER);
|
||||
psql_bind_uint(res, 2, oldsyncid);
|
||||
psql_bind_uint(res, 3, newsyncid);
|
||||
psql_bind_uint(res, 4, localfileid);
|
||||
psql_bind_uint(res, 5, newlocalparentfolderid);
|
||||
psql_bind_str(res, 6, newname);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_rfile_rm(psync_syncid_t syncid, psync_fileid_t fileid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid) VALUES (?, ?, ?, 0)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DELETE_REMOTE_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, fileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_DELETE_REMOTE_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, fileid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_rdir_rm(psync_syncid_t syncid, psync_folderid_t folderid) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement("INSERT INTO task (type, syncid, itemid, "
|
||||
res = psql_prepare("INSERT INTO task (type, syncid, itemid, "
|
||||
"localitemid) VALUES (?, ?, ?, 0)");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_DELETE_REMOTE_FILE);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, folderid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, PSYNC_DELETE_REMOTE_FILE);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, folderid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
void ptask_stop_async() {
|
||||
|
|
@ -1109,11 +1109,11 @@ void ptask_cfldr_save_fldrkey(void *ptr) {
|
|||
insert_folder_key_task *t;
|
||||
psync_sql_res *res;
|
||||
t = (insert_folder_key_task *)ptr;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO cryptofolderkey (folderid, enckey) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(res, 1, t->id);
|
||||
psync_sql_bind_blob(res, 2, (const char *)t->key->data, t->key->datalen);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, t->id);
|
||||
psql_bind_blob(res, 2, (const char *)t->key->data, t->key->datalen);
|
||||
psql_run_free(res);
|
||||
free(t->key);
|
||||
free(t);
|
||||
}
|
||||
|
|
@ -1122,12 +1122,12 @@ void ptask_cfldr_save_filekey(void *ptr) {
|
|||
insert_file_key_task *t;
|
||||
psync_sql_res *res;
|
||||
t = (insert_file_key_task *)ptr;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"REPLACE INTO cryptofilekey (fileid, hash, enckey) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(res, 1, t->id);
|
||||
psync_sql_bind_uint(res, 2, t->hash);
|
||||
psync_sql_bind_blob(res, 3, (const char *)t->key->data, t->key->datalen);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, t->id);
|
||||
psql_bind_uint(res, 2, t->hash);
|
||||
psql_bind_blob(res, 3, (const char *)t->key->data, t->key->datalen);
|
||||
psql_run_free(res);
|
||||
free(t->key);
|
||||
free(t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -415,11 +415,11 @@ void ptools_send_psyncs_event(const char *binapi, const char *auth) {
|
|||
|
||||
time(&rawtime);
|
||||
|
||||
syncEventFlag = psync_sql_cellint(
|
||||
syncEventFlag = psql_cellint(
|
||||
"SELECT value FROM setting WHERE id='syncEventSentFlag'", 0);
|
||||
|
||||
if (syncEventFlag != 1) {
|
||||
syncCnt = psync_sql_cellint(
|
||||
syncCnt = psql_cellint(
|
||||
"SELECT COUNT(*) FROM syncfolder WHERE synctype != 7", 0);
|
||||
|
||||
if (syncCnt < 1) {
|
||||
|
|
@ -440,10 +440,10 @@ void ptools_send_psyncs_event(const char *binapi, const char *auth) {
|
|||
pdbg_logf(D_NOTICE, "Syncs Count Event Result:[%d], Message: [%s] .", intRes,
|
||||
errMsg);
|
||||
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"REPLACE INTO setting (id, value) VALUES ('syncEventSentFlag', ?)");
|
||||
psync_sql_bind_uint(sql, 1, 1);
|
||||
psync_sql_run_free(sql);
|
||||
psql_bind_uint(sql, 1, 1);
|
||||
psql_run_free(sql);
|
||||
}
|
||||
|
||||
free(errMsg);
|
||||
|
|
@ -493,15 +493,15 @@ psync_syncid_t ptools_syncid_from_fid(psync_folderid_t fid) {
|
|||
psync_variant_row row;
|
||||
psync_syncid_t syncId = -1;
|
||||
|
||||
res = psync_sql_query("SELECT syncid FROM syncedfolder WHERE folderid = ?");
|
||||
res = psql_query("SELECT syncid FROM syncedfolder WHERE folderid = ?");
|
||||
|
||||
psync_sql_bind_uint(res, 1, fid);
|
||||
psql_bind_uint(res, 1, fid);
|
||||
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
if ((row = psql_fetch(res))) {
|
||||
syncId = psync_get_number(row[0]);
|
||||
}
|
||||
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
|
||||
return syncId;
|
||||
}
|
||||
|
|
@ -512,20 +512,20 @@ char *ptools_sfldr_by_syncid(uint64_t syncId) {
|
|||
const char *syncName;
|
||||
char *retName;
|
||||
|
||||
res = psync_sql_query("SELECT localpath FROM syncfolder sf WHERE sf.id = ?");
|
||||
res = psql_query("SELECT localpath FROM syncfolder sf WHERE sf.id = ?");
|
||||
|
||||
psync_sql_bind_uint(res, 1, syncId);
|
||||
psql_bind_uint(res, 1, syncId);
|
||||
|
||||
if ((row = psync_sql_fetch_row(res))) {
|
||||
if ((row = psql_fetch(res))) {
|
||||
syncName = psync_get_string(row[0]);
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
retName = strdup(syncName);
|
||||
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
|
||||
return retName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -467,21 +467,21 @@ int64_t do_ptree_public_link(const char *linkname, const char *root,
|
|||
ids2 = (char *)malloc(numfiles * FOLDERID_ENTRY_SIZE);
|
||||
idsp = ids2;
|
||||
for (i = 0; i < numfiles; ++i) {
|
||||
psync_sql_rdlock();
|
||||
psql_rdlock();
|
||||
filep = psync_fsfolder_resolve_path(files[i]);
|
||||
if (filep) {
|
||||
res = psync_sql_query_nolock("select id from file where parentfolderid "
|
||||
res = psql_query_nolock("select id from file where parentfolderid "
|
||||
"= ? and name = ? limit 1");
|
||||
psync_sql_bind_uint(res, 1, filep->folderid);
|
||||
psync_sql_bind_string(res, 2, filep->name);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, filep->folderid);
|
||||
psql_bind_str(res, 2, filep->name);
|
||||
row = psql_fetch_int(res);
|
||||
id = row[0];
|
||||
} else {
|
||||
psync_sql_rdunlock();
|
||||
psql_rdunlock();
|
||||
continue;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_rdunlock();
|
||||
psql_free(res);
|
||||
psql_rdunlock();
|
||||
|
||||
k = sprintf(idsp, "%lld", (long long)id);
|
||||
if (unlikely(k <= 0))
|
||||
|
|
@ -564,8 +564,8 @@ int cache_links(char *err, size_t err_size /*OUT*/) {
|
|||
int i, linkscnt;
|
||||
psync_sql_res *q;
|
||||
|
||||
q = psync_sql_prep_statement("DELETE FROM links WHERE isincomming = 0 ");
|
||||
psync_sql_run_free(q);
|
||||
q = psql_prepare("DELETE FROM links WHERE isincomming = 0 ");
|
||||
psql_run_free(q);
|
||||
|
||||
if (psync_my_auth[0]) {
|
||||
binparam params[] = {PAPI_STR("auth", psync_my_auth),
|
||||
|
|
@ -632,7 +632,7 @@ int cache_links(char *err, size_t err_size /*OUT*/) {
|
|||
for (i = 0; i < linkscnt; ++i) {
|
||||
link = publinks->array[i];
|
||||
|
||||
q = psync_sql_prep_statement(
|
||||
q = psql_prepare(
|
||||
"REPLACE INTO links (id, code, comment, traffic, maxspace, downloads, "
|
||||
"created,"
|
||||
" modified, name, isfolder, folderid, fileid, isincomming, icon, "
|
||||
|
|
@ -645,69 +645,69 @@ int cache_links(char *err, size_t err_size /*OUT*/) {
|
|||
pdbg_logf(D_WARNING, "cache links sql prep return NULL");
|
||||
return -1;
|
||||
}
|
||||
psync_sql_bind_uint(q, 1,
|
||||
psql_bind_uint(q, 1,
|
||||
papi_find_result2(link, "linkid", PARAM_NUM)->num);
|
||||
psync_sql_bind_string(q, 2,
|
||||
psql_bind_str(q, 2,
|
||||
papi_find_result2(link, "code", PARAM_STR)->str);
|
||||
psync_sql_bind_uint(q, 3, 0);
|
||||
psync_sql_bind_uint(q, 4,
|
||||
psql_bind_uint(q, 3, 0);
|
||||
psql_bind_uint(q, 4,
|
||||
papi_find_result2(link, "traffic", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 5, 0);
|
||||
psync_sql_bind_uint(q, 6,
|
||||
psql_bind_uint(q, 5, 0);
|
||||
psql_bind_uint(q, 6,
|
||||
papi_find_result2(link, "downloads", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 7,
|
||||
psql_bind_uint(q, 7,
|
||||
papi_find_result2(link, "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 8,
|
||||
psql_bind_uint(q, 8,
|
||||
papi_find_result2(link, "modified", PARAM_NUM)->num);
|
||||
meta = papi_find_result2(link, "metadata", PARAM_HASH);
|
||||
psync_sql_bind_string(q, 9,
|
||||
psql_bind_str(q, 9,
|
||||
papi_find_result2(meta, "name", PARAM_STR)->str);
|
||||
if (papi_find_result2(meta, "isfolder", PARAM_BOOL)->num) {
|
||||
psync_sql_bind_uint(q, 10, 1);
|
||||
psync_sql_bind_uint(q, 11,
|
||||
psql_bind_uint(q, 10, 1);
|
||||
psql_bind_uint(q, 11,
|
||||
papi_find_result2(meta, "folderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 12, 0);
|
||||
psql_bind_uint(q, 12, 0);
|
||||
if (papi_check_result2(link, "enableduploadforchosenusers", PARAM_BOOL)) {
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
q, 20,
|
||||
papi_find_result2(link, "enableduploadforchosenusers", PARAM_BOOL)
|
||||
->num);
|
||||
} else {
|
||||
psync_sql_bind_uint(q, 20, 0);
|
||||
psql_bind_uint(q, 20, 0);
|
||||
}
|
||||
if (papi_check_result2(link, "enableduploadforeveryone", PARAM_BOOL)) {
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
q, 21,
|
||||
papi_find_result2(link, "enableduploadforeveryone", PARAM_BOOL)
|
||||
->num);
|
||||
} else {
|
||||
psync_sql_bind_uint(q, 21, 0);
|
||||
psql_bind_uint(q, 21, 0);
|
||||
}
|
||||
} else {
|
||||
psync_sql_bind_uint(q, 10, 0);
|
||||
psync_sql_bind_uint(q, 11, 0);
|
||||
psync_sql_bind_uint(q, 12,
|
||||
psql_bind_uint(q, 10, 0);
|
||||
psql_bind_uint(q, 11, 0);
|
||||
psql_bind_uint(q, 12,
|
||||
papi_find_result2(meta, "fileid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 20, 0);
|
||||
psync_sql_bind_uint(q, 21, 0);
|
||||
psql_bind_uint(q, 20, 0);
|
||||
psql_bind_uint(q, 21, 0);
|
||||
}
|
||||
psync_sql_bind_uint(q, 13, papi_find_result2(meta, "icon", PARAM_NUM)->num);
|
||||
psync_sql_bind_string(q, 14,
|
||||
psql_bind_uint(q, 13, papi_find_result2(meta, "icon", PARAM_NUM)->num);
|
||||
psql_bind_str(q, 14,
|
||||
papi_find_result2(link, "link", PARAM_STR)->str);
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
q, 15, papi_find_result2(meta, "parentfolderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
q, 16, papi_find_result2(link, "haspassword", PARAM_BOOL)->num);
|
||||
psync_sql_bind_uint(q, 17,
|
||||
psql_bind_uint(q, 17,
|
||||
papi_find_result2(link, "views", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 18, papi_find_result2(link, "type", PARAM_NUM)->num);
|
||||
psql_bind_uint(q, 18, papi_find_result2(link, "type", PARAM_NUM)->num);
|
||||
if (papi_check_result2(link, "expires", PARAM_NUM))
|
||||
psync_sql_bind_uint(q, 19,
|
||||
psql_bind_uint(q, 19,
|
||||
papi_find_result2(link, "expires", PARAM_NUM)->num);
|
||||
else
|
||||
psync_sql_bind_uint(q, 19, 0);
|
||||
psql_bind_uint(q, 19, 0);
|
||||
|
||||
psync_sql_run_free(q);
|
||||
psql_run_free(q);
|
||||
}
|
||||
|
||||
free(bres);
|
||||
|
|
@ -1095,7 +1095,7 @@ plink_info_list_t *do_psync_list_links(char **err /*OUT*/) {
|
|||
builder = psync_list_builder_create(sizeof(link_info_t),
|
||||
offsetof(plink_info_list_t, entries));
|
||||
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, code, comment, traffic, maxspace, downloads, created,"
|
||||
" modified, name, isfolder, folderid, fileid, isincomming, icon, "
|
||||
"fulllink,"
|
||||
|
|
@ -1104,7 +1104,7 @@ plink_info_list_t *do_psync_list_links(char **err /*OUT*/) {
|
|||
|
||||
if (!res)
|
||||
return NULL;
|
||||
psync_list_bulder_add_sql(builder, res, create_link);
|
||||
psql_list_add(builder, res, create_link);
|
||||
|
||||
return (plink_info_list_t *)psync_list_builder_finalize(builder);
|
||||
}
|
||||
|
|
@ -1193,8 +1193,8 @@ int cache_upload_links(char **err /*OUT*/) {
|
|||
|
||||
*err = 0;
|
||||
|
||||
q = psync_sql_prep_statement("DELETE FROM links WHERE isincomming = 1 ");
|
||||
psync_sql_run_free(q);
|
||||
q = psql_prepare("DELETE FROM links WHERE isincomming = 1 ");
|
||||
psql_run_free(q);
|
||||
|
||||
if (psync_my_auth[0]) {
|
||||
binparam params[] = {PAPI_STR("auth", psync_my_auth),
|
||||
|
|
@ -1249,53 +1249,53 @@ int cache_upload_links(char **err /*OUT*/) {
|
|||
for (i = 0; i < linkscnt; ++i) {
|
||||
link = publinks->array[i];
|
||||
|
||||
q = psync_sql_prep_statement(
|
||||
q = psql_prepare(
|
||||
"REPLACE INTO links (id, code, comment, traffic, maxspace, downloads, "
|
||||
"created,"
|
||||
" modified, name, isfolder, folderid, fileid, isincomming, icon, "
|
||||
"fulllink,"
|
||||
" parentfolderid, haspassword, views, type)"
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?)");
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
q, 1, papi_find_result2(link, "uploadlinkid", PARAM_NUM)->num);
|
||||
psync_sql_bind_string(q, 2,
|
||||
psql_bind_str(q, 2,
|
||||
papi_find_result2(link, "code", PARAM_STR)->str);
|
||||
psync_sql_bind_string(q, 3,
|
||||
psql_bind_str(q, 3,
|
||||
papi_find_result2(link, "comment", PARAM_STR)->str);
|
||||
psync_sql_bind_uint(q, 4, papi_find_result2(link, "space", PARAM_NUM)->num);
|
||||
psql_bind_uint(q, 4, papi_find_result2(link, "space", PARAM_NUM)->num);
|
||||
if ((br = papi_check_result2(link, "maxspace", PARAM_NUM)))
|
||||
psync_sql_bind_uint(q, 5, br->num);
|
||||
psql_bind_uint(q, 5, br->num);
|
||||
else
|
||||
psync_sql_bind_uint(q, 5, 0);
|
||||
psync_sql_bind_uint(q, 6, papi_find_result2(link, "files", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 7,
|
||||
psql_bind_uint(q, 5, 0);
|
||||
psql_bind_uint(q, 6, papi_find_result2(link, "files", PARAM_NUM)->num);
|
||||
psql_bind_uint(q, 7,
|
||||
papi_find_result2(link, "created", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 8,
|
||||
psql_bind_uint(q, 8,
|
||||
papi_find_result2(link, "modified", PARAM_NUM)->num);
|
||||
|
||||
meta = papi_find_result2(link, "metadata", PARAM_HASH);
|
||||
psync_sql_bind_string(q, 9,
|
||||
psql_bind_str(q, 9,
|
||||
papi_find_result2(meta, "name", PARAM_STR)->str);
|
||||
if (papi_find_result2(meta, "isfolder", PARAM_BOOL)->num) {
|
||||
psync_sql_bind_uint(q, 10, 1);
|
||||
psync_sql_bind_uint(q, 11,
|
||||
psql_bind_uint(q, 10, 1);
|
||||
psql_bind_uint(q, 11,
|
||||
papi_find_result2(meta, "folderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 12, 0);
|
||||
psql_bind_uint(q, 12, 0);
|
||||
} else {
|
||||
psync_sql_bind_uint(q, 10, 0);
|
||||
psync_sql_bind_uint(q, 11, 0);
|
||||
psync_sql_bind_uint(q, 12,
|
||||
psql_bind_uint(q, 10, 0);
|
||||
psql_bind_uint(q, 11, 0);
|
||||
psql_bind_uint(q, 12,
|
||||
papi_find_result2(meta, "fileid", PARAM_NUM)->num);
|
||||
}
|
||||
psync_sql_bind_uint(q, 13, papi_find_result2(meta, "icon", PARAM_NUM)->num);
|
||||
psync_sql_bind_string(q, 14,
|
||||
psql_bind_uint(q, 13, papi_find_result2(meta, "icon", PARAM_NUM)->num);
|
||||
psql_bind_str(q, 14,
|
||||
papi_find_result2(link, "link", PARAM_STR)->str);
|
||||
psync_sql_bind_uint(
|
||||
psql_bind_uint(
|
||||
q, 15, papi_find_result2(meta, "parentfolderid", PARAM_NUM)->num);
|
||||
psync_sql_bind_uint(q, 16, 0);
|
||||
psync_sql_bind_uint(q, 17, 0);
|
||||
psync_sql_bind_uint(q, 18, 0);
|
||||
psync_sql_run_free(q);
|
||||
psql_bind_uint(q, 16, 0);
|
||||
psql_bind_uint(q, 17, 0);
|
||||
psql_bind_uint(q, 18, 0);
|
||||
psql_run_free(q);
|
||||
}
|
||||
|
||||
free(bres);
|
||||
|
|
@ -1327,12 +1327,12 @@ int do_delete_all_links(int64_t folderid, int64_t fileid, char **err) {
|
|||
psync_uint_row row;
|
||||
int ret = 0;
|
||||
|
||||
res = psync_sql_query_rdlock("SELECT id, folderid, fileid, isincomming FROM "
|
||||
res = psql_query_rdlock("SELECT id, folderid, fileid, isincomming FROM "
|
||||
"links where folderid = ? or fileid = ? ");
|
||||
psync_sql_bind_int(res, 1, folderid);
|
||||
psync_sql_bind_int(res, 2, fileid);
|
||||
psql_bind_int(res, 1, folderid);
|
||||
psql_bind_int(res, 2, fileid);
|
||||
|
||||
while ((row = psync_sql_fetch_rowint(res))) {
|
||||
while ((row = psql_fetch_int(res))) {
|
||||
if (row[3]) {
|
||||
ret = do_psync_delete_upload_link(row[0], err);
|
||||
if (ret)
|
||||
|
|
@ -1352,11 +1352,11 @@ int do_delete_all_folder_links(psync_folderid_t folderid, char **err) {
|
|||
int ret = 0;
|
||||
uint32_t i;
|
||||
|
||||
res = psync_sql_query_rdlock("SELECT id, folderid, fileid, isincomming FROM "
|
||||
res = psql_query_rdlock("SELECT id, folderid, fileid, isincomming FROM "
|
||||
"links where folderid = ? ");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
|
||||
rows = psync_sql_fetchall_int(res);
|
||||
rows = psql_fetchall_int(res);
|
||||
|
||||
for (i = 0; i < rows->rows; ++i) {
|
||||
if (psync_get_result_cell(rows, i, 3)) {
|
||||
|
|
@ -1378,11 +1378,11 @@ int do_delete_all_file_links(psync_fileid_t fileid, char **err) {
|
|||
int ret = 0;
|
||||
uint32_t i;
|
||||
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, folderid, fileid, isincomming FROM links where fileid = ? ");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
|
||||
rows = psync_sql_fetchall_int(res);
|
||||
rows = psql_fetchall_int(res);
|
||||
|
||||
for (i = 0; i < rows->rows; ++i) {
|
||||
if (psync_get_result_cell(rows, i, 3)) {
|
||||
|
|
|
|||
|
|
@ -146,14 +146,14 @@ static int task_wait_no_uploads(uint64_t taskid) {
|
|||
pdbg_logf(D_NOTICE, "waited for uploads to finish");
|
||||
}
|
||||
pthread_mutex_unlock(¤t_uploads_mutex);
|
||||
res = psync_sql_query("SELECT COUNT(*) FROM task WHERE id<? AND type=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_bind_uint(res, 2, PSYNC_UPLOAD_FILE);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
res = psql_query("SELECT COUNT(*) FROM task WHERE id<? AND type=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_bind_uint(res, 2, PSYNC_UPLOAD_FILE);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
cnt = row[0];
|
||||
else
|
||||
cnt = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (cnt) {
|
||||
pdbg_logf(D_NOTICE, "all uploads stopped, but there are still %u upload tasks",
|
||||
(unsigned)cnt);
|
||||
|
|
@ -204,17 +204,17 @@ static int task_createfolder(psync_syncid_t syncid,
|
|||
const binresult *meta;
|
||||
uint64_t result;
|
||||
int ret;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT s.folderid FROM localfolder l, syncedfolder s WHERE l.id=? AND "
|
||||
"l.syncid=? AND l.localparentfolderid=s.localfolderid AND s.syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfolderid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
psync_sql_bind_uint(res, 3, syncid);
|
||||
if (pdbg_likely(row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, localfolderid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
psql_bind_uint(res, 3, syncid);
|
||||
if (pdbg_likely(row = psql_fetch_int(res)))
|
||||
parentfolderid = row[0];
|
||||
else
|
||||
parentfolderid = PSYNC_INVALID_FOLDERID;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (unlikely(parentfolderid == PSYNC_INVALID_FOLDERID))
|
||||
return 0;
|
||||
else {
|
||||
|
|
@ -246,21 +246,21 @@ static int task_createfolder(psync_syncid_t syncid,
|
|||
folderid = papi_find_result2(meta, "folderid", PARAM_NUM)->num;
|
||||
pdbg_logf(D_NOTICE, "remote folder %lu %lu/%s created", (long unsigned)folderid,
|
||||
(long unsigned)parentfolderid, name);
|
||||
psync_sql_start_transaction();
|
||||
psql_start();
|
||||
pfileops_create_fldr(meta);
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE localfolder SET folderid=? WHERE id=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_uint(res, 2, localfolderid);
|
||||
psync_sql_bind_uint(res, 3, syncid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement("UPDATE syncedfolder SET folderid=? WHERE "
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_uint(res, 2, localfolderid);
|
||||
psql_bind_uint(res, 3, syncid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare("UPDATE syncedfolder SET folderid=? WHERE "
|
||||
"localfolderid=? AND syncid=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_uint(res, 2, localfolderid);
|
||||
psync_sql_bind_uint(res, 3, syncid);
|
||||
psync_sql_run_free(res);
|
||||
ret = psync_sql_commit_transaction();
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_uint(res, 2, localfolderid);
|
||||
psql_bind_uint(res, 3, syncid);
|
||||
psql_run_free(res);
|
||||
ret = psql_commit();
|
||||
pdiff_unlock();
|
||||
if (papi_find_result2(bres, "created", PARAM_BOOL)->num)
|
||||
pdiff_wake();
|
||||
|
|
@ -297,22 +297,22 @@ static int task_renamefile(uint64_t taskid, psync_syncid_t syncid,
|
|||
|
||||
if (task_wait_no_uploads(taskid))
|
||||
return -1;
|
||||
res = psync_sql_query_rdlock("SELECT fileid FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
res = psql_query_rdlock("SELECT fileid FROM localfile WHERE id=?");
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
fileid = row[0];
|
||||
else
|
||||
fileid = 0;
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query_rdlock(
|
||||
psql_free(res);
|
||||
res = psql_query_rdlock(
|
||||
"SELECT folderid FROM syncedfolder WHERE syncid=? AND localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, newlocalparentfolderid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, newlocalparentfolderid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
folderid = row[0];
|
||||
else
|
||||
folderid = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (pdbg_unlikely(!fileid) || pdbg_unlikely(!folderid))
|
||||
return 0;
|
||||
else
|
||||
|
|
@ -410,10 +410,10 @@ static int task_renameremotefolder(psync_folderid_t folderid,
|
|||
pdbg_logf(D_NOTICE, "remote folderid %lu moved/renamed to (%lu)/%s",
|
||||
(long unsigned)folderid, (long unsigned)newparentfolderid, newname);
|
||||
|
||||
if (!psync_sql_start_transaction()) {
|
||||
if (!psql_start()) {
|
||||
pfileops_update_fldr(
|
||||
papi_find_result2(res, "metadata", PARAM_HASH));
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
|
||||
pdiff_wake();
|
||||
|
|
@ -442,24 +442,24 @@ static int task_renamefolder(uint64_t taskid, psync_syncid_t syncid,
|
|||
psync_folderid_t folderid, parentfolderid;
|
||||
if (task_wait_no_uploads(taskid))
|
||||
return -1;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT folderid FROM syncedfolder WHERE syncid=? AND localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, localfolderid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, localfolderid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
folderid = row[0];
|
||||
else
|
||||
folderid = 0;
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_query_rdlock(
|
||||
psql_free(res);
|
||||
res = psql_query_rdlock(
|
||||
"SELECT folderid FROM syncedfolder WHERE syncid=? AND localfolderid=?");
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_bind_uint(res, 2, newlocalparentfolderid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_bind_uint(res, 2, newlocalparentfolderid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
parentfolderid = row[0];
|
||||
else
|
||||
parentfolderid = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
if (pdbg_unlikely(!folderid) || pdbg_unlikely(!parentfolderid))
|
||||
return 0;
|
||||
else
|
||||
|
|
@ -469,12 +469,12 @@ static int task_renamefolder(uint64_t taskid, psync_syncid_t syncid,
|
|||
static void set_local_file_remote_id(psync_fileid_t localfileid,
|
||||
psync_fileid_t fileid, uint64_t hash) {
|
||||
psync_sql_res *res;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE localfile SET fileid=?, hash=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
psync_sql_bind_uint(res, 2, hash);
|
||||
psync_sql_bind_uint(res, 3, localfileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
psql_bind_uint(res, 2, hash);
|
||||
psql_bind_uint(res, 3, localfileid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
|
||||
static void set_local_file_conflicted(psync_fileid_t localfileid,
|
||||
|
|
@ -484,23 +484,23 @@ static void set_local_file_conflicted(psync_fileid_t localfileid,
|
|||
psync_sql_res *res;
|
||||
char *newpath;
|
||||
pdbg_logf(D_NOTICE, "conflict found, renaming %s to %s", localpath, newname);
|
||||
psync_sql_start_transaction();
|
||||
res = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
res = psql_prepare(
|
||||
"UPDATE localfile SET fileid=?, hash=?, name=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fileid);
|
||||
psync_sql_bind_uint(res, 2, hash);
|
||||
psync_sql_bind_string(res, 3, newname);
|
||||
psync_sql_bind_uint(res, 4, localfileid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_prep_statement("UPDATE task SET name=? WHERE id=?");
|
||||
psync_sql_bind_string(res, 1, newname);
|
||||
psync_sql_bind_uint(res, 2, taskid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, fileid);
|
||||
psql_bind_uint(res, 2, hash);
|
||||
psql_bind_str(res, 3, newname);
|
||||
psql_bind_uint(res, 4, localfileid);
|
||||
psql_run_free(res);
|
||||
res = psql_prepare("UPDATE task SET name=? WHERE id=?");
|
||||
psql_bind_str(res, 1, newname);
|
||||
psql_bind_uint(res, 2, taskid);
|
||||
psql_run_free(res);
|
||||
newpath = pfolder_lpath_lfile(localfileid, NULL);
|
||||
if (pdbg_unlikely(pfile_rename_overwrite(localpath, newpath)))
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
else
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
free(newpath);
|
||||
}
|
||||
|
||||
|
|
@ -555,14 +555,14 @@ static int check_file_if_exists(const unsigned char *hashhex, uint64_t fsize,
|
|||
uint64_t filesize, hash;
|
||||
unsigned char shashhex[PSYNC_HASH_DIGEST_HEXLEN];
|
||||
int ret;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT id, size FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(res, 1, folderid);
|
||||
psync_sql_bind_string(res, 2, name);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
psql_bind_uint(res, 1, folderid);
|
||||
psql_bind_str(res, 2, name);
|
||||
row = psql_fetch_int(res);
|
||||
if (row && row[1] == fsize) {
|
||||
fileid = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
ret = psync_get_remote_file_checksum(fileid, shashhex, &filesize, &hash);
|
||||
if (ret == PSYNC_NET_OK) {
|
||||
if (filesize == fsize &&
|
||||
|
|
@ -583,7 +583,7 @@ static int check_file_if_exists(const unsigned char *hashhex, uint64_t fsize,
|
|||
else if (ret == PSYNC_NET_PERMFAIL)
|
||||
return 0;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -747,21 +747,21 @@ static int upload_file(const char *localpath, const unsigned char *hashhex,
|
|||
papi_find_result2(res, "checksums", PARAM_ARRAY)->array[0],
|
||||
PSYNC_CHECKSUM, PARAM_STR)
|
||||
->str;
|
||||
psync_sql_start_transaction();
|
||||
sres = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
sres = psql_prepare(
|
||||
"REPLACE INTO hashchecksum (hash, size, checksum) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(sres, 1, hash);
|
||||
psync_sql_bind_uint(sres, 2, rsize);
|
||||
psync_sql_bind_lstring(sres, 3, hashhexsrv, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psync_sql_run_free(sres);
|
||||
psql_bind_uint(sres, 1, hash);
|
||||
psql_bind_uint(sres, 2, rsize);
|
||||
psql_bind_lstr(sres, 3, hashhexsrv, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psql_run_free(sres);
|
||||
if (papi_check_result2(meta, "conflicted", PARAM_BOOL)) {
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
set_local_file_conflicted(localfileid, fileid, hash, localpath,
|
||||
papi_find_result2(meta, "name", PARAM_STR)->str,
|
||||
upload->taskid);
|
||||
} else {
|
||||
set_local_file_remote_id(localfileid, fileid, hash);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
pdiff_unlock();
|
||||
if (rsize != fsize || memcmp(hashhexsrv, hashhex, PSYNC_HASH_DIGEST_HEXLEN)) {
|
||||
|
|
@ -919,22 +919,22 @@ static int upload_save(psock_t *api, psync_fileid_t localfileid,
|
|||
meta = papi_find_result2(res, "metadata", PARAM_HASH);
|
||||
fileid = papi_find_result2(meta, "fileid", PARAM_NUM)->num;
|
||||
hash = papi_find_result2(meta, "hash", PARAM_NUM)->num;
|
||||
psync_sql_start_transaction();
|
||||
sres = psync_sql_prep_statement(
|
||||
psql_start();
|
||||
sres = psql_prepare(
|
||||
"REPLACE INTO hashchecksum (hash, size, checksum) VALUES (?, ?, ?)");
|
||||
psync_sql_bind_uint(sres, 1, hash);
|
||||
psync_sql_bind_uint(sres, 2, size);
|
||||
psync_sql_bind_lstring(sres, 3, (const char *)hashhex,
|
||||
psql_bind_uint(sres, 1, hash);
|
||||
psql_bind_uint(sres, 2, size);
|
||||
psql_bind_lstr(sres, 3, (const char *)hashhex,
|
||||
PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psync_sql_run_free(sres);
|
||||
psql_run_free(sres);
|
||||
if (papi_check_result2(meta, "conflicted", PARAM_BOOL)) {
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
set_local_file_conflicted(
|
||||
localfileid, fileid, hash, localpath,
|
||||
papi_find_result2(meta, "name", PARAM_STR)->str, taskid);
|
||||
} else {
|
||||
set_local_file_remote_id(localfileid, fileid, hash);
|
||||
psync_sql_commit_transaction();
|
||||
psql_commit();
|
||||
}
|
||||
ret = PSYNC_NET_OK;
|
||||
pdiff_wake();
|
||||
|
|
@ -993,25 +993,25 @@ static int upload_big_file(const char *localpath, const unsigned char *hashhex,
|
|||
}
|
||||
uploadid = papi_find_result2(res, "uploadid", PARAM_NUM)->num;
|
||||
free(res);
|
||||
psync_sql_start_transaction();
|
||||
sql = psync_sql_query_nolock("SELECT id FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, localfileid);
|
||||
row = psync_sql_fetch_rowint(sql);
|
||||
psync_sql_free_result(sql);
|
||||
psql_start();
|
||||
sql = psql_query_nolock("SELECT id FROM localfile WHERE id=?");
|
||||
psql_bind_uint(sql, 1, localfileid);
|
||||
row = psql_fetch_int(sql);
|
||||
psql_free(sql);
|
||||
if (!row) {
|
||||
psync_sql_rollback_transaction();
|
||||
psql_rollback();
|
||||
pdbg_logf(D_NOTICE,
|
||||
"local file %s (%lu) disappeard from localfile while creating "
|
||||
"upload, failing task",
|
||||
localpath, (unsigned long)localfileid);
|
||||
return -1;
|
||||
}
|
||||
sql = psync_sql_prep_statement(
|
||||
sql = psql_prepare(
|
||||
"INSERT INTO localfileupload (localfileid, uploadid) VALUES (?, ?)");
|
||||
psync_sql_bind_uint(sql, 1, localfileid);
|
||||
psync_sql_bind_uint(sql, 2, uploadid);
|
||||
psync_sql_run_free(sql);
|
||||
psync_sql_commit_transaction();
|
||||
psql_bind_uint(sql, 1, localfileid);
|
||||
psql_bind_uint(sql, 2, uploadid);
|
||||
psql_run_free(sql);
|
||||
psql_commit();
|
||||
}
|
||||
psync_list_init(&rlist);
|
||||
if (likely(uploadoffset < fsize)) {
|
||||
|
|
@ -1033,52 +1033,52 @@ static int upload_big_file(const char *localpath, const unsigned char *hashhex,
|
|||
uint64_t fileid, hash;
|
||||
fileid = 0;
|
||||
sql =
|
||||
psync_sql_query_rdlock("SELECT fileid, hash FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, localfileid);
|
||||
if ((row = psync_sql_fetch_rowint(sql))) {
|
||||
psql_query_rdlock("SELECT fileid, hash FROM localfile WHERE id=?");
|
||||
psql_bind_uint(sql, 1, localfileid);
|
||||
if ((row = psql_fetch_int(sql))) {
|
||||
fileid = row[0];
|
||||
hash = row[1];
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
pdbg_logf(D_NOTICE, "fileid(local)=%lu", (unsigned long)fileid);
|
||||
if (fileid && psync_net_scan_file_for_blocks(api, &rlist, fileid, hash,
|
||||
fd) == PSYNC_NET_TEMPFAIL)
|
||||
goto err1;
|
||||
} else
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
if (!fileid) {
|
||||
pdbg_logf(D_NOTICE, "looking for folderid=%lu and name=%s in file",
|
||||
(unsigned long)folderid, name);
|
||||
sql = psync_sql_query_rdlock(
|
||||
sql = psql_query_rdlock(
|
||||
"SELECT id, hash FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(sql, 1, folderid);
|
||||
psync_sql_bind_string(sql, 2, name);
|
||||
if ((row = psync_sql_fetch_rowint(sql))) {
|
||||
psql_bind_uint(sql, 1, folderid);
|
||||
psql_bind_str(sql, 2, name);
|
||||
if ((row = psql_fetch_int(sql))) {
|
||||
fileid = row[0];
|
||||
hash = row[1];
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
pdbg_logf(D_NOTICE, "fileid(file)=%lu", (unsigned long)fileid);
|
||||
if (fileid && psync_net_scan_file_for_blocks(api, &rlist, fileid, hash,
|
||||
fd) == PSYNC_NET_TEMPFAIL)
|
||||
goto err1;
|
||||
} else
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
}
|
||||
if (!fileid) {
|
||||
sql = psync_sql_query_rdlock("SELECT name FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(sql, 1, localfileid);
|
||||
if ((srow = psync_sql_fetch_rowstr(sql))) {
|
||||
sql = psql_query_rdlock("SELECT name FROM localfile WHERE id=?");
|
||||
psql_bind_uint(sql, 1, localfileid);
|
||||
if ((srow = psql_fetch_str(sql))) {
|
||||
char *nname = psync_strdup(srow[0]);
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
pdbg_logf(D_NOTICE, "looking for folderid=%lu and name=%s in file",
|
||||
(unsigned long)folderid, nname);
|
||||
sql = psync_sql_query_rdlock(
|
||||
sql = psql_query_rdlock(
|
||||
"SELECT id, hash FROM file WHERE parentfolderid=? AND name=?");
|
||||
psync_sql_bind_uint(sql, 1, folderid);
|
||||
psync_sql_bind_string(sql, 2, nname);
|
||||
if ((row = psync_sql_fetch_rowint(sql))) {
|
||||
psql_bind_uint(sql, 1, folderid);
|
||||
psql_bind_str(sql, 2, nname);
|
||||
if ((row = psql_fetch_int(sql))) {
|
||||
fileid = row[0];
|
||||
hash = row[1];
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
pdbg_logf(D_NOTICE, "fileid(file, local name)=%lu",
|
||||
(unsigned long)fileid);
|
||||
if (fileid &&
|
||||
|
|
@ -1088,16 +1088,16 @@ static int upload_big_file(const char *localpath, const unsigned char *hashhex,
|
|||
goto err1;
|
||||
}
|
||||
} else
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
free(nname);
|
||||
} else
|
||||
psync_sql_free_result(sql);
|
||||
psql_free(sql);
|
||||
}
|
||||
sql =
|
||||
psync_sql_query_rdlock("SELECT uploadid FROM localfileupload WHERE "
|
||||
psql_query_rdlock("SELECT uploadid FROM localfileupload WHERE "
|
||||
"localfileid=? ORDER BY uploadid DESC LIMIT 5");
|
||||
psync_sql_bind_uint(sql, 1, localfileid);
|
||||
fr = psync_sql_fetchall_int(sql);
|
||||
psql_bind_uint(sql, 1, localfileid);
|
||||
fr = psql_fetchall_int(sql);
|
||||
for (id = 0; id < fr->rows; id++)
|
||||
if (psync_get_result_cell(fr, id, 0) != uploadid &&
|
||||
psync_net_scan_upload_for_blocks(api, &rlist,
|
||||
|
|
@ -1282,17 +1282,17 @@ static void delete_uploadids(psync_fileid_t localfileid) {
|
|||
psync_sql_res *res;
|
||||
psync_full_result_int *rows;
|
||||
uint32_t i;
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT uploadid FROM localfileupload WHERE localfileid=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
rows = psync_sql_fetchall_int(res);
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
rows = psql_fetchall_int(res);
|
||||
if (rows->rows) {
|
||||
for (i = 0; i < rows->rows; i++)
|
||||
delete_uploadid(psync_get_result_cell(rows, i, 0));
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"DELETE FROM localfileupload WHERE localfileid=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
free(rows);
|
||||
}
|
||||
|
|
@ -1300,19 +1300,19 @@ static void delete_uploadids(psync_fileid_t localfileid) {
|
|||
static void delete_from_localfile(psync_fileid_t localfileid) {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
res = psync_sql_query(
|
||||
res = psql_query(
|
||||
"SELECT syncid, localparentfolderid FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
psync_syncid_t syncid = row[0];
|
||||
psync_folderid_t folderid = row[1];
|
||||
psync_sql_free_result(res);
|
||||
res = psync_sql_prep_statement("DELETE FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
psync_sql_run_free(res);
|
||||
psql_free(res);
|
||||
res = psql_prepare("DELETE FROM localfile WHERE id=?");
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
psql_run_free(res);
|
||||
ppathstatus_syncfldr_task_completed(syncid, folderid);
|
||||
} else
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
|
||||
static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
|
||||
|
|
@ -1387,14 +1387,14 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
|
|||
psys_sleep_milliseconds(PSYNC_SLEEP_ON_LOCKED_FILE);
|
||||
return -1;
|
||||
}
|
||||
res = psync_sql_query_rdlock("SELECT uploadid FROM localfileupload WHERE "
|
||||
res = psql_query_rdlock("SELECT uploadid FROM localfileupload WHERE "
|
||||
"localfileid=? ORDER BY uploadid DESC LIMIT 1");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
uploadid = row[0];
|
||||
else
|
||||
uploadid = 0;
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
ufsize = 0;
|
||||
if (uploadid) {
|
||||
ret = psync_get_upload_checksum(uploadid, uhashhex, &ufsize);
|
||||
|
|
@ -1425,34 +1425,34 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
|
|||
pthread_mutex_unlock(¤t_uploads_mutex);
|
||||
upload->filesize = fsize;
|
||||
}
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"UPDATE localfile SET size=?, checksum=? WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, fsize);
|
||||
psync_sql_bind_lstring(res, 2, (char *)hashhex, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psync_sql_bind_uint(res, 3, localfileid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_query_rdlock(
|
||||
psql_bind_uint(res, 1, fsize);
|
||||
psql_bind_lstr(res, 2, (char *)hashhex, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
psql_bind_uint(res, 3, localfileid);
|
||||
psql_run_free(res);
|
||||
res = psql_query_rdlock(
|
||||
"SELECT s.folderid FROM localfile f, syncedfolder s WHERE f.id=? AND "
|
||||
"f.localparentfolderid=s.localfolderid AND s.syncid=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
psync_sql_bind_uint(res, 2, syncid);
|
||||
if (pdbg_likely(row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
psql_bind_uint(res, 2, syncid);
|
||||
if (pdbg_likely(row = psql_fetch_int(res)))
|
||||
folderid = row[0];
|
||||
else {
|
||||
pdbg_logf(D_WARNING, "could not get remote folderid for local file %lu",
|
||||
(unsigned long)localfileid);
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
psync_unlock_file(lock);
|
||||
free(localpath);
|
||||
return 0;
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
nname = NULL;
|
||||
if (strchr(name, PSYNC_REPLACE_INV_CH_IN_FILENAMES)) {
|
||||
res = psync_sql_query_rdlock("SELECT f.name FROM localfile lf, file f "
|
||||
res = psql_query_rdlock("SELECT f.name FROM localfile lf, file f "
|
||||
"WHERE lf.id=? AND lf.fileid=f.id");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
srow = psync_sql_fetch_rowstr(res);
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
srow = psql_fetch_str(res);
|
||||
if (srow && strcmp(srow[0], name)) {
|
||||
const char *s1 = srow[0], *s2 = name;
|
||||
while (*s1 && *s2 &&
|
||||
|
|
@ -1467,7 +1467,7 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
|
|||
name = nname;
|
||||
}
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
}
|
||||
ret = check_file_if_exists(hashhex, fsize, folderid, name, localfileid, &st);
|
||||
/* PSYNC_MIN_SIZE_FOR_EXISTS_CHECK should be low enough not to waste bandwidth
|
||||
|
|
@ -1484,10 +1484,10 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
|
|||
return ret == 1 ? 0 : -1;
|
||||
}
|
||||
memcpy(upload->hash, hashhex, PSYNC_HASH_DIGEST_HEXLEN);
|
||||
res = psync_sql_query_rdlock(
|
||||
res = psql_query_rdlock(
|
||||
"SELECT hash FROM localfile WHERE hash IS NOT NULL AND id=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psync_sql_fetch_rowint(res))) {
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psql_fetch_int(res))) {
|
||||
pr.paramtype = PARAM_NUM;
|
||||
pr.paramnamelen = 6;
|
||||
pr.paramname = "ifhash";
|
||||
|
|
@ -1499,7 +1499,7 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
|
|||
pr.opts = 3;
|
||||
pr.str = "new";
|
||||
}
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_NOTICE, "uploading file %s", localpath);
|
||||
if (fsize <= PSYNC_MIN_SIZE_FOR_CHECKSUMS)
|
||||
ret = upload_file(localpath, hashhex, fsize, folderid, name, localfileid,
|
||||
|
|
@ -1532,17 +1532,17 @@ static int task_uploadfile(psync_syncid_t syncid, psync_folderid_t localfileid,
|
|||
static void delete_upload_task(uint64_t taskid, psync_fileid_t localfileid) {
|
||||
psync_sql_res *res;
|
||||
psync_uint_row row;
|
||||
psync_sql_lock();
|
||||
res = psync_sql_prep_statement("DELETE FROM task WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psync_sql_query_nolock(
|
||||
psql_lock();
|
||||
res = psql_prepare("DELETE FROM task WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
res = psql_query_nolock(
|
||||
"SELECT syncid, localparentfolderid FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psync_sql_fetch_rowint(res)))
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
if ((row = psql_fetch_int(res)))
|
||||
ppathstatus_syncfldr_task_completed(row[0], row[1]);
|
||||
psync_sql_free_result(res);
|
||||
psync_sql_unlock();
|
||||
psql_free(res);
|
||||
psql_unlock();
|
||||
}
|
||||
|
||||
static void task_run_upload_file_thread(void *ptr) {
|
||||
|
|
@ -1552,9 +1552,9 @@ static void task_run_upload_file_thread(void *ptr) {
|
|||
if (task_uploadfile(ut->upllist.syncid, ut->upllist.localfileid, ut->filename,
|
||||
&ut->upllist)) {
|
||||
psys_sleep_milliseconds(PSYNC_SLEEP_ON_FAILED_DOWNLOAD);
|
||||
res = psync_sql_prep_statement("UPDATE task SET inprogress=0 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, ut->upllist.taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE task SET inprogress=0 WHERE id=?");
|
||||
psql_bind_uint(res, 1, ut->upllist.taskid);
|
||||
psql_run_free(res);
|
||||
pupload_wake();
|
||||
} else
|
||||
delete_upload_task(ut->upllist.taskid, ut->upllist.localfileid);
|
||||
|
|
@ -1582,21 +1582,21 @@ static int task_run_uploadfile(uint64_t taskid, psync_syncid_t syncid,
|
|||
uint64_t filesize;
|
||||
size_t len;
|
||||
int stop;
|
||||
res = psync_sql_query_rdlock("SELECT size FROM localfile WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, localfileid);
|
||||
row = psync_sql_fetch_rowint(res);
|
||||
res = psql_query_rdlock("SELECT size FROM localfile WHERE id=?");
|
||||
psql_bind_uint(res, 1, localfileid);
|
||||
row = psql_fetch_int(res);
|
||||
if (likely(row)) {
|
||||
filesize = row[0];
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
} else {
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pdbg_logf(D_WARNING, "could not get size for local file %s (localfileid %lu)",
|
||||
filename, (unsigned long)localfileid);
|
||||
return 0;
|
||||
}
|
||||
res = psync_sql_prep_statement("UPDATE task SET inprogress=1 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE task SET inprogress=1 WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
len = strlen(filename);
|
||||
ut = (upload_task_t *)malloc(offsetof(upload_task_t, filename) + len +
|
||||
1);
|
||||
|
|
@ -1629,9 +1629,9 @@ static int task_run_uploadfile(uint64_t taskid, psync_syncid_t syncid,
|
|||
pthread_mutex_unlock(¤t_uploads_mutex);
|
||||
if (stop) {
|
||||
free(ut);
|
||||
res = psync_sql_prep_statement("UPDATE task SET inprogress=0 WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("UPDATE task SET inprogress=0 WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
} else {
|
||||
pstatus_send_update();
|
||||
prun_thread1("upload file", task_run_upload_file_thread, ut);
|
||||
|
|
@ -1710,7 +1710,7 @@ static void upload_thread() {
|
|||
while (psync_do_run) {
|
||||
pstatus_wait_statuses_arr(requiredstatuses, ARRAY_SIZE(requiredstatuses));
|
||||
|
||||
row = psync_sql_row("SELECT id, type, syncid, itemid, localitemid, "
|
||||
row = psql_row("SELECT id, type, syncid, itemid, localitemid, "
|
||||
"newitemid, name, newsyncid FROM task WHERE "
|
||||
"type&" NTO_STR(PSYNC_TASK_DWLUPL_MASK) "=" NTO_STR(
|
||||
PSYNC_TASK_UPLOAD) " AND inprogress=0 ORDER BY id "
|
||||
|
|
@ -1727,9 +1727,9 @@ static void upload_thread() {
|
|||
delete_upload_task(taskid, psync_get_number(row[3]));
|
||||
pstatus_upload_recalc_async();
|
||||
} else {
|
||||
res = psync_sql_prep_statement("DELETE FROM task WHERE id=?");
|
||||
psync_sql_bind_uint(res, 1, taskid);
|
||||
psync_sql_run_free(res);
|
||||
res = psql_prepare("DELETE FROM task WHERE id=?");
|
||||
psql_bind_uint(res, 1, taskid);
|
||||
psql_run_free(res);
|
||||
}
|
||||
} else if (type != PSYNC_UPLOAD_FILE)
|
||||
psys_sleep_milliseconds(PSYNC_SLEEP_ON_FAILED_UPLOAD);
|
||||
|
|
@ -1760,14 +1760,14 @@ void pupload_init() {
|
|||
void pupload_del_tasks(psync_fileid_t localfileid) {
|
||||
psync_sql_res *res;
|
||||
upload_list_t *upl;
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"DELETE FROM task WHERE type=? AND localitemid=?");
|
||||
psync_sql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
psync_sql_bind_uint(res, 2, localfileid);
|
||||
psync_sql_run(res);
|
||||
if (psync_sql_affected_rows())
|
||||
psql_bind_uint(res, 1, PSYNC_UPLOAD_FILE);
|
||||
psql_bind_uint(res, 2, localfileid);
|
||||
psql_run(res);
|
||||
if (psql_affected())
|
||||
pstatus_upload_recalc_async();
|
||||
psync_sql_free_result(res);
|
||||
psql_free(res);
|
||||
pthread_mutex_lock(¤t_uploads_mutex);
|
||||
psync_list_for_each_element(upl, &uploads, upload_list_t,
|
||||
list) if (upl->localfileid == localfileid)
|
||||
|
|
@ -1779,11 +1779,11 @@ void pupload_stop_sync(psync_syncid_t syncid) {
|
|||
upload_list_t *upl;
|
||||
psync_sql_res *res;
|
||||
|
||||
res = psync_sql_prep_statement(
|
||||
res = psql_prepare(
|
||||
"DELETE FROM task WHERE syncid=? AND type&" NTO_STR(
|
||||
PSYNC_TASK_DWLUPL_MASK) "=" NTO_STR(PSYNC_TASK_UPLOAD));
|
||||
psync_sql_bind_uint(res, 1, syncid);
|
||||
psync_sql_run_free(res);
|
||||
psql_bind_uint(res, 1, syncid);
|
||||
psql_run_free(res);
|
||||
|
||||
pthread_mutex_lock(¤t_uploads_mutex);
|
||||
psync_list_for_each_element(upl, &uploads, upload_list_t,
|
||||
|
|
|
|||
Loading…
Reference in New Issue