~aleteoryx/muditaos

6665a43d2b901b89809c4f18338d8ea6c0b08df7 — Lefucjusz 2 years ago 73b72b9
[BH-1780] Fix uncaught std::filesystem::file_size exception

Fix of the issue that exceptions thrown
by file_size method were not caught
at all, what resulted in system crashing.
M harmony_changelog.md => harmony_changelog.md +1 -0
@@ 9,6 9,7 @@
* Fixed not disappearing snooze icon when an alarm is deactivated
* Fixed incorrect message after new alarm setting in some scenarios
* Fixed frequency lock during user activity
* Fixed possibility of OS crash during update package size check

### Added
* Files not fully transferred via Center will be now removed when USB cable is unplugged

M module-services/service-desktop/endpoints/update/UpdateHelper.cpp => module-services/service-desktop/endpoints/update/UpdateHelper.cpp +15 -7
@@ 20,7 20,10 @@

namespace sdesktop::endpoints
{
    constexpr auto chunkSize = 1024 * 128;
    namespace
    {
        constexpr auto chunkSize = 1024 * 128;
    }

    struct UpdatePackageEntries
    {


@@ 56,7 59,7 @@ namespace sdesktop::endpoints
        std::string err;
        const auto versionJson = json11::Json::parse(buffer.str(), err);
        if (!err.empty()) {
            LOG_ERROR("Parsing '%s' failed", path.c_str());
            LOG_ERROR("Parsing '%s' failed, error message: '%s'", path.c_str(), err.c_str());
            return std::nullopt;
        }
        return versionJson;


@@ 85,7 88,7 @@ namespace sdesktop::endpoints
        }

        std::fclose(fd);
        return md5.getHash() == hash;
        return (md5.getHash() == hash);
    }

    bool removeDirectory(const std::filesystem::path &path)


@@ 112,7 115,7 @@ namespace sdesktop::endpoints
            tar::unpack(path, where);
        }
        catch (const std::filesystem::filesystem_error &err) {
            LOG_ERROR("Unpacking tar '%s' failed with %s", path.c_str(), err.what());
            LOG_ERROR("Unpacking tar '%s' failed with '%s'", path.c_str(), err.what());
            return false;
        }
        return true;


@@ 141,7 144,13 @@ namespace sdesktop::endpoints
            return false;
        }

        const auto requiredSpace = std::filesystem::file_size(updatePackage);
        std::error_code fileSizeError;
        const auto requiredSpace = std::filesystem::file_size(updatePackage, fileSizeError);
        if (fileSizeError) {
            LOG_ERROR("File size check failed, error message: '%s'", fileSizeError.message().c_str());
            return false;
        }

        const auto freeSpace = (static_cast<std::uint64_t>(stat.f_bfree) * static_cast<std::uint64_t>(stat.f_bsize));
        LOG_INFO("Checking available space: %" PRIu64 " bytes, required: %" PRIu64 " bytes",
                 freeSpace,


@@ 156,7 165,7 @@ namespace sdesktop::endpoints
        return std::filesystem::exists(path);
    }

    void UpdateHelper::preProcess(http::Method method, Context &context)
    void UpdateHelper::preProcess(http::Method method, [[maybe_unused]] Context &context)
    {
        LOG_INFO("In UpdateHelper - requesting %d", static_cast<int>(method));
    }


@@ 197,5 206,4 @@ namespace sdesktop::endpoints
    UpdateHelper::UpdateHelper(sys::Service *p)
        : BaseHelper(p), updatePackagePath{purefs::dir::getTemporaryPath() / "update"}, binariesPath{get_binary_dir()}
    {}

} // namespace sdesktop::endpoints

M pure_changelog.md => pure_changelog.md +1 -0
@@ 27,6 27,7 @@
* Fixed alarm preview playback behavior
* Fixed frequency lock during user activity
* Fixed crash on transferring audio file with big metadata
* Fixed possibility of OS crash during update package size check

## [1.8.0 2023-09-27]