~aleteoryx/muditaos

e05ddbfdd9b9663f64a7dcf0b9fcc6d6aa8bffe3 — tomaszkrosnowski 4 years ago 9fafa13
[EGD-7010] Remove sensitive data from logs

Sensivite data like first/second name, messages and notes content,
dialed gsm numbers etc are removed from logs to guarantee security for
Pure users.
24 files changed, 112 insertions(+), 129 deletions(-)

M module-apps/application-settings/windows/BtScanWindow.cpp
M module-apps/application-settings/windows/Fota.cpp
M module-services/service-desktop/WorkerDesktop.cpp
M module-services/service-desktop/endpoints/backup/BackupRestore.cpp
M module-services/service-desktop/endpoints/bluetooth/BluetoothHelper.cpp
M module-services/service-desktop/endpoints/contacts/ContactHelper.cpp
M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp
M module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp
M module-services/service-desktop/endpoints/filesystem/FileContext.cpp
M module-services/service-desktop/endpoints/filesystem/FileOperations.cpp
M module-services/service-desktop/endpoints/filesystem/FilesystemEndpoint.cpp
M module-services/service-desktop/endpoints/messages/MessageHelper.cpp
M module-services/service-desktop/endpoints/security/SecurityEndpointHelper.cpp
M module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp
M module-services/service-fileindexer/ServiceFileIndexer.cpp
M module-services/service-fileindexer/StartupIndexer.cpp
M module-services/service-fileindexer/notesIndexer.cpp
M module-services/service-fota/FotaServiceAPI.cpp
M module-services/service-lwip/ServiceLwIP.cpp
M module-vfs/drivers/src/thirdparty/littlefs/lfs_glue.cpp
M module-vfs/src/purefs/blkdev/disk_manager.cpp
M module-vfs/src/purefs/fs/filesystem.cpp
M module-vfs/src/purefs/fs/filesystem_syscalls.cpp
M module-vfs/src/purefs/vfs_subsystem.cpp
M module-apps/application-settings/windows/BtScanWindow.cpp => module-apps/application-settings/windows/BtScanWindow.cpp +1 -1
@@ 70,7 70,7 @@ namespace gui

        for (auto device : devices) {
            add_box_label2(box, device.name, [=](Item &) {
                LOG_DEBUG("Device: %s", device.name.c_str());
                LOG_DEBUG("Device added to list");

                std::shared_ptr<BluetoothAddrMessage> msg =
                    std::make_shared<BluetoothAddrMessage>(bd_addr_to_str(device.address));

M module-apps/application-settings/windows/Fota.cpp => module-apps/application-settings/windows/Fota.cpp +2 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "Fota.hpp"


@@ 247,7 247,7 @@ void Fota::handleHTTPResponse()
    app->connect(FotaService::HTTPResponseMessage(), [&](sys::Message *req) {
        if (auto msg = dynamic_cast<FotaService::HTTPResponseMessage *>(req)) {
            LOG_DEBUG("HTTP Response to: %s", msg->url.c_str());
            LOG_DEBUG("HTPP AT Error   : %s", FotaService::toString(msg->httpError).c_str());
            LOG_DEBUG("HTTP AT Error   : %s", FotaService::toString(msg->httpError).c_str());
            LOG_DEBUG(
                "response headers:\n\t%s",
                std::accumulate(msg->responseHeaders.begin(), msg->responseHeaders.end(), std::string("\n\t")).c_str());

M module-services/service-desktop/WorkerDesktop.cpp => module-services/service-desktop/WorkerDesktop.cpp +5 -7
@@ 224,10 224,8 @@ void WorkerDesktop::stopTransfer(const TransferFailAction action)
        responseStatus = parserFSM::http::Code::NotAcceptable;
        removeFile     = true;

        LOG_ERROR("File %s transfer CRC32 mismatch, expected: %s, actual: %s",
                  filePath.c_str(),
                  expectedFileCrc32.c_str(),
                  fileCrc32.c_str());
        LOG_ERROR(
            "File transfer CRC32 mismatch, expected: %s, actual: %s", expectedFileCrc32.c_str(), fileCrc32.c_str());
    }

    parserFSM::Context responseContext;


@@ 251,12 249,12 @@ void WorkerDesktop::stopTransfer(const TransferFailAction action)
    if (removeFile) {
        try {
            if (!std::filesystem::remove(filePath)) {
                LOG_ERROR("stopTransfer can't delete  %s", filePath.c_str());
                LOG_ERROR("can't delete file");
            }
            LOG_DEBUG("Deleted file(requested) %s", filePath.c_str());
            LOG_DEBUG("Deleted file");
        }
        catch (const std::filesystem::filesystem_error &fsError) {
            LOG_ERROR("remove on %s, error %s", filePath.c_str(), fsError.what());
            LOG_ERROR("Removing file failed");
        }
    }


M module-services/service-desktop/endpoints/backup/BackupRestore.cpp => module-services/service-desktop/endpoints/backup/BackupRestore.cpp +43 -54
@@ 44,12 44,12 @@ static bool copyFile(const std::filesystem::path &from, const std::filesystem::p
    });

    if (fromFp == nullptr) {
        LOG_ERROR("can't open %s for reading", from.c_str());
        LOG_ERROR("can't open file for reading");
        return false;
    }

    if (toFp == nullptr) {
        LOG_ERROR("can't open %s for writing", to.c_str());
        LOG_ERROR("can't open file for writing");
        return false;
    }



@@ 98,7 98,7 @@ bool BackupRestore::BackupUserFiles(sys::Service *ownerService, std::filesystem:

bool BackupRestore::WriteBackupInfo(sys::Service *ownerService, const std::filesystem::path &path)
{
    LOG_INFO("Writing backup info to %s", path.c_str());
    LOG_INFO("Writing backup info");

    if (std::filesystem::is_directory(path)) {
        try {


@@ 130,7 130,7 @@ bool BackupRestore::WriteBackupInfo(sys::Service *ownerService, const std::files
bool BackupRestore::RestoreUserFiles(sys::Service *ownerService, const std::filesystem::path &path)
{
    assert(ownerService != nullptr);
    LOG_INFO("RestoreUserFiles: restore started from %s", path.c_str());
    LOG_INFO("RestoreUserFiles: restore started");

    if (BackupRestore::UnpackBackupFile(path) == false) {
        return false;


@@ 197,9 197,7 @@ bool BackupRestore::CreateBackupDir(std::filesystem::path &path)

    if (!std::filesystem::is_directory(path)) {
        if (!std::filesystem::create_directory(path, errorCode)) {
            LOG_ERROR("CreateBackupDir: creating backup directory %s failed. \"%s\"",
                      path.c_str(),
                      errorCode.message().c_str());
            LOG_ERROR("CreateBackupDir: creating backup directory failed.");
            return false;
        }
    }


@@ 210,7 208,7 @@ bool BackupRestore::CreateBackupDir(std::filesystem::path &path)
bool BackupRestore::PackUserFiles(std::filesystem::path &path)
{
    if (std::filesystem::is_empty(path)) {
        LOG_ERROR("backup dir %s is empty, nothing to backup, quitting...", path.c_str());
        LOG_ERROR("backup dir is empty, nothing to backup, quitting...");
        BackupRestore::RemoveBackupDir(path);
        return false;
    }


@@ 219,12 217,12 @@ bool BackupRestore::PackUserFiles(std::filesystem::path &path)
        (purefs::dir::getBackupOSPath() / path.filename()).replace_extension(purefs::extension::tar);
    mtar_t tarFile;

    LOG_INFO("opening file %s...", tarFilePath.c_str());
    LOG_INFO("opening tar file...");

    int ret = mtar_open(&tarFile, tarFilePath.c_str(), "w");

    if (ret != MTAR_ESUCCESS) {
        LOG_ERROR("opening file %s failed, error: %s, quitting...", tarFilePath.c_str(), mtar_strerror(ret));
        LOG_ERROR("opening tar file failed, quitting...");
        BackupRestore::RemoveBackupDir(path);
        return false;
    }


@@ 237,22 235,22 @@ bool BackupRestore::PackUserFiles(std::filesystem::path &path)
            continue;
        }

        LOG_INFO("archiving file %s...", direntry.path().c_str());
        LOG_INFO("archiving file ...");
        auto *file = std::fopen(direntry.path().string().c_str(), "r");

        if (file == nullptr) {
            LOG_ERROR("archiving file %s failed, cannot open file, quitting...", direntry.path().c_str());
            LOG_ERROR("archiving file failed, cannot open file, quitting...");
            mtar_close(&tarFile);
            BackupRestore::RemoveBackupDir(path);
            return false;
        }

        LOG_DEBUG("writting tar header for %s...", direntry.path().c_str());
        LOG_DEBUG("writting tar header ...");

        if (mtar_write_file_header(&tarFile,
                                   direntry.path().filename().c_str(),
                                   static_cast<unsigned>(std::filesystem::file_size(direntry))) != MTAR_ESUCCESS) {
            LOG_ERROR("writing tar header for %s failed", direntry.path().filename().c_str());
            LOG_ERROR("writing tar header failed");
            std::fclose(file);
            mtar_close(&tarFile);
            BackupRestore::RemoveBackupDir(path);


@@ 261,7 259,7 @@ bool BackupRestore::PackUserFiles(std::filesystem::path &path)

        uintmax_t filesize = std::filesystem::file_size(direntry.path(), e);
        if (e) {
            LOG_ERROR("failed to get size for file: %s \"%s\"", path.c_str(), e.message().c_str());
            LOG_ERROR("failed to get size for file");
            BackupRestore::RemoveBackupDir(path);
            return false;
        }


@@ 276,19 274,19 @@ bool BackupRestore::PackUserFiles(std::filesystem::path &path)
                readsize = purefs::buffer::tar_buf;
            }

            LOG_DEBUG("reading file %s...", direntry.path().c_str());
            LOG_DEBUG("reading file ...");

            if (std::fread(buffer.get(), 1, readsize, file) != readsize) {
                LOG_ERROR("reading file %s failed, quitting...", direntry.path().c_str());
                LOG_ERROR("reading file failed, quitting...");
                std::fclose(file);
                mtar_close(&tarFile);
                BackupRestore::RemoveBackupDir(path);
                return false;
            }

            LOG_DEBUG("writting %s into backup...", direntry.path().c_str());
            LOG_DEBUG("writting into backup...");
            if (mtar_write_data(&tarFile, buffer.get(), readsize) != MTAR_ESUCCESS) {
                LOG_ERROR("PackUserFiles: writting %s into backup failed, quitting...", direntry.path().c_str());
                LOG_ERROR("PackUserFiles: writting into backup failed, quitting...");
                std::fclose(file);
                mtar_close(&tarFile);
                BackupRestore::RemoveBackupDir(path);


@@ 296,35 294,35 @@ bool BackupRestore::PackUserFiles(std::filesystem::path &path)
            }
        }

        LOG_INFO("closing file %s...", direntry.path().c_str());
        LOG_INFO("closing file...");
        if (std::fclose(file) != 0) {
            LOG_ERROR("PackUserFiles: closing file %s failed, quitting...", direntry.path().c_str());
            LOG_ERROR("PackUserFiles: closing file failed, quitting...");
            mtar_close(&tarFile);
            BackupRestore::RemoveBackupDir(path);
            return false;
        }

        LOG_INFO("deleting file %s...", direntry.path().c_str());
        LOG_INFO("deleting file ...");

        if (std::remove(direntry.path().c_str()) != 0) {
            LOG_ERROR("PackUserFiles: deleting file %s failed, quitting...", direntry.path().c_str());
            LOG_ERROR("PackUserFiles: deleting file failed, quitting...");
            mtar_close(&tarFile);
            BackupRestore::RemoveBackupDir(path);
            return false;
        }
    }

    LOG_INFO("finalizing file %s...", tarFilePath.c_str());
    LOG_INFO("finalizing tar file...");
    if (mtar_finalize(&tarFile) != MTAR_ESUCCESS) {
        LOG_ERROR("PackUserFiles: finalizing file %s failed, quitting....", tarFilePath.c_str());
        LOG_ERROR("PackUserFiles: finalizing tar file failed, quitting....");
        mtar_close(&tarFile);
        BackupRestore::RemoveBackupDir(path);
        return false;
    }

    LOG_INFO("closing file %s...", tarFilePath.c_str());
    LOG_INFO("closing tar file...");
    if (mtar_close(&tarFile) != MTAR_ESUCCESS) {
        LOG_ERROR("PackUserFiles: closing file %s failed, quitting...", tarFilePath.c_str());
        LOG_ERROR("PackUserFiles: closing tar file failed, quitting...");
        BackupRestore::RemoveBackupDir(path);
        return false;
    }


@@ 340,21 338,21 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)

    auto extractDestination = purefs::dir::getTemporaryPath() / tarFilePath.stem();

    LOG_INFO("creating temporary directory %s", extractDestination.c_str());
    LOG_INFO("creating temporary directory");
    if (!std::filesystem::is_directory(extractDestination, e)) {
        std::filesystem::create_directory(extractDestination, e);
        if (e) {
            LOG_ERROR("Can't create temporary directory %s \"%s\"", extractDestination.c_str(), e.message().c_str());
            LOG_ERROR("Can't create temporary directory");
            return false;
        }
    }

    LOG_INFO("opening file %s...", tarFilePath.c_str());
    LOG_INFO("opening tar file ...");

    int ret = mtar_open(&tarFile, tarFilePath.c_str(), "r");

    if (ret != MTAR_ESUCCESS) {
        LOG_ERROR("opening file %s failed, error: %s, quitting...", tarFilePath.c_str(), mtar_strerror(ret));
        LOG_ERROR("opening tar file failed, quitting...");
        return false;
    }



@@ 362,16 360,16 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)

    do {
        ret = mtar_read_header(&tarFile, &tarHeader);
        LOG_DEBUG("reading tar header name %s...", tarHeader.name);
        LOG_DEBUG("reading tar header name...");

        if ((tarHeader.type == MTAR_TREG) && (ret == MTAR_ESUCCESS)) {
            LOG_DEBUG("extracting file %s...", tarHeader.name);
            LOG_DEBUG("extracting tar file ...");

            std::filesystem::path extractedFile = extractDestination / tarHeader.name;
            auto *file                          = std::fopen(extractedFile.c_str(), "w");

            if (file == nullptr) {
                LOG_ERROR("can't open %s for writing", extractedFile.c_str());
                LOG_ERROR("can't open file for writing");
                mtar_close(&tarFile);
                return false;
            }


@@ 389,7 387,7 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)
                }

                if (mtar_read_data(&tarFile, buffer.get(), readsize) != MTAR_ESUCCESS) {
                    LOG_ERROR("extracting file %s failed, quitting...", extractedFile.c_str());
                    LOG_ERROR("extracting file failed, quitting...");
                    mtar_close(&tarFile);
                    std::fclose(file);
                    std::remove(extractedFile.c_str());


@@ 397,7 395,7 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)
                }

                if (std::fwrite(buffer.get(), 1, readsize, file) != readsize) {
                    LOG_ERROR("writting file %s failed, quitting...", extractedFile.c_str());
                    LOG_ERROR("writting file failed, quitting...");
                    mtar_close(&tarFile);
                    std::fclose(file);
                    std::remove(extractedFile.c_str());


@@ 405,7 403,7 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)
                }
            }

            LOG_INFO("extracting file %s succeeded", extractedFile.c_str());
            LOG_INFO("extracting file succeeded");
            std::fclose(file);
        }
        else {


@@ 416,12 414,12 @@ bool BackupRestore::UnpackBackupFile(const std::filesystem::path &tarFilePath)
        LOG_DEBUG("reading tar next status %s", mtar_strerror(ret));
    } while (ret == MTAR_ESUCCESS);

    LOG_DEBUG("cleanup %s", tarFilePath.c_str());
    LOG_DEBUG("cleanup");
    mtar_close(&tarFile);
    std::remove(tarFilePath.c_str());

    if (e) {
        LOG_WARN("can't cleanup temporary dir %s \"%s\"", extractDestination.c_str(), e.message().c_str());
        LOG_WARN("can't cleanup temporary dir");
    }

    return true;


@@ 443,7 441,7 @@ bool BackupRestore::ReplaceUserFiles(const std::filesystem::path &path)

    for (auto &direntry : std::filesystem::directory_iterator(tempDir, e)) {
        if (e) {
            LOG_INFO("Can't list contents of %s \"%s\"", tempDir.c_str(), e.message().c_str());
            LOG_INFO("Can't list contents of temp dir");
            return false;
        }



@@ 456,25 454,17 @@ bool BackupRestore::ReplaceUserFiles(const std::filesystem::path &path)
            continue;
        }

        LOG_INFO("restoring backup file %s...", direntry.path().c_str());
        LOG_INFO("restoring backup file ...");

        if (std::filesystem::remove(userDir / direntry.path().filename(), e)) {
            std::filesystem::rename(tempDir / direntry.path().filename(), userDir / direntry.path().filename(), e);
            if (e) {
                LOG_ERROR("can't rename %s->%s restore failed \"%s\"",
                          (tempDir / direntry.path().filename()).c_str(),
                          (userDir / direntry.path().filename()).c_str(),
                          e.message().c_str());
                LOG_ERROR("can't rename file. Restore failed");
                return false;
            }
            else {
                LOG_INFO("restored %s->%s",
                         (tempDir / direntry.path().filename()).c_str(),
                         (userDir / direntry.path().filename()).c_str());
            }
        }
        else {
            LOG_WARN("can't remove %s \"%s\"", (userDir / direntry.path().filename()).c_str(), e.message().c_str());
            LOG_WARN("can't remove file");
            // we should continue, there can be new files in the backup
        }
    }


@@ 488,12 478,11 @@ json11::Json BackupRestore::GetBackupFiles()
    std::error_code e;
    for (const auto &p : std::filesystem::directory_iterator(purefs::dir::getBackupOSPath(), e)) {
        if (e) {
            LOG_ERROR(
                "Can't get directory %s contents \"%s\"", purefs::dir::getBackupOSPath().c_str(), e.message().c_str());
            LOG_ERROR("Can't get directory %s contents", purefs::dir::getBackupOSPath().c_str());
            return json11::Json();
        }
        if (!p.is_directory() && p.path().extension() == purefs::extension::tar) {
            LOG_DEBUG("possible restore file %s", p.path().filename().c_str());
            LOG_DEBUG("possible restore file");
            dirEntryVector.push_back(p.path().filename());
        }
    }

M module-services/service-desktop/endpoints/bluetooth/BluetoothHelper.cpp => module-services/service-desktop/endpoints/bluetooth/BluetoothHelper.cpp +2 -2
@@ 82,7 82,7 @@ auto parserFSM::BluetoothHelper::processPostRequest(Context &context) -> sys::Re
        msg = std::make_unique<::message::bluetooth::Connect>(std::move(address));
    }
    else if (auto address = body[json::bluetooth::pair].string_value(); !address.empty()) {
        LOG_INFO("Requesting pairing with %s form harness", address.c_str());
        LOG_INFO("Requesting pairing form harness");
        msg = std::make_unique<BluetoothPairMessage>(std::move(address));
    }



@@ 101,7 101,7 @@ auto parserFSM::BluetoothHelper::processDeleteRequest(Context &context) -> sys::
        }
    }
    else if (auto address = body[json::bluetooth::unpair].string_value(); !address.empty()) {
        LOG_INFO("Requesting pairing with %s form harness", address.c_str());
        LOG_INFO("Requesting pairing form harness");
        msg = std::make_unique<::message::bluetooth::Unpair>(std::move(address));
    }
    sendRequest(context, std::move(msg));

M module-services/service-desktop/endpoints/contacts/ContactHelper.cpp => module-services/service-desktop/endpoints/contacts/ContactHelper.cpp +1 -1
@@ 109,7 109,7 @@ auto ContactHelper::requestDataFromDB(Context &context) -> sys::ReturnCodes
        DBServiceAPI::GetQuery(ownerServicePtr, db::Interface::Name::Contact, std::move(query));
    }
    catch (const std::exception &e) {
        LOG_ERROR("%s", e.what());
        LOG_ERROR("exception while requesting data from DB");
        return sys::ReturnCodes::Failure;
    }


M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp +1 -2
@@ 59,7 59,7 @@ auto DeveloperModeHelper::processPut(Context &context) -> ProcessResult
        using namespace sdesktop::developerMode;
        auto cmd     = body[json::developerMode::AT].string_value();
        auto timeout = std::chrono::milliseconds(body[json::developerMode::timeout].int_value());
        LOG_DEBUG("at request send >%s\n< with timeout >%d<", cmd.c_str(), int(timeout.count()));
        LOG_DEBUG("at request sent with timeout >%d<", int(timeout.count()));
        auto event = std::make_unique<ATResponseEvent>(cmd, timeout);
        auto msg   = std::make_shared<DeveloperModeRequest>(std::move(event));
        code       = toCode(owner->bus.sendUnicast(msg, ServiceCellular::serviceName));


