From 5ce2f3d3295ac3ab973e0f79d0cdf41a67101ea6 Mon Sep 17 00:00:00 2001 From: Roman Kubiak <56821808+rkubiak01@users.noreply.github.com> Date: Tue, 17 Nov 2020 12:27:25 +0100 Subject: [PATCH] Revert "[EGD-4344] vfs-utils refactor (#1010)" (#1027) This reverts commit e6ca468d2c0a3d3f9a045c123ee901690e2b28a9. --- CMakeLists.txt | 1 + .../application-desktop/windows/Update.cpp | 8 +- .../windows/QuotesMainWindow.cpp | 2 +- .../application-settings/windows/Info.cpp | 4 +- module-bluetooth/Bluetooth/BtKeysStorage.cpp | 6 +- .../service-desktop/ServiceDesktop.cpp | 2 +- .../endpoints/update/UpdateMuditaOS.cpp | 22 +- module-utils/CMakeLists.txt | 2 +- module-utils/Utils.cpp | 182 ------------ module-utils/Utils.hpp | 19 -- module-utils/common_data/EventStore.cpp | 103 ------- module-utils/common_data/EventStore.hpp | 58 ---- module-vfs/CMakeLists.txt | 1 + .../cross/free_rtos_custom/portable/vfs.cpp | 18 +- .../linux/free_rtos_custom/portable/vfs.cpp | 15 +- module-vfs/include/user/deprecated/vfs.hpp | 55 +++- module-vfs/src/deprecated/vfs-utils.cpp | 277 ++++++++++++++++++ module-vfs/src/deprecated/vfs.cpp | 7 +- module-vfs/tests/unittest_vfs.cpp | 19 +- 19 files changed, 381 insertions(+), 420 deletions(-) delete mode 100644 module-utils/Utils.cpp create mode 100644 module-vfs/src/deprecated/vfs-utils.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index efa3643cc..b49407233 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,7 @@ target_link_libraries(${PROJECT_NAME} module-os module-utils module-vfs + module-utils module-sys module-cellular module-db diff --git a/module-apps/application-desktop/windows/Update.cpp b/module-apps/application-desktop/windows/Update.cpp index 45745f353..0509c7533 100644 --- a/module-apps/application-desktop/windows/Update.cpp +++ b/module-apps/application-desktop/windows/Update.cpp @@ -176,11 +176,11 @@ namespace gui updateVersion << utils::localize.get("app_desktop_update_to"); updateVersion << ": "; updateVersion << msg.updateStats - .versioInformation[BootConfigJson::os_version][BootConfigJson::version_string] + .versioInformation[purefs::json::os_version][purefs::json::version_string] .string_value(); updateVersion << " ("; updateVersion << msg.updateStats - .versioInformation[BootConfigJson::git_info][BootConfigJson::os_git_revision] + .versioInformation[purefs::json::git_info][purefs::json::os_git_revision] .string_value(); updateVersion << ")"; @@ -188,8 +188,8 @@ namespace gui updateFileDetails << ": "; updateFileDetails << std::to_string(msg.updateStats.totalBytes / 1024); updateFileDetails << "Kb ("; - updateFileDetails << msg.updateStats.versioInformation[BootConfigJson::misc][BootConfigJson::builddate] - .string_value(); + updateFileDetails + << msg.updateStats.versioInformation[purefs::json::misc][purefs::json::builddate].string_value(); updateFileDetails << ")"; currentVersionInfo->setText(currentVersion.str()); diff --git a/module-apps/application-settings-new/windows/QuotesMainWindow.cpp b/module-apps/application-settings-new/windows/QuotesMainWindow.cpp index 6d1f24ac5..febf23843 100644 --- a/module-apps/application-settings-new/windows/QuotesMainWindow.cpp +++ b/module-apps/application-settings-new/windows/QuotesMainWindow.cpp @@ -47,7 +47,7 @@ namespace gui { std::string err; - std::string fileContents = utils::filesystem::loadFileAsString(fn); + std::string fileContents = vfs.loadFileAsString(fn); auto obj = json11::Json::parse(fileContents, err).array_items(); diff --git a/module-apps/application-settings/windows/Info.cpp b/module-apps/application-settings/windows/Info.cpp index ea7dd763f..d51300e32 100644 --- a/module-apps/application-settings/windows/Info.cpp +++ b/module-apps/application-settings/windows/Info.cpp @@ -50,9 +50,9 @@ namespace gui addAlignedLabelWithValue(box, "Version:", std::string(VERSION)); addAlignedLabelWithValue(box, "Bootloader:", - (Store::BootConfig::get()->getBootloaderVersion().empty() + (vfs.getBootConfig().bootloader_verion.empty() ? utils::localize.get("not available") - : Store::BootConfig::get()->getBootloaderVersion())); + : vfs.getBootConfig().bootloader_verion)); std::string firmwareVersion; CellularServiceAPI::GetFirmwareVersion(getApplication(), firmwareVersion); diff --git a/module-bluetooth/Bluetooth/BtKeysStorage.cpp b/module-bluetooth/Bluetooth/BtKeysStorage.cpp index 84911f402..fc5d1c2b5 100644 --- a/module-bluetooth/Bluetooth/BtKeysStorage.cpp +++ b/module-bluetooth/Bluetooth/BtKeysStorage.cpp @@ -2,8 +2,6 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include - -#include "Utils.hpp" #include "BtKeysStorage.hpp" json11::Json Bt::KeyStorage::fileJson = json11::Json(); @@ -41,7 +39,7 @@ namespace Bt { LOG_INFO("opening storage from API"); fileContent.clear(); - fileContent = utils::filesystem::loadFileAsString(strings::keysFilename); + fileContent = vfs.loadFileAsString(strings::keysFilename); if (fileContent.empty()) { LOG_WARN("opening empty key file!"); return; @@ -133,7 +131,7 @@ namespace Bt { json11::Json finalJson = json11::Json::object{{strings::keys, keys}}; fileContent = finalJson.dump(); - utils::filesystem::replaceWithString(strings::keysFilename, fileContent); + vfs.replaceWithString(strings::keysFilename, fileContent); } } // namespace Bt diff --git a/module-services/service-desktop/ServiceDesktop.cpp b/module-services/service-desktop/ServiceDesktop.cpp index 07669c9e3..cba132996 100644 --- a/module-services/service-desktop/ServiceDesktop.cpp +++ b/module-services/service-desktop/ServiceDesktop.cpp @@ -104,7 +104,7 @@ sys::ReturnCodes ServiceDesktop::InitHandler() return std::make_shared(); }); - Store::BootConfig::get()->updateTimestamp(); + vfs.updateTimestamp(); return (sys::ReturnCodes::Success); } diff --git a/module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp b/module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp index e976757b2..614337cbb 100644 --- a/module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp +++ b/module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp @@ -202,7 +202,7 @@ updateos::UpdateError UpdateMuditaOS::verifyVersion() return updateos::UpdateError::VerifyVersionFailure; } - std::string versionJsonString = utils::filesystem::loadFileAsString(getUpdateTmpChild(updateos::file::version)); + std::string versionJsonString = vfs.loadFileAsString(getUpdateTmpChild(updateos::file::version)); std::string parserError; json11::Json updateVersionInformation = json11::Json::parse(versionJsonString, parserError); if (parserError != "") { @@ -313,24 +313,24 @@ updateos::UpdateError UpdateMuditaOS::updateBootJSON() fs::path bootJSONAbsoulte = purefs::createPath(purefs::dir::getRootDiskPath(), purefs::file::boot_json); informDebug("updateBootJSON %s", bootJSONAbsoulte.c_str()); - FILE *fp = fopen(bootJSONAbsoulte.c_str(), "r"); + vfs::FILE *fp = vfs.fopen(bootJSONAbsoulte.c_str(), "r"); if (fp != nullptr) { - utils::filesystem::computeCRC32(fp, &bootJSONAbsoulteCRC); + vfs.computeCRC32(fp, &bootJSONAbsoulteCRC); bootJSONAbsoulte += purefs::extension::crc32; - FILE *fpCRC = fopen(bootJSONAbsoulte.c_str(), "w"); + vfs::FILE *fpCRC = vfs.fopen(bootJSONAbsoulte.c_str(), "w"); if (fpCRC != nullptr) { std::array crcBuf; snprintf(crcBuf.data(), crcBuf.size(), "%lX", bootJSONAbsoulteCRC); - fwrite(crcBuf.data(), 1, purefs::buffer::crc_char_size, fpCRC); - fclose(fpCRC); + vfs.fwrite(crcBuf.data(), 1, purefs::buffer::crc_char_size, fpCRC); + vfs.fclose(fpCRC); } else { return updateos::UpdateError::CantUpdateCRC32JSON; } - fclose(fp); + vfs.fclose(fp); } else { return updateos::UpdateError::CantUpdateCRC32JSON; @@ -422,7 +422,7 @@ updateos::UpdateError UpdateMuditaOS::prepareTempDirForUpdate() { status = updateos::UpdateState::CreatingDirectories; - updateTempDirectory = purefs::dir::getTemporaryPath() / utils::filesystem::generateRandomId(updateos::prefix_len); + updateTempDirectory = purefs::dir::getTemporaryPath() / vfs::generateRandomId(updateos::prefix_len); informDebug("Temp dir for update %s", updateTempDirectory.c_str()); @@ -592,10 +592,10 @@ const fs::path UpdateMuditaOS::checkForUpdate() if (versionInfo.is_null()) continue; - if (versionInfo[BootConfigJson::os_version][BootConfigJson::version_string].is_string()) { + if (versionInfo[purefs::json::os_version][purefs::json::version_string].is_string()) { if (UpdateMuditaOS::isUpgradeToCurrent( - versionInfo[BootConfigJson::os_version][BootConfigJson::version_string].string_value())) { - return purefs::dir::getUpdatesOSPath() / file.fileName; + versionInfo[purefs::json::os_version][purefs::json::version_string].string_value())) { + return updatesOSPath / file.fileName; } } } diff --git a/module-utils/CMakeLists.txt b/module-utils/CMakeLists.txt index 515512ede..d5a648b65 100644 --- a/module-utils/CMakeLists.txt +++ b/module-utils/CMakeLists.txt @@ -33,7 +33,7 @@ set (SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/NumberHolderMatcher.hpp ${CMAKE_CURRENT_SOURCE_DIR}/country.hpp ${CMAKE_CURRENT_SOURCE_DIR}/state/ServiceState.hpp - Utils.cpp) +) add_library(${PROJECT_NAME} STATIC ${SOURCES} ${BOARD_SOURCES}) diff --git a/module-utils/Utils.cpp b/module-utils/Utils.cpp deleted file mode 100644 index 694557234..000000000 --- a/module-utils/Utils.cpp +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include