Skip to content

Commit

Permalink
Merge branch 'develop' into KDESKTOP-744-Change-CMake-files-to-build-…
Browse files Browse the repository at this point in the history
…in-RelWithDebInfo

# Conflicts:
#	.github/workflows/windows.yml
  • Loading branch information
MaximePouce committed Apr 29, 2024
2 parents 0d017fa + 4cb0243 commit 8f87979
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 18 deletions.
4 changes: 2 additions & 2 deletions VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set( KDRIVE_VERSION_MAJOR 3 )
set( KDRIVE_VERSION_MINOR 5 )
set( KDRIVE_VERSION_PATCH 9 )
set( KDRIVE_VERSION_MINOR 6 )
set( KDRIVE_VERSION_PATCH 0 )
set( KDRIVE_VERSION_YEAR 2024 )
set( KDRIVE_SOVERSION 0 )

Expand Down
4 changes: 2 additions & 2 deletions infomaniak-build-tools/windows/build-drive.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ $binaries = @(
)

$testers = @(
"kDrive_test_common.exe"
# "kDrive_test_parms.exe",
"kDrive_test_common.exe",
"kDrive_test_parms.exe"
# "kDrive_test_syncengine.exe"
)

Expand Down
40 changes: 39 additions & 1 deletion src/gui/guirequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,45 @@ ExitCode GuiRequests::setLaunchOnStartup(bool enabled) {
return ExitCodeSystemError;
}

ExitCode exitCode;
ExitCode exitCode = ExitCodeUnknown;
QDataStream resultStream(&results, QIODevice::ReadOnly);
resultStream >> exitCode;

return exitCode;
}

ExitCode GuiRequests::getAppState(AppStateKey key, QString &value) {
QByteArray params;
QDataStream paramsStream(&params, QIODevice::WriteOnly);
paramsStream << key;

QByteArray results;
if (!CommClient::instance()->execute(REQUEST_NUM_UTILITY_GET_APPSTATE, params, results)) {
return ExitCodeSystemError;
}

ExitCode exitCode = ExitCodeUnknown;
QDataStream resultStream(&results, QIODevice::ReadOnly);
resultStream >> exitCode;
if (exitCode == ExitCodeOk) {
resultStream >> value;
}

return exitCode;
}