@@ 252,7 252,6 @@ bool DeveloperModeHelper::sendKeypress(bsp::KeyCodes keyCode, gui::InputEvent::S
    RawKey key{.state = RawKey::State::Released, .key_code = keyCode};

    gui::InputEvent event(key, state, static_cast<gui::KeyCode>(keyCode));
    LOG_INFO("Sending %s", event.str().c_str());
    auto message = std::make_shared<app::AppInputEventMessage>(event);

    return owner->bus.sendUnicast(std::move(message), service::name::evt_manager);

M module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp => module-services/service-desktop/endpoints/factoryReset/FactoryReset.cpp +13 -14
@@ 98,20 98,20 @@ namespace FactoryReset

            if (std::filesystem::is_directory(direntry)) {
                if (direntry.path().string() != purefs::dir::getFactoryOSPath()) {
                    LOG_INFO("FactoryReset: recursively deleting dir %s...", delpath.c_str());
                    LOG_INFO("FactoryReset: recursively deleting dir...");
                    try {
                        std::filesystem::remove_all(delpath.c_str());
                    }
                    catch (const std::filesystem::filesystem_error &e) {
                        LOG_ERROR("FactoryReset: error deleting dir %s, aborting...", delpath.c_str());
                        LOG_ERROR("FactoryReset: error deleting dir, aborting...");
                        return false;
                    }
                }
            }
            else {
                LOG_INFO("FactoryReset: deleting file %s...", delpath.c_str());
                LOG_INFO("FactoryReset: deleting file...");
                if (std::filesystem::remove(delpath.c_str())) {
                    LOG_ERROR("FactoryReset: error deleting file %s, aborting...", delpath.c_str());
                    LOG_ERROR("FactoryReset: error deleting file, aborting...");
                    return false;
                }
            }


@@ 123,9 123,8 @@ namespace FactoryReset
    bool CopyDirContent(const std::string &sourcedir, const std::string &targetdir)
    {
        if (recurseDepth >= max_recurse_depth) {
            LOG_ERROR("FactoryReset: recurse level %d (too high), error assumed, skipping restore of dir %s",
                      recurseDepth,
                      sourcedir.c_str());
            LOG_ERROR("FactoryReset: recurse level %d (too high), error assumed, skipping restore of dir",
                      recurseDepth);
            return false;
        }



@@ 148,7 147,7 @@ namespace FactoryReset
            if ((sourcepath.size() >= max_filepath_length) || (targetpath.size() >= max_filepath_length)) {
                LOG_ERROR("FactoryReset: path length (source or target) exceeds system limit of %d",
                          max_filepath_length);
                LOG_ERROR("FactoryReset: skipping restore of dir %s into %s", sourcepath.c_str(), targetpath.c_str());
                LOG_ERROR("FactoryReset: skipping restore of directory");
                return false;
            }



@@ 157,16 156,16 @@ namespace FactoryReset
                    continue;
                }

                LOG_INFO("FactoryReset: restoring dir  %s into %s...", sourcepath.c_str(), targetpath.c_str());
                LOG_INFO("FactoryReset: restoring directory");

                try {
                    if (std::filesystem::create_directory(targetpath.c_str())) {
                        LOG_ERROR("FactoryReset: create dir %s failed", targetpath.c_str());
                        LOG_ERROR("FactoryReset: create dir failed");
                        return false;
                    }
                }
                catch (const std::filesystem::filesystem_error &err) {
                    LOG_FATAL("Exception while creating dir %s", targetpath.c_str());
                    LOG_FATAL("Exception while creating dir");
                    return false;
                }



@@ 180,7 179,7 @@ namespace FactoryReset
                recurseDepth--;
            }
            else {
                LOG_INFO("FactoryReset: restoring file %s into %s...", sourcepath.c_str(), targetpath.c_str());
                LOG_INFO("FactoryReset: restoring file");

                if (!CopyFile(sourcepath, targetpath)) {
                    return false;


@@ 212,13 211,13 @@ namespace FactoryReset
                    }

                    if (std::fread(buffer.get(), 1, readsize, sf.get()) != readsize) {
                        LOG_ERROR("FactoryReset: read from sourcefile %s failed", sourcefile.c_str());
                        LOG_ERROR("FactoryReset: read from sourcefile failed");
                        ret = false;
                        break;
                    }

                    if (std::fwrite(buffer.get(), 1, readsize, tf.get()) != readsize) {
                        LOG_ERROR("FactoryReset: write to targetfile %s failed", targetfile.c_str());
                        LOG_ERROR("FactoryReset: write to targetfile failed");
                        ret = false;
                        break;
                    }

M module-services/service-desktop/endpoints/filesystem/FileContext.cpp => module-services/service-desktop/endpoints/filesystem/FileContext.cpp +3 -3
@@ 51,7 51,7 @@ auto FileContext::getDataForFile() -> std::vector<std::uint8_t>
    std::unique_ptr<std::FILE, decltype(fileCloser)> file(std::fopen(path.c_str(), "rb"), fileCloser);

    if (!file) {
        LOG_ERROR("File %s open error", path.c_str());
        LOG_ERROR("File open error");
        return {};
    }



@@ 66,14 66,14 @@ auto FileContext::getDataForFile() -> std::vector<std::uint8_t>
    LOG_DEBUG("Read %u bytes", static_cast<unsigned int>(dataRead));

    if (dataRead != dataLeft) {
        LOG_ERROR("File %s read error", path.c_str());
        LOG_ERROR("File read error");
        return {};
    }

    advanceFileOffset(buffer.size());

    if (reachedEOF()) {
        LOG_INFO("Reached EOF of %s", path.c_str());
        LOG_INFO("Reached EOF");
    }

    return buffer;

M module-services/service-desktop/endpoints/filesystem/FileOperations.cpp => module-services/service-desktop/endpoints/filesystem/FileOperations.cpp +2 -2
@@ 19,7 19,7 @@ auto FileOperations::createReceiveIDForFile(const std::filesystem::path &file) -
    const auto size = std::filesystem::file_size(file);

    if (!size) {
        LOG_ERROR("File %s is empty", file.c_str());
        LOG_ERROR("File is empty");
        return std::make_pair(0, 0);
    }



@@ 29,7 29,7 @@ auto FileOperations::createReceiveIDForFile(const std::filesystem::path &file) -
        createFileContextFor(file, size, rxID);
    }
    catch (std::exception &e) {
        LOG_ERROR("FileOperations::createFileContextFor() exception: %s", e.what());
        LOG_ERROR("FileOperations::createFileContextFor() exception");
        return std::make_pair(0, 0);
    }


