From bb0ef540b77e28d913384ecff85fb3d0bd62cf02 Mon Sep 17 00:00:00 2001 From: Mateusz Piesta Date: Wed, 30 Nov 2022 13:41:42 +0100 Subject: [PATCH] [MOS-803] DeviceInfo endpoint update * Added some changes to the DeviceInfo endpoint * Updated relevant code accordingly * Removed unneeded paths definitions * Minor bug fixes --- .../endpoints/pure/device_info_endpoint.md | 12 ++-- image/user/boot.json | 4 +- module-services/service-desktop/Sync.cpp | 2 +- .../include/endpoints/JsonKeyNames.hpp | 60 ++++++++++--------- .../deviceInfo/DeviceInfoEndpointCommon.hpp | 6 ++ .../include/service-desktop/Constants.hpp | 2 +- module-vfs/paths/filesystem_paths.cpp | 22 +------ .../paths/include/purefs/filesystem_paths.hpp | 2 - .../deviceInfo/DeviceInfoEndpoint.cpp | 26 ++++---- products/PurePhone/CMakeLists.txt | 4 +- .../deviceInfo/DeviceInfoEndpoint.cpp | 7 ++- scripts/lua/migration/migration.lua | 4 +- scripts/lua/share/helpers.lua | 2 +- 13 files changed, 75 insertions(+), 78 deletions(-) diff --git a/doc/os_api/endpoints/pure/device_info_endpoint.md b/doc/os_api/endpoints/pure/device_info_endpoint.md index aff34f74a7949f84811e74b85b6d51043df3290c..c1d019d4a96799cc052e5e17f990c876e8e776ee 100644 --- a/doc/os_api/endpoints/pure/device_info_endpoint.md +++ b/doc/os_api/endpoints/pure/device_info_endpoint.md @@ -78,8 +78,10 @@ enum class Method "trayState":"1", "version": "0.73.1", "serialNumber": "12345678901234", - "backupLocation": "path/to/directory", - "syncPackageLocationLocation": "path/to/directory" + "recoveryStatusFilePath": "path/to/recovery_status", + "updateFilePath": "path/to/update_package", + "backupFilePath": "path/to/backup_package", + "syncFilePath": "path/to/sync_package", }, "endpoint":1, "status":200, @@ -112,8 +114,10 @@ enum class Method - *uuid* - unique payload id, same as in request message - *version* - os version string - *serialNumber* - device serial number (14 digits) - - *"backupLocation"* - path to the location of backup files on device file-system - - *"syncPackageLocation"* - path to the location of sync package on device filesystem + - *recoveryStatusFilePath* - location of the PureRecovery status file + - *updateFilePath* - location of the update package + - *backupFilePath* - location of the backup package + - *syncFilePath* - location of the sync package ``` struct Network diff --git a/image/user/boot.json b/image/user/boot.json index 09c949bcb807dcf000631e6b0c3ca1af21802cbc..6ec0e3c18f91edb037c2e5c3d379ef0d69a49a03 100644 --- a/image/user/boot.json +++ b/image/user/boot.json @@ -8,7 +8,7 @@ "prefix" : "/system_a" }, "b": { - "bootable": true, + "bootable": false, "successful": false, "boot_attempts_left": "10", "prefix" : "/system_b" @@ -19,6 +19,6 @@ "os": "os.bin", "recovery": "recovery.bin", "bin_dir": "bin", - "update_dir": "/user/update" + "update_dir": "/user/temp/update" } } diff --git a/module-services/service-desktop/Sync.cpp b/module-services/service-desktop/Sync.cpp index d884605fb5269d2da83ecb3a978e09564effbb12..2fc442c55a53086eeb0fc5466a9ea4d793009ba9 100644 --- a/module-services/service-desktop/Sync.cpp +++ b/module-services/service-desktop/Sync.cpp @@ -92,7 +92,7 @@ bool Sync::PackSyncFiles(const std::filesystem::path &path) } auto isTarFileOpen = false; - std::filesystem::path tarFilePath = (purefs::dir::getSyncPackagePath() / path.filename()); + std::filesystem::path tarFilePath = (purefs::dir::getTemporaryPath() / path.filename()); mtar_t tarFile; auto cleanup = gsl::finally([&isTarFileOpen, &tarFile]() { diff --git a/module-services/service-desktop/endpoints/include/endpoints/JsonKeyNames.hpp b/module-services/service-desktop/endpoints/include/endpoints/JsonKeyNames.hpp index 9e502a95adc7bc239c2c30bebb786a0dae47c967..3a4924076033739fb74fe8f2493c2b9667e045de 100644 --- a/module-services/service-desktop/endpoints/include/endpoints/JsonKeyNames.hpp +++ b/module-services/service-desktop/endpoints/include/endpoints/JsonKeyNames.hpp @@ -25,35 +25,37 @@ namespace sdesktop::endpoints::json inline constexpr auto networkOperatorName = "networkOperatorName"; inline constexpr auto accessTechnology = "accessTechnology"; - inline constexpr auto update = "update"; - inline constexpr auto updateInfo = "updateInfo"; - inline constexpr auto updateError = "updateError"; - inline constexpr auto errorCode = "errorCode"; - inline constexpr auto statusCode = "statusCode"; - inline constexpr auto updateHistory = "updateHistory"; - inline constexpr auto usbMscMode = "usbMscMode"; - inline constexpr auto versionString = "string"; - inline constexpr auto fileExists = "fileExists"; - inline constexpr auto boot = "boot"; - inline constexpr auto version = "version"; - inline constexpr auto taskId = "id"; - inline constexpr auto state = "state"; - inline constexpr auto success = "success"; - inline constexpr auto reboot = "reboot"; - inline constexpr auto rebootMode = "rebootMode"; - inline constexpr auto request = "request"; - inline constexpr auto restore = "restore"; - inline constexpr auto finished = "finished"; - inline constexpr auto pending = "pending"; - inline constexpr auto location = "location"; - inline constexpr auto reason = "reason"; - inline constexpr auto serialNumber = "serialNumber"; - inline constexpr auto caseColour = "caseColour"; - inline constexpr auto fileList = "fileList"; - inline constexpr auto files = "files"; - inline constexpr auto backupLocation = "backupLocation"; - inline constexpr auto syncPackageLocation = "syncPackageLocation"; - inline constexpr auto deviceToken = "deviceToken"; + inline constexpr auto update = "update"; + inline constexpr auto updateInfo = "updateInfo"; + inline constexpr auto updateError = "updateError"; + inline constexpr auto errorCode = "errorCode"; + inline constexpr auto statusCode = "statusCode"; + inline constexpr auto updateHistory = "updateHistory"; + inline constexpr auto usbMscMode = "usbMscMode"; + inline constexpr auto versionString = "string"; + inline constexpr auto fileExists = "fileExists"; + inline constexpr auto boot = "boot"; + inline constexpr auto version = "version"; + inline constexpr auto taskId = "id"; + inline constexpr auto state = "state"; + inline constexpr auto success = "success"; + inline constexpr auto reboot = "reboot"; + inline constexpr auto rebootMode = "rebootMode"; + inline constexpr auto request = "request"; + inline constexpr auto restore = "restore"; + inline constexpr auto finished = "finished"; + inline constexpr auto pending = "pending"; + inline constexpr auto location = "location"; + inline constexpr auto reason = "reason"; + inline constexpr auto serialNumber = "serialNumber"; + inline constexpr auto caseColour = "caseColour"; + inline constexpr auto fileList = "fileList"; + inline constexpr auto files = "files"; + inline constexpr auto recoveryStatusFilePath = "recoveryStatusFilePath"; + inline constexpr auto updateFilePath = "updateFilePath"; + inline constexpr auto backupFilePath = "backupFilePath"; + inline constexpr auto syncFilePath = "syncFilePath"; + inline constexpr auto deviceToken = "deviceToken"; namespace updateprocess { diff --git a/module-services/service-desktop/endpoints/include/endpoints/deviceInfo/DeviceInfoEndpointCommon.hpp b/module-services/service-desktop/endpoints/include/endpoints/deviceInfo/DeviceInfoEndpointCommon.hpp index 911eba723b84dc3708029a81f64c1a5fcd9241fb..bbfeb8cb34edf6c39e0ad5c577550443b7cbe089 100644 --- a/module-services/service-desktop/endpoints/include/endpoints/deviceInfo/DeviceInfoEndpointCommon.hpp +++ b/module-services/service-desktop/endpoints/include/endpoints/deviceInfo/DeviceInfoEndpointCommon.hpp @@ -40,6 +40,12 @@ namespace sdesktop::endpoints { return http::Code::BadRequest; }; + + protected: + static constexpr auto updateFilename = "update.tar"; + static constexpr auto syncFilename = "sync.tar"; + static constexpr auto backupFilename = "backup.tar"; + static constexpr auto recoveryStatusFilename = "recovery_status.json"; }; } // namespace sdesktop::endpoints diff --git a/module-services/service-desktop/include/service-desktop/Constants.hpp b/module-services/service-desktop/include/service-desktop/Constants.hpp index 60f2c5a1c99c9352d1b1fc8afdf7cf3c1d17a0c7..1e9849602aad3b6a6d3a949337f84a3e56255037 100644 --- a/module-services/service-desktop/include/service-desktop/Constants.hpp +++ b/module-services/service-desktop/include/service-desktop/Constants.hpp @@ -8,4 +8,4 @@ namespace service::name { inline constexpr auto service_desktop = "ServiceDesktop"; -}; +} diff --git a/module-vfs/paths/filesystem_paths.cpp b/module-vfs/paths/filesystem_paths.cpp index be1e555f83fdbf8d5412a7fe9bf3b5af3d4c70b2..7121182e85997bff4d4631ea65dd6a54b78b7a59 100644 --- a/module-vfs/paths/filesystem_paths.cpp +++ b/module-vfs/paths/filesystem_paths.cpp @@ -10,14 +10,11 @@ namespace constexpr inline auto PATH_USER = "/user"; constexpr inline auto PATH_CONF = "/mfgconf"; constexpr inline auto PATH_DB = "db"; - constexpr inline auto PATH_UPDATE = "update"; - constexpr inline auto PATH_SYNC = "sync"; constexpr inline auto PATH_LOGS = "log"; constexpr inline auto PATH_CRASH_DUMPS = "crash_dumps"; constexpr inline auto PATH_USER_MEDIA = "media"; // TODO this won't work with our current non-hierarchical MTP implementation - constexpr inline auto PATH_TMP = "tmp"; - constexpr inline auto PATH_BACKUP = "backup"; + constexpr inline auto PATH_TMP = "temp"; constexpr inline auto PATH_ASSETS = "assets"; constexpr inline auto PATH_DATA = "data"; } // namespace @@ -51,16 +48,6 @@ namespace purefs return getSystemDiskPath() / PATH_DB; } - std::filesystem::path getUpdateDirPath() noexcept - { - return getUserDiskPath() / PATH_UPDATE; - } - - std::filesystem::path getSyncPackagePath() noexcept - { - return getUserDiskPath() / PATH_SYNC; // TODO what's this? - } - std::filesystem::path getLogsPath() noexcept { return getSystemDiskPath() / PATH_LOGS; @@ -78,12 +65,7 @@ namespace purefs std::filesystem::path getTemporaryPath() noexcept { - return getSystemDiskPath() / PATH_TMP; // TODO is it needed + if it is, where it should be placed - } - - std::filesystem::path getBackupOSPath() noexcept - { - return getUserDiskPath() / PATH_BACKUP; // TODO is it still needed? + return getSystemDiskPath() / PATH_TMP; } std::filesystem::path getBootJSONPath() noexcept diff --git a/module-vfs/paths/include/purefs/filesystem_paths.hpp b/module-vfs/paths/include/purefs/filesystem_paths.hpp index bd6efbd3a8e47d0ed902286cb073e62472bb24d6..0fb6c306630fe30b03f0ecde0cf2e28b80c532ec 100644 --- a/module-vfs/paths/include/purefs/filesystem_paths.hpp +++ b/module-vfs/paths/include/purefs/filesystem_paths.hpp @@ -15,13 +15,11 @@ namespace purefs std::filesystem::path getUserDiskPath() noexcept; std::filesystem::path getMfgConfPath() noexcept; std::filesystem::path getDatabasesPath() noexcept; - std::filesystem::path getUpdateDirPath() noexcept; std::filesystem::path getSyncPackagePath() noexcept; std::filesystem::path getLogsPath() noexcept; std::filesystem::path getCrashDumpsPath() noexcept; std::filesystem::path getUserMediaPath() noexcept; std::filesystem::path getTemporaryPath() noexcept; - std::filesystem::path getBackupOSPath() noexcept; std::filesystem::path getBootJSONPath() noexcept; std::filesystem::path getAssetsDirPath() noexcept; std::filesystem::path getSystemDataDirPath() noexcept; diff --git a/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp b/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp index 8e9c1a41f175d08abd3fa5e0e585659bbaafe222..822e8fcaa984c69edb7d444caa22891168de964d 100644 --- a/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp +++ b/products/BellHybrid/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp @@ -31,17 +31,21 @@ namespace sdesktop::endpoints { auto [totalDeviceSpaceMiB, reservedSystemSpaceMiB, usedUserSpaceMiB] = getStorageInfo(); - context.setResponseBody( - json11::Json::object({{json::batteryLevel, std::to_string(Store::Battery::get().level)}, - {json::batteryState, std::to_string(static_cast(Store::Battery::get().state))}, - {json::deviceSpaceTotal, std::to_string(totalDeviceSpaceMiB)}, - {json::systemReservedSpace, std::to_string(reservedSystemSpaceMiB)}, - {json::usedUserSpace, std::to_string(usedUserSpaceMiB)}, - {json::gitRevision, (std::string)(GIT_REV)}, - {json::gitBranch, (std::string)GIT_BRANCH}, - {json::currentRTCTime, std::to_string(static_cast(std::time(nullptr)))}, - {json::version, std::string(VERSION)}, - {json::serialNumber, getSerialNumber()}})); + context.setResponseBody(json11::Json::object( + {{json::batteryLevel, std::to_string(Store::Battery::get().level)}, + {json::batteryState, std::to_string(static_cast(Store::Battery::get().state))}, + {json::deviceSpaceTotal, std::to_string(totalDeviceSpaceMiB)}, + {json::systemReservedSpace, std::to_string(reservedSystemSpaceMiB)}, + {json::usedUserSpace, std::to_string(usedUserSpaceMiB)}, + {json::gitRevision, (std::string)(GIT_REV)}, + {json::gitBranch, (std::string)GIT_BRANCH}, + {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}})); return http::Code::OK; } diff --git a/products/PurePhone/CMakeLists.txt b/products/PurePhone/CMakeLists.txt index 28276ea1566516a0ac60efe3a0765d6c4dc74dd0..d8ca4766a01f09684b50aca2fb4dfa0848a184f3 100644 --- a/products/PurePhone/CMakeLists.txt +++ b/products/PurePhone/CMakeLists.txt @@ -108,9 +108,9 @@ include(AddVersionJson) add_directories( TARGET create_user_directories - PREFIX ${SYSROOT_PATH}/user/media/app + PREFIX ${SYSROOT_PATH}/user DEPENDS system_directories_common - DIRECTORIES music_player + DIRECTORIES data temp media/app/music_player ) if (${PROJECT_TARGET} STREQUAL "TARGET_RT1051") diff --git a/products/PurePhone/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp b/products/PurePhone/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp index 02cefd8a4707f8772fadbde27a36543d4748cf19..c3b3da5c8233b5d6577cb22f2e1dbdfa9937716d 100644 --- a/products/PurePhone/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp +++ b/products/PurePhone/services/desktop/endpoints/deviceInfo/DeviceInfoEndpoint.cpp @@ -19,7 +19,6 @@ namespace sdesktop::endpoints { - auto DeviceInfoEndpoint::getSerialNumber() -> std::string { return dynamic_cast(ownerServicePtr)->getSerialNumber(); @@ -58,8 +57,10 @@ namespace sdesktop::endpoints {json::version, std::string(VERSION)}, {json::serialNumber, getSerialNumber()}, {json::caseColour, getCaseColour()}, - {json::backupLocation, purefs::dir::getBackupOSPath().string()}, - {json::syncPackageLocation, purefs::dir::getSyncPackagePath().string()}, + {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::deviceToken, getDeviceToken()}})); return http::Code::OK; diff --git a/scripts/lua/migration/migration.lua b/scripts/lua/migration/migration.lua index 629c0e7d327aca7006200d81431a4d4e6cea6eca..0dbe02f233efe89ea66e7e5590ecca23c4670078 100644 --- a/scripts/lua/migration/migration.lua +++ b/scripts/lua/migration/migration.lua @@ -56,7 +56,7 @@ local function read_db_version(file) end local function db_migrate_up(db_path, scripts, target_version) - current_version = read_db_version(db_path) + local current_version = read_db_version(db_path) if current_version == target_version then return migration.retcode.ALREADY_UP_TO_DATE @@ -73,7 +73,7 @@ local function db_migrate_up(db_path, scripts, target_version) end local function db_migrate_down(db_path, scripts, target_version) - current_version = read_db_version(db_path) + local current_version = read_db_version(db_path) if current_version == target_version then return migration.retcode.ALREADY_UP_TO_DATE diff --git a/scripts/lua/share/helpers.lua b/scripts/lua/share/helpers.lua index ded871cde23de8f52bbf663c5ee0be615dfd1d3e..44fe1500f1546118c94769b5864387f3c9589084 100644 --- a/scripts/lua/share/helpers.lua +++ b/scripts/lua/share/helpers.lua @@ -79,7 +79,7 @@ function helpers.copy_file(filename_in, filename_out) fd_out:close() end ---- Remove directory and its content +--- Remove directory and its contents -- @function rmdir -- @param dir directory to remove function helpers.rmdir(dir)