ExitCode GuiRequests::updateAppState(AppStateKey key, const QString &value) {
QByteArray params;
QDataStream paramsStream(&params, QIODevice::WriteOnly);
paramsStream << key;
paramsStream << value;

QByteArray results;
if (!CommClient::instance()->execute(REQUEST_NUM_UTILITY_SET_APPSTATE, params, results)) {
return ExitCodeSystemError;
}

ExitCode exitCode = ExitCodeUnknown;
QDataStream resultStream(&results, QIODevice::ReadOnly);
resultStream >> exitCode;

Expand Down
2 changes: 2 additions & 0 deletions src/gui/guirequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ struct GuiRequests {
static ExitCode hasSystemLaunchOnStartup(bool &enabled);
static ExitCode hasLaunchOnStartup(bool &enabled);
static ExitCode setLaunchOnStartup(bool enabled);
static ExitCode getAppState(AppStateKey key, QString &value);
static ExitCode updateAppState(AppStateKey key, const QString &value);
};

} // namespace KDC
2 changes: 2 additions & 0 deletions src/libcommon/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ typedef enum {
REQUEST_NUM_UTILITY_HASSYSTEMLAUNCHONSTARTUP,
REQUEST_NUM_UTILITY_HASLAUNCHONSTARTUP,
REQUEST_NUM_UTILITY_SETLAUNCHONSTARTUP,
REQUEST_NUM_UTILITY_SET_APPSTATE,
REQUEST_NUM_UTILITY_GET_APPSTATE,
REQUEST_NUM_UPDATER_VERSION,
REQUEST_NUM_UPDATER_ISKDCUPDATER,
REQUEST_NUM_UPDATER_ISSPARKLEUPDATER,
Expand Down
6 changes: 6 additions & 0 deletions src/libcommon/utility/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,10 @@ struct ItemType {
// `LinkTypeUnknown`) and its target doesn't exist.
IoError ioError{IoErrorSuccess};
};

enum class AppStateKey {
// Adding a new key here requires to add it in insertDefaultAppState in parmsdbappstate.cpp and ideally testparmsdb.cpp
Unknown, // Used for initialization, will throw error if used
Test // To be removed after the implementation of the first key
};
} // namespace KDC
2 changes: 2 additions & 0 deletions src/libcommon/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ bool CommonUtility::isVersionLower(const std::string &currentVersion, const std:
for (size_t i = 0; i < targetTabVersion.size(); i++) {
if (currTabVersion[i] > targetTabVersion[i]) {
return false;
} else if (currTabVersion[i] < targetTabVersion[i]) {
return true;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libparms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(parms_SRCS
db/error.h db/error.cpp
db/migrationselectivesync.h db/migrationselectivesync.cpp
db/uploadsessiontoken.h db/uploadsessiontoken.cpp
db/parmsdbappstate.h db/parmsdbappstate.cpp
)

if (APPLE)
Expand Down
24 changes: 19 additions & 5 deletions src/libparms/db/parmsdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ bool ParmsDb::create(bool &retry) {
}
queryFree(CREATE_SELF_RESTARTER_TABLE_ID);

// app state
createAppState();

// Migration old selectivesync table
ASSERT(queryCreate(CREATE_MIGRATION_SELECTIVESYNC_TABLE_ID));
if (!queryPrepare(CREATE_MIGRATION_SELECTIVESYNC_TABLE_ID, CREATE_MIGRATION_SELECTIVESYNC_TABLE, false, errId, error)) {
Expand Down Expand Up @@ -1292,7 +1295,8 @@ bool ParmsDb::prepare() {
}

ASSERT(queryCreate(SELECT_ALL_MIGRATION_SELECTIVESYNC_REQUEST_ID));
if (!queryPrepare(SELECT_ALL_MIGRATION_SELECTIVESYNC_REQUEST_ID, SELECT_ALL_MIGRATION_SELECTIVESYNC_REQUEST, false, errId, error)) {
if (!queryPrepare(SELECT_ALL_MIGRATION_SELECTIVESYNC_REQUEST_ID, SELECT_ALL_MIGRATION_SELECTIVESYNC_REQUEST, false, errId,
error)) {
queryFree(SELECT_ALL_MIGRATION_SELECTIVESYNC_REQUEST_ID);
return sqlFail(SELECT_ALL_MIGRATION_SELECTIVESYNC_REQUEST_ID, error);
}
Expand Down Expand Up @@ -1322,6 +1326,9 @@ bool ParmsDb::prepare() {
return sqlFail(INSERT_SELF_RESTARTER_REQUEST_ID, error);
}

// App state
prepareAppState();

if (!initData()) {
LOG_WARN(_logger, "Error in initParameters");
return false;
Expand Down Expand Up @@ -1402,7 +1409,6 @@ bool ParmsDb::upgrade(const std::string &fromVersion, const std::string & /*toVe
LOG_DEBUG(_logger, "Upgrade < 3.6.1 DB");

queryFree(CREATE_SELF_RESTARTER_TABLE_ID);

ASSERT(queryCreate(CREATE_SELF_RESTARTER_TABLE_ID));
if (!queryPrepare(CREATE_SELF_RESTARTER_TABLE_ID, CREATE_SELF_RESTARTER_TABLE, false, errId, error)) {
queryFree(CREATE_SELF_RESTARTER_TABLE_ID);
Expand All @@ -1414,6 +1420,8 @@ bool ParmsDb::upgrade(const std::string &fromVersion, const std::string & /*toVe
return sqlFail(CREATE_SELF_RESTARTER_TABLE_ID, error);
}
queryFree(CREATE_SELF_RESTARTER_TABLE_ID);

createAppState();
}

return true;
Expand Down Expand Up @@ -1442,6 +1450,11 @@ bool ParmsDb::initData() {
return false;
}

if (!insertDefaultAppState()) {
LOG_WARN(_logger, "Error in insertDefaultAppState");
return false;
}

// Update exclusion templates
if (!updateExclusionTemplates()) {
LOG_WARN(_logger, "Error in updateExclusionTemplates");
Expand Down Expand Up @@ -3326,12 +3339,12 @@ bool ParmsDb::selectLastClientSelfRestartTime(int64_t &lastClientRestartTime) {
return true;
}


bool ParmsDb::updateLastServerSelfRestartTime(int64_t lastServertRestartTime) {
const std::scoped_lock lock(_mutex);

if (lastServertRestartTime == -1) {
lastServertRestartTime = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()).time_since_epoch().count();
lastServertRestartTime =
std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()).time_since_epoch().count();
}

ASSERT(queryResetAndClearBindings(UPDATE_SELF_RESTARTER_SERVER_REQUEST_ID));
Expand All @@ -3353,7 +3366,8 @@ bool ParmsDb::updateLastClientSelfRestartTime(int64_t lastClientRestartTime) {
const std::scoped_lock lock(_mutex);

if (lastClientRestartTime == -1) {
lastClientRestartTime = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()).time_since_epoch().count();
lastClientRestartTime =
std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()).time_since_epoch().count();
}

ASSERT(queryResetAndClearBindings(UPDATE_SELF_RESTARTER_CLIENT_REQUEST_ID));
Expand Down
10 changes: 9 additions & 1 deletion src/libparms/db/parmsdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ class PARMS_EXPORT ParmsDb : public Db {

bool selectLastServerSelfRestartTime(int64_t &lastServerRestartTime);
bool selectLastClientSelfRestartTime(int64_t &lastClientRestartTime);

bool updateLastServerSelfRestartTime(int64_t lastServerRestartTime = -1 /* -1 means now*/);
bool updateLastClientSelfRestartTime(int64_t lastClientRestartTime = -1 /* -1 means now*/);

bool selectAppState(AppStateKey key, std::string &value, bool& found);
bool updateAppState(AppStateKey key, const std::string &value, bool& found); // update or insert


private:
static std::shared_ptr<ParmsDb> _instance;
bool _test;
Expand All @@ -136,7 +139,12 @@ class PARMS_EXPORT ParmsDb : public Db {

bool insertDefaultParameters();
bool insertDefaultSelfRestarterData();
bool insertDefaultAppState();
bool updateExclusionTemplates();

bool createAppState();
bool prepareAppState();

#ifdef __APPLE__
bool updateExclusionApps();
#endif
Expand Down
139 changes: 139 additions & 0 deletions src/libparms/db/parmsdbappstate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Infomaniak kDrive - Desktop
* Copyright (C) 2023-2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "parmsdb.h"
#include "parmsdbappstate.h"
#include "libcommonserver/utility/asserts.h"


namespace KDC {

bool ParmsDb::createAppState() {
int errId = 0;
std::string error;

ASSERT(queryCreate(CREATE_APP_STATE_TABLE_ID));
if (!queryPrepare(CREATE_APP_STATE_TABLE_ID, CREATE_APP_STATE_TABLE, false, errId, error)) {
queryFree(CREATE_APP_STATE_TABLE_ID);
return sqlFail(CREATE_APP_STATE_TABLE_ID, error);
}
if (!queryExec(CREATE_APP_STATE_TABLE_ID, errId, error)) {
queryFree(CREATE_APP_STATE_TABLE_ID);
return sqlFail(CREATE_APP_STATE_TABLE_ID, error);
}
queryFree(CREATE_APP_STATE_TABLE_ID);
return true;
}

bool ParmsDb::prepareAppState() {
int errId = 0;
std::string error;

ASSERT(queryCreate(INSERT_APP_STATE_REQUEST_ID));
if (!queryPrepare(INSERT_APP_STATE_REQUEST_ID, INSERT_APP_STATE_REQUEST, false, errId, error)) {
queryFree(INSERT_APP_STATE_REQUEST_ID);
return sqlFail(INSERT_APP_STATE_REQUEST_ID, error);
}

ASSERT(queryCreate(SELECT_APP_STATE_REQUEST_ID));
if (!queryPrepare(SELECT_APP_STATE_REQUEST_ID, SELECT_APP_STATE_REQUEST, false, errId, error)) {
queryFree(SELECT_APP_STATE_REQUEST_ID);
return sqlFail(SELECT_APP_STATE_REQUEST_ID, error);
}

ASSERT(queryCreate(UPDATE_APP_STATE_REQUEST_ID));
if (!queryPrepare(UPDATE_APP_STATE_REQUEST_ID, UPDATE_APP_STATE_REQUEST, false, errId, error)) {
queryFree(UPDATE_APP_STATE_REQUEST_ID);
return sqlFail(UPDATE_APP_STATE_REQUEST_ID, error);
}
return true;
}

bool ParmsDb::insertDefaultAppState() {
const std::scoped_lock lock(_mutex);
int errId = 0;
std::string error;
bool found = false;

ASSERT(queryResetAndClearBindings(SELECT_APP_STATE_REQUEST_ID));
ASSERT(queryBindValue(SELECT_APP_STATE_REQUEST_ID, 1, static_cast<int>(AppStateKey::Test)));
if (!queryNext(SELECT_APP_STATE_REQUEST_ID, found)) {
LOG_WARN(_logger, "Error getting query result: " << SELECT_APP_STATE_REQUEST_ID);
return false;
}

ASSERT(queryResetAndClearBindings(SELECT_APP_STATE_REQUEST_ID));
if (!found) {
ASSERT(queryResetAndClearBindings(INSERT_APP_STATE_REQUEST_ID));
ASSERT(queryBindValue(INSERT_APP_STATE_REQUEST_ID, 1, static_cast<int>(AppStateKey::Test)));
ASSERT(queryBindValue(INSERT_APP_STATE_REQUEST_ID, 2, APP_STATE_KEY_DEFAULT_Test));
if (!queryExec(INSERT_APP_STATE_REQUEST_ID, errId, error)) {
LOG_WARN(_logger, "Error running query: " << INSERT_APP_STATE_REQUEST_ID);
return false;
}
}
return true;
}

bool ParmsDb::selectAppState(AppStateKey key, std::string &value, bool &found) {
const std::scoped_lock lock(_mutex);
found = false;

ASSERT(queryResetAndClearBindings(SELECT_APP_STATE_REQUEST_ID));
ASSERT(queryBindValue(SELECT_APP_STATE_REQUEST_ID, 1, static_cast<int>(key)));
if (!queryNext(SELECT_APP_STATE_REQUEST_ID, found)) {
LOG_WARN(_logger, "Error getting query result: " << SELECT_APP_STATE_REQUEST_ID);
return false;
}

if (!found) {
LOG_WARN(_logger, "AppStateKey not found: " << static_cast<int>(key));
return true;
}
ASSERT(queryStringValue(SELECT_APP_STATE_REQUEST_ID, 0, value));
ASSERT(queryResetAndClearBindings(SELECT_APP_STATE_REQUEST_ID));
return true;
}

bool ParmsDb::updateAppState(AppStateKey key, const std::string &value, bool &found) {
std::string existingValue;
int errId = 0;
std::string error;
if (!selectAppState(key, existingValue, found)) {
return false;
}

if (!found) {
return true;
}

const std::scoped_lock lock(_mutex);
if (found) {
ASSERT(queryResetAndClearBindings(UPDATE_APP_STATE_REQUEST_ID));
ASSERT(queryBindValue(UPDATE_APP_STATE_REQUEST_ID, 1, static_cast<int>(key)));
ASSERT(queryBindValue(UPDATE_APP_STATE_REQUEST_ID, 2, value));
if (!queryExec(UPDATE_APP_STATE_REQUEST_ID, errId, error)) {
LOG_WARN(_logger, "Error running query: " << UPDATE_APP_STATE_REQUEST_ID);
return false;
}
ASSERT(queryResetAndClearBindings(UPDATE_APP_STATE_REQUEST_ID));
}
return true;
}

} // namespace KDC
Loading

0 comments on commit 8f87979

Please sign in to comment.