~aleteoryx/muditaos

ref: 17417f8777165b0dc5e1eedb834eda68d8d8365b muditaos/module-services/service-desktop/endpoints/update/UpdateHelper.cpp -rw-r--r-- 1.3 KiB
17417f87 — Marcin Smoczyński [CP-742] Fix assembly not being build 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
39
40
41
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <endpoints/update/UpdateHelper.hpp>
#include <endpoints/Context.hpp>
#include <log/log.hpp>
#include <SystemManager/SystemManagerCommon.hpp>
#include <purefs/filesystem_paths.hpp>

#include <filesystem>

namespace sdesktop::endpoints
{

    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, ResponseContext{.status = http::Code::BadRequest}};
        }

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

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

        return {sent::no, ResponseContext{.status = http::Code::InternalServerError}};
    }

} // namespace sdesktop::endpoints