M module-services/service-desktop/endpoints/filesystem/FilesystemEndpoint.cpp => module-services/service-desktop/endpoints/filesystem/FilesystemEndpoint.cpp +8 -8
@@ 41,19 41,19 @@ auto FilesystemEndpoint::startGetFile(Context &context) const -> sys::ReturnCode
    std::filesystem::path filePath = context.getBody()[parserFSM::json::fileName].string_value();

    if (!std::filesystem::exists(filePath)) {
        LOG_ERROR("file not found: %s", filePath.c_str());
        LOG_ERROR("file not found");

        context.setResponseStatus(parserFSM::http::Code::NotFound);
        context.setResponseBody(json11::Json::object({{json::reason, json::filesystem::reasons::fileDoesNotExist}}));
        return sys::ReturnCodes::Failure;
    }

    LOG_DEBUG("Checking file: %s", filePath.c_str());
    LOG_DEBUG("Checking file");

    auto [rxID, fileSize] = fileOps.createReceiveIDForFile(filePath);

    if (!fileSize) {
        LOG_ERROR("File %s corrupted", filePath.c_str());
        LOG_ERROR("File is corrupted");

        context.setResponseStatus(parserFSM::http::Code::InternalServerError);
        context.setResponseBody(json11::Json::object({{json::reason, json::filesystem::reasons::fileDoesNotExist}}));


@@ 132,10 132,10 @@ auto FilesystemEndpoint::runPost(Context &context) -> sys::ReturnCodes
        const uint32_t fileSize = context.getBody()[parserFSM::json::fileSize].int_value();
        const auto fileCrc32    = context.getBody()[parserFSM::json::fileCrc32].string_value();

        LOG_DEBUG("got owner, file %s", tmpFilePath.c_str());
        LOG_DEBUG("got owner for tmp file");

        if (isWritable(tmpFilePath)) {
            LOG_INFO("download %" PRIu32 " bytes to: %s", fileSize, tmpFilePath.c_str());
            LOG_INFO("download %" PRIu32 " bytes to tmp file", fileSize);

            if (owner->desktopWorker->startDownload(tmpFilePath, fileSize, fileCrc32) == sys::ReturnCodes::Success) {
                context.setResponseStatus(parserFSM::http::Code::Accepted);


@@ 143,18 143,18 @@ auto FilesystemEndpoint::runPost(Context &context) -> sys::ReturnCodes
            }
        }
        else {
            LOG_ERROR("download command failed, can't write %" PRIu32 " bytes to: %s", fileSize, tmpFilePath.c_str());
            LOG_ERROR("download command failed, can't write %" PRIu32 " bytes to tmp file", fileSize);
        }
    }
    else if (cmd == parserFSM::json::filesystem::commands::checkFile) {
        fs::path filePath = context.getBody()[parserFSM::json::fileName].string_value();
        LOG_DEBUG("Checking file: %s", filePath.c_str());
        LOG_DEBUG("Checking file");

        context.setResponseBody(json11::Json::object{{json::fileExists, std::filesystem::exists(filePath)}});
        returnCode = sys::ReturnCodes::Success;
    }
    else {
        LOG_ERROR("unknown command: %s", cmd.c_str());
        LOG_ERROR("unknown command");
    }

    MessageHandler::putToSendQueue(context.createSimpleResponse());

M module-services/service-desktop/endpoints/messages/MessageHelper.cpp => module-services/service-desktop/endpoints/messages/MessageHelper.cpp +4 -4
@@ 353,7 353,7 @@ namespace parserFSM
            DBServiceAPI::GetQuery(ownerServicePtr, db::Interface::Name::SMSThread, std::move(query));
        }
        catch (const std::bad_cast &e) {
            LOG_ERROR("%s", e.what());
            LOG_ERROR("exception while requesting thread");
            return sys::ReturnCodes::Failure;
        }
        return sys::ReturnCodes::Success;


@@ 490,7 490,7 @@ namespace parserFSM
            DBServiceAPI::GetQuery(ownerServicePtr, db::Interface::Name::SMS, std::move(query));
        }
        catch (const std::bad_cast &e) {
            LOG_ERROR("%s", e.what());
            LOG_ERROR("exception while getting message by thread ID");
            return sys::ReturnCodes::Failure;
        }
        return sys::ReturnCodes::Success;


@@ 569,7 569,7 @@ namespace parserFSM
            DBServiceAPI::GetQuery(ownerServicePtr, db::Interface::Name::SMS, std::move(query));
        }
        catch (const std::bad_cast &e) {
            LOG_ERROR("%s", e.what());
            LOG_ERROR("exception while getting message");
            return sys::ReturnCodes::Failure;
        }
        return sys::ReturnCodes::Success;


