• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

KittensBasket / dasboot / 15105410690

19 May 2025 05:55AM UTC coverage: 74.584% (+7.9%) from 66.7%
15105410690

push

github

web-flow
Add initial TImageManager (#55)

* Add initial TImageManager

* God bless

---------

Co-authored-by: voidzeronull0 <user@omen.localdomain>

147 of 284 branches covered (51.76%)

Branch coverage included in aggregate %.

35 of 97 new or added lines in 2 files covered. (36.08%)

3 existing lines in 1 file now uncovered.

1467 of 1880 relevant lines covered (78.03%)

13.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.16
/dasboot/core/coordinator/imagemanager.cpp
1
#include "imagemanager.hpp"
2

3
namespace NImageManager {
4

5
    TStatus TImageManager::Install(Images image) {
1✔
6
        TStatus status;
1✔
7

8
        status = DownloadImage(image);
1✔
9
        if (status.Code == TStatus::Failed) {
1!
10
            status.Error = "TImageManager::Install: " + status.Error;
1✔
11
            return status;
1✔
12
        }
1✔
13

NEW
14
        status = DearchiveImage();
×
NEW
15
        return { TStatus::Success };
×
16
    }
1✔
17

18
    // GOD FORBID US - curl requires C-styled function with this signature
19
    // TBD - move it to os.hpp - VoidZeroNull0
NEW
20
    size_t WriteArchive(void* ptr, size_t size, size_t nmemb, FILE* stream) {
×
NEW
21
        return fwrite(ptr, size, nmemb, stream);
×
NEW
22
    }
×
23

24
    TStatus TImageManager::DownloadImage(Images image) {
1✔
25
        TStatus status;
1✔
26

27
        CURL* curl = curl_easy_init();
1✔
28
        if (!curl) {
1!
NEW
29
            status.Code = TStatus::Failed;
×
NEW
30
            status.Error = "TImageManager::DownloadImage:Could not init curl";
×
NEW
31
            return status;
×
NEW
32
        }
×
33

34
        std::string url;
1✔
35
        CurrentImageName = "";
1✔
36
        if (image == Images::Alpine) {
1!
37
            url = "https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.3-x86_64.tar.gz";
1✔
38
            CurrentImageName = "alpine";
1✔
39
        }
1✔
NEW
40
        else {
×
NEW
41
            status.Code = TStatus::Failed;
×
NEW
42
            status.Error = "TImageManager::DownloadImage: Non-implemented image";
×
NEW
43
            return status; 
×
NEW
44
        }
×
45

46
        std::string path = MakeString() << ImagesLocation << CurrentImageName << ".tar.gz"; 
1✔
47

48
        FILE* file = fopen(path.c_str(), "wb");
1✔
49
        if (!file) {
1!
50
            status.Code = TStatus::Failed;
1✔
51
            status.Error = "TImageManager::DownloadImage: Could not create file";
1✔
52
            return status;
1✔
53
        }
1✔
54

NEW
55
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
×
NEW
56
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteArchive);
×
NEW
57
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
×
NEW
58
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
×
59

NEW
60
        CURLcode result = curl_easy_perform(curl);
×
NEW
61
        if (result != CURLE_OK) {
×
NEW
62
            status.Code = TStatus::Failed;
×
NEW
63
            status.Error = MakeString() << "TImageManager::DownloadImage: Curl result error" << result;
×
NEW
64
            fclose(file);
×
NEW
65
            curl_easy_cleanup(curl);
×
NEW
66
            return status;
×
NEW
67
        }
×
68

NEW
69
        fclose(file);
×
NEW
70
        curl_easy_cleanup(curl);
×
71

NEW
72
        return { TStatus::Success };
×
NEW
73
    }
×
74

NEW
75
    TStatus TImageManager::DearchiveImage() {
×
NEW
76
        TStatus status;
×
77

NEW
78
        struct archive* a = archive_read_new();
×
NEW
79
        struct archive* ext = archive_write_disk_new();
×
NEW
80
        struct archive_entry* entry;
×
81

NEW
82
        archive_read_support_format_tar(a);
×
NEW
83
        archive_read_support_filter_gzip(a); // для .gz
×
84

NEW
85
        std::string path = MakeString() << ImagesLocation << CurrentImageName << ".tar.gz";
×
NEW
86
        if (archive_read_open_filename(a, path.c_str(), 10240)) {
×
NEW
87
            status.Code = TStatus::Failed;
×
NEW
88
            status.Error = "TImageManager::DownloadImage: Could not open archive";
×
NEW
89
            return status;
×
NEW
90
        }
×
91

NEW
92
        path = MakeString() << ImagesLocation << "/" << CurrentImageName;
×
NEW
93
        while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
×
NEW
94
            const char* currentFile = archive_entry_pathname(entry);
×
NEW
95
            std::string fullOutputPath = path + "/" + currentFile;
×
NEW
96
            archive_entry_set_pathname(entry, fullOutputPath.c_str());
×
97

NEW
98
            archive_write_header(ext, entry);
×
NEW
99
            const void* buff;
×
NEW
100
            size_t size;
×
NEW
101
            la_int64_t offset;
×
102

NEW
103
            while (archive_read_data_block(a, &buff, &size, &offset) == ARCHIVE_OK) {
×
NEW
104
                archive_write_data_block(ext, buff, size, offset);
×
NEW
105
            }
×
NEW
106
        }
×
107

NEW
108
        archive_read_close(a);
×
NEW
109
        archive_read_free(a);
×
NEW
110
        archive_write_close(ext);
×
NEW
111
        archive_write_free(ext);
×
112

NEW
113
        return { TStatus::Success };
×
NEW
114
    }
×
115
} // namespace NImageManager
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc