From bb2df2a32ccb9e1cfbc11161ec7dfb2b044a7b0e Mon Sep 17 00:00:00 2001 From: Bartosz Date: Thu, 1 Dec 2022 12:37:57 +0100 Subject: [PATCH] [MOS-803] Fixes Fixes for deviceInfo endpoint, scripts and missing migration files in sysroot --- .../deviceInfo/DeviceInfoEndpointCommon.cpp | 18 +++--------------- .../deviceInfo/DeviceInfoEndpoint.cpp | 8 ++++---- .../deviceInfo/DeviceInfoEndpoint.cpp | 8 ++++---- scripts/lua/backup.lua | 2 +- scripts/lua/restore.lua | 2 +- tools/init_databases.py | 4 +++- 6 files changed, 16 insertions(+), 26 deletions(-) diff --git a/module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpointCommon.cpp b/module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpointCommon.cpp index 3c04ee8892172d8789da2b3021012a58d0bf6f60..c721e468aa66328391e3592696e2d62562ab813d 100644 --- a/module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpointCommon.cpp +++ b/module-services/service-desktop/endpoints/deviceInfo/DeviceInfoEndpointCommon.cpp @@ -3,19 +3,10 @@ #include #include -#include -#include -#include #include -#include -#include -#include #include -#include - -#include namespace sdesktop::endpoints { @@ -37,8 +28,7 @@ namespace sdesktop::endpoints auto DeviceInfoEndpointCommon::handleGet(Context &context) -> http::Code { const auto &requestBody = context.getBody(); - - if (requestBody[json::fileList].is_number()) { + if (not requestBody.object_items().empty() and requestBody[json::fileList].is_number()) { const auto diagFileType = parseDiagnosticFileType(requestBody[json::fileList]); @@ -47,12 +37,10 @@ namespace sdesktop::endpoints return http::Code::BadRequest; } - return gatherListOfDiagnostics(context, diagFileType); } - else { - return getDeviceInfo(context); - } + + return getDeviceInfo(context); } auto DeviceInfoEndpointCommon::parseDiagnosticFileType(const json11::Json &fileList) -> DiagnosticFileType diff --git a/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp b/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp index 822e8fcaa984c69edb7d444caa22891168de964d..1bf9a59048fdb7e9c2c9bf4fafbb17e3227ca335 100644 --- a/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp +++ b/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp @@ -42,10 +42,10 @@ namespace sdesktop::endpoints {json::currentRTCTime, std::to_string(static_cast(std::time(nullptr)))}, {json::version, std::string(VERSION)}, {json::serialNumber, getSerialNumber()}, - {json::recoveryStatusFilePath, purefs::dir::getTemporaryPath() / recoveryStatusFilename}, - {json::updateFilePath, purefs::dir::getTemporaryPath() / updateFilename}, - {json::backupFilePath, purefs::dir::getTemporaryPath() / backupFilename}, - {json::syncFilePath, purefs::dir::getTemporaryPath() / syncFilename}})); + {json::recoveryStatusFilePath, (purefs::dir::getTemporaryPath() / recoveryStatusFilename).string()}, + {json::updateFilePath, (purefs::dir::getTemporaryPath() / updateFilename).string()}, + {json::backupFilePath, (purefs::dir::getTemporaryPath() / backupFilename).string()}, + {json::syncFilePath, (purefs::dir::getTemporaryPath() / syncFilename).string()}})); return http::Code::OK; } diff --git a/products/PurePhone/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp b/products/PurePhone/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp index c3b3da5c8233b5d6577cb22f2e1dbdfa9937716d..a1cc6c7961afdbf347c43e430f6cd9eff23869c9 100644 --- a/products/PurePhone/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp +++ b/products/PurePhone/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp @@ -57,10 +57,10 @@ namespace sdesktop::endpoints {json::version, std::string(VERSION)}, {json::serialNumber, getSerialNumber()}, {json::caseColour, getCaseColour()}, - {json::recoveryStatusFilePath, purefs::dir::getTemporaryPath() / recoveryStatusFilename}, - {json::updateFilePath, purefs::dir::getTemporaryPath() / updateFilename}, - {json::backupFilePath, purefs::dir::getTemporaryPath() / backupFilename}, - {json::syncFilePath, purefs::dir::getTemporaryPath() / syncFilename}, + {json::recoveryStatusFilePath, (purefs::dir::getTemporaryPath() / recoveryStatusFilename).string()}, + {json::updateFilePath, (purefs::dir::getTemporaryPath() / updateFilename).string()}, + {json::backupFilePath, (purefs::dir::getTemporaryPath() / backupFilename).string()}, + {json::syncFilePath, (purefs::dir::getTemporaryPath() / syncFilename).string()}, {json::deviceToken, getDeviceToken()}})); return http::Code::OK; diff --git a/scripts/lua/backup.lua b/scripts/lua/backup.lua index 43adcb7ede443b6cbf74ff66221d3c858f06e5e2..1059f788b580c0d99aeb341dadcf4eb30964eeaa 100644 --- a/scripts/lua/backup.lua +++ b/scripts/lua/backup.lua @@ -16,7 +16,7 @@ backup.img_failure = "assets/gui_image_backup_failed.bin" local function check_available_space() local db_size = helpers.dir_size_filtered(paths.db_dir, match_db_files) local version_size = lfs.attributes(paths.version_file, 'size') - local available_space = recovery.sys.free_space(paths.user_dir) + local available_space = recovery.sys.free_space(recovery.sys.user()) -- Multiply the result by two due to the internal padding inside tar local required_space = (db_size + version_size) * 2 diff --git a/scripts/lua/restore.lua b/scripts/lua/restore.lua index 2088a904e5635d1377f7cc237ffbde306768c8c1..45f55fa285fb83c54c3520525d9eb4edcf89e009 100644 --- a/scripts/lua/restore.lua +++ b/scripts/lua/restore.lua @@ -18,7 +18,7 @@ restore.img_failure = "assets/gui_image_restore_failed.bin" local function check_available_space() local backup_size = lfs.attributes(paths.backup_file, 'size') - local available_space = recovery.sys.free_space(paths.user_dir) + local available_space = recovery.sys.free_space(recovery.sys.user()) print(string.format("Checking disk space:\nNeeded space: %d bytes, available space: %d bytes", backup_size, available_space)) diff --git a/tools/init_databases.py b/tools/init_databases.py index 099b64cac0bc30201b72247eef076ac188606026..f6e66a49290bacdea6cdd263319d0dfe5396e650 100755 --- a/tools/init_databases.py +++ b/tools/init_databases.py @@ -9,6 +9,7 @@ import argparse import logging import sys import json +import shutil log = logging.getLogger(__name__) logging.basicConfig(format='%(asctime)s [%(levelname)s]: %(message)s', level=logging.INFO) @@ -29,7 +30,7 @@ def migrate_database_up(database: str, migration_path: os.path, dst_directory: o try: connection = sqlite3.connect(dst_db_path) log.info(f"\nPerforming up-migration of {database} to {dst_version}") - for i in range(dst_version+1): + for i in range(dst_version + 1): migration_script = os.path.join(migration_path, *[database, str(i), "up.sql"]) devel_script = os.path.join(migration_path, *[database, str(i), "devel.sql"]) with open(migration_script) as ms: @@ -115,6 +116,7 @@ def main() -> int: for database_path in [args.common_path, args.product_path]: migration_path = os.path.join(database_path, migration_folder_name) ret |= migrate_database_wrapper(migration_path, json_data, args.output_path, args.development) + shutil.copytree(migration_path, os.path.join(args.output_path, migration_folder_name), dirs_exist_ok=True) return ret