@@ 657,7 657,7 @@ namespace parserFSM
            DBServiceAPI::GetQuery(ownerServicePtr, db::Interface::Name::SMSTemplate, std::move(query));
        }
        catch (const std::bad_cast &e) {
            LOG_ERROR("%s", e.what());
            LOG_ERROR("exception while getting messages template");
            return sys::ReturnCodes::Failure;
        }
        return sys::ReturnCodes::Success;

M module-services/service-desktop/endpoints/security/SecurityEndpointHelper.cpp => module-services/service-desktop/endpoints/security/SecurityEndpointHelper.cpp +1 -1
@@ 78,7 78,7 @@ auto SecurityEndpointHelper::processConfiguration(Context &context) -> http::Cod
                         : http::Code::InternalServerError;
        }
        catch (const std::exception &e) {
            LOG_ERROR("Passcode decoding exception: %s", e.what());
            LOG_ERROR("Passcode decoding exception");
        }
    }


M module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp => module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp +1 -2
@@ 615,8 615,7 @@ updateos::UpdateError UpdateMuditaOS::prepareTempDirForUpdate(const std::filesys
    if (!std::filesystem::is_directory(temporaryPath)) {
        informDebug("prepareTempDirForUpdate %s is not a directory", temporaryPath.c_str());
        if (!std::filesystem::create_directory(temporaryPath.c_str())) {
            return informError(
                updateos::UpdateError::CantCreateTempDir, "%s can't create it %s", temporaryPath.c_str());
            return informError(updateos::UpdateError::CantCreateTempDir, "can't create %s", temporaryPath.c_str());
        }
        else {
            informDebug("prepareTempDirForUpdate %s created", temporaryPath.c_str());

M module-services/service-fileindexer/ServiceFileIndexer.cpp => module-services/service-fileindexer/ServiceFileIndexer.cpp +5 -5
@@ 51,7 51,7 @@ namespace service
                    onTextContentChanged(fcm->newPath());
                    break;
                default:
                    LOG_INFO("Skip indexing file %s", fcm->newPath().c_str());
                    LOG_INFO("Skip indexing file");
                    break;
                }
            } break;


@@ 109,17 109,17 @@ namespace service
    // When file is changed update db only
    auto ServiceFileIndexer::onDeleteFile(std::string_view path) -> void
    {
        LOG_DEBUG("File deleted %s", std::string(path).c_str());
        LOG_DEBUG("File deleted");
    }
    // When file is renamed
    auto ServiceFileIndexer::onRenameFile(std::string_view oldPath, std::string_view newPath) -> void
    {
        LOG_DEBUG("File renamed old: %s, new: %s", std::string(oldPath).c_str(), std::string(newPath).c_str());
        LOG_DEBUG("File renamed");
    }
    // On audio file content change
    auto ServiceFileIndexer::onAudioContentChanged(std::string_view path) -> void
    {
        LOG_DEBUG("Audio content index %s", std::string(path).c_str());
        LOG_DEBUG("Audio content index...");
        TagLib::FileRef fref(std::string(path).c_str());
        if (!fref.isNull() && fref.tag()) {
            const auto tag = fref.tag();


@@ 144,7 144,7 @@ namespace service
    // On text file content change
    auto ServiceFileIndexer::onTextContentChanged(std::string_view path) -> void
    {
        LOG_DEBUG("Text content index %s", std::string(path).c_str());
        LOG_DEBUG("Text content index...");
        detail::notesIndexer noteInfo(path);
        LOG_DEBUG("Words %zu Lines %zu Chars %zu Size %zu",
                  noteInfo.getWords(),

M module-services/service-fileindexer/StartupIndexer.cpp => module-services/service-fileindexer/StartupIndexer.cpp +1 -1
@@ 44,7 44,7 @@ namespace service::detail
                    if (fs::path(path).extension() == ext.first) {
                        _this->mMsgs.emplace_back(std::make_shared<msg::FileChangeMessage>(
                            path, msg::FileChangeMessage::evt_t::modified, ""s));
                        LOG_DEBUG("Initial indexing file added %s", path);
                        LOG_DEBUG("Initial indexing file added");
                    }
                }
            }

M module-services/service-fileindexer/notesIndexer.cpp => module-services/service-fileindexer/notesIndexer.cpp +2 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <log.hpp>


@@ 14,7 14,7 @@ namespace service::detail
    {
        auto file = std::fopen(std::string(path).c_str(), "r");
        if (!file) {
            LOG_INFO("Unable to open file [%s]. Ignore...", std::string(path).c_str());
            LOG_INFO("Unable to open requested file. Ignore...");
            return;
        }
        if (!std::feof(file)) {

M module-services/service-fota/FotaServiceAPI.cpp => module-services/service-fota/FotaServiceAPI.cpp +1 -1
@@ 47,7 47,7 @@ namespace FotaService

    void API::FotaStart(sys::Service *serv, const std::string &url)
    {
        LOG_DEBUG("Fota Star: %s", url.c_str());
        LOG_DEBUG("Fota Start: %s", url.c_str());
        std::shared_ptr<FotaService::FOTAStart> msg = std::make_shared<FotaService::FOTAStart>();

        msg->url = url;

M module-services/service-lwip/ServiceLwIP.cpp => module-services/service-lwip/ServiceLwIP.cpp +1 -1
@@ 102,7 102,7 @@ sys::MessagePointer ServiceLwIP::DataReceivedHandler(sys::DataMessage *msg, sys:
        }
    }
    catch (std::exception &ex) {
        LOG_ERROR("Exception on BtService!: %s", ex.what());
        LOG_ERROR("Exception on ServiceLwIP!: %s", ex.what());
    }
    return std::make_shared<sys::ResponseMessage>();
}

M module-vfs/drivers/src/thirdparty/littlefs/lfs_glue.cpp => module-vfs/drivers/src/thirdparty/littlefs/lfs_glue.cpp +0 -1
@@ 69,7 69,6 @@ namespace purefs::fs::drivers::littlefs::internal
            }
            int read(const struct lfs_config *lfsc, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
            {
                // LOG_DEBUG("lfs_read_req(block=%u off=%u size=%u", unsigned(block), unsigned(off), unsigned(size));
                auto ctx = reinterpret_cast<io_context *>(lfsc->context);
                if (!ctx) {
                    return LFS_ERR_IO;

M module-vfs/src/purefs/blkdev/disk_manager.cpp => module-vfs/src/purefs/blkdev/disk_manager.cpp +3 -3
@@ 37,7 37,7 @@ namespace purefs::blkdev
        cpp_freertos::LockGuard _lck(*m_lock);
        const auto ret = m_dev_map.find(std::string(device_name));
        if (ret != std::end(m_dev_map)) {
            LOG_ERROR("Disc: %s already registered.", std::string(device_name).c_str());
            LOG_ERROR("Disc with same name already registered");
            return -EEXIST;
        }
        else {


@@ 62,7 62,7 @@ namespace purefs::blkdev
        cpp_freertos::LockGuard _lck(*m_lock);
        auto it = m_dev_map.find(std::string(device_name));
        if (it == std::end(m_dev_map)) {
            LOG_ERROR("Disc: %s doesn't exists in manager.", std::string(device_name).c_str());
            LOG_ERROR("Disc with given name doesn't exists in manager");
            return -ENOENT;
        }
        auto ret = it->second->cleanup();


@@ 245,7 245,7 @@ namespace purefs::blkdev
        for (const auto &disk : m_dev_map) {
            auto err = disk.second->pm_control(target_state);
            if (err) {
                LOG_ERROR("Unable to change PM state for device %s errno: %i", disk.first.c_str(), err);
                LOG_ERROR("Unable to change PM state for specified device. Errno: %i", err);
                last_err = err;
            }
        }

M module-vfs/src/purefs/fs/filesystem.cpp => module-vfs/src/purefs/fs/filesystem.cpp +5 -5
@@ 39,7 39,7 @@ namespace purefs::fs
        cpp_freertos::LockGuard _lck(*m_lock);
        const auto it = m_fstypes.find(std::string(fsname));
        if (it != std::end(m_fstypes)) {
            LOG_ERROR("Disc: %s already registered.", std::string(fsname).c_str());
            LOG_ERROR("Filesystem %s already registered", std::string(fsname).c_str());
            return -EEXIST;
        }
        else {


@@ 77,7 77,7 @@ namespace purefs::fs
    {
        // Sanity check input data
        if (target.size() <= 1 || target[0] != '/') {
            LOG_ERROR("VFS: Invalid target mountpoint path %s", std::string(target).c_str());
            LOG_ERROR("VFS: Invalid target mountpoint path");
            return -EINVAL;
        }
        if (flags & ~(mount_flags::remount | mount_flags::read_only)) {


@@ 93,13 93,13 @@ namespace purefs::fs
                    return {};
                }
                else {
                    LOG_ERROR("VFS: mount point already exists %s", std::string(target).c_str());
                    LOG_ERROR("VFS: given mount point already exists");
                    return -EBUSY;
                }
            }
            const auto mpp = m_partitions.find(std::string(dev_or_part));
            if (mpp != std::end(m_partitions)) {
                LOG_ERROR("VFS: partition already used %s", std::string(dev_or_part).c_str());
                LOG_ERROR("VFS: given partition already used");
                return -EBUSY;
            }
            std::string filesystem_type;


@@ 142,7 142,7 @@ namespace purefs::fs
                }
            }
            else {
                LOG_ERROR("Device or partition %s doesn't exists", std::string(dev_or_part).c_str());
                LOG_ERROR("Device or partition with given name doesn't exists");
                return -ENXIO;
            }
        }

M module-vfs/src/purefs/fs/filesystem_syscalls.cpp => module-vfs/src/purefs/fs/filesystem_syscalls.cpp +3 -3
@@ 145,13 145,13 @@ namespace purefs::fs
        const auto abspath     = absolute_path(path);
        auto [mountp, pathpos] = find_mount_point(abspath);
        if (!mountp) {
            LOG_ERROR("VFS: Unable to find mount point: %s", std::string(path).c_str());
            LOG_ERROR("VFS: Unable to find specified mount point");
            return -ENOENT;
        }
        auto fsops = mountp->fs_ops();
        if (fsops) {
            if ((flags & O_ACCMODE) != O_RDONLY && (mountp->flags() & mount_flags::read_only)) {
                LOG_ERROR("Trying to open file %.*s with WR... flag on RO filesystem", int(path.size()), path.data());
                LOG_ERROR("Trying to open file with WR... flag on RO filesystem");
                return -EACCES;
            }
            auto fh = fsops->open(mountp, abspath, flags, mode);


@@ 188,7 188,7 @@ namespace purefs::fs
        const auto abspath     = absolute_path(path);
        auto [mountp, pathpos] = find_mount_point(abspath);
        if (!mountp) {
            LOG_ERROR("VFS: Unable to find mount point: %s", std::string(path).c_str());
            LOG_ERROR("VFS: Unable to find specified mount point");
            return std::make_shared<internal::directory_handle>(nullptr, -ENOENT);
        }
        auto fsops = mountp->fs_ops();

M module-vfs/src/purefs/vfs_subsystem.cpp => module-vfs/src/purefs/vfs_subsystem.cpp +4 -4
@@ 73,23 73,23 @@ namespace purefs::subsystem
            struct stat stbuf;
            int err = vfsn->stat(file, stbuf);
            if (err) {
                LOG_ERROR("Unable to lock vfs fallback to current dir");
                LOG_ERROR("Unable to lock vfs. Fallback to current dir");
                return "current"s;
            }
            if (stbuf.st_size > boot_size_limit) {
                LOG_ERROR("Boot file to long fallback to current dir");
                LOG_ERROR("Boot file to long. Fallback to current dir");
                return "current"s;
            }
            std::string json_str(stbuf.st_size, ' ');
            std::string error;
            err = read_file_to_cpp_string(vfsn, file, json_str);
            if (err) {
                LOG_ERROR("Unable to read boot file fallback to current dir err %i", err);
                LOG_ERROR("Unable to read boot file (err: %i). Fallback to current dir", err);
                return "current"s;
            }
            auto json = json11::Json::parse(json_str, error);
            if (!error.empty()) {
                LOG_ERROR("Unable to parse json boot file fallback to current dir error %s", error.c_str());
                LOG_ERROR("Unable to parse json boot file (err: %s). Fallback to current dir", error.c_str());
                return "current"s;
            }
            return json[json::main][json::os_type].string_value();