~aleteoryx/muditaos

ref: 65193f0a677e3f3606193d00eace4df74e916ae6 muditaos/module-services/service-desktop/endpoints/update/UpdateHelper.cpp -rw-r--r-- 1.3 KiB
65193f0a — Mateusz Piesta [BH-626] Home screen 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "UpdateHelper.hpp"
#include <log.hpp>
#include <SystemManager/SystemManager.hpp>
#include <purefs/filesystem_paths.hpp>

#include <filesystem>

namespace parserFSM
{
    auto constexpr updatePackageFile = "update.tar";

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

    auto UpdateHelper::processPost(Context &context) -> ProcessResult
    {
        const auto &body = context.getBody();

        if (!(body["update"] == true && body["reboot"] == true)) {
            return {sent::no, endpoint::ResponseContext{.status = http::Code::BadRequest}};
        }

        if (!std::filesystem::exists(purefs::dir::getUserDiskPath() / updatePackageFile)) {
            return {sent::no, endpoint::ResponseContext{.status = http::Code::NotFound}};
        }

        if (sys::SystemManager::RebootToUpdate(owner, sys::UpdateReason::Update)) {
            return {sent::no, endpoint::ResponseContext{.status = http::Code::NoContent}};
        }

        return {sent::no, endpoint::ResponseContext{.status = http::Code::InternalServerError}};
    }
} // namespace parserFSM