blob: 63bfb2f9b3a37e6c5297687ba2b54fa7c42fb58b (
plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#include "pch.h"
#include "StatusParagraph.h"
#include "vcpkglib_helpers.h"
using namespace vcpkg::details;
namespace vcpkg
{
//
namespace BinaryParagraphRequiredField
{
static const std::string STATUS = "Status";
}
StatusParagraph::StatusParagraph() : want(Want::ERROR_STATE), state(InstallState::ERROR_STATE)
{
}
void serialize(const StatusParagraph& pgh, std::string& out_str)
{
serialize(pgh.package, out_str);
out_str.append("Status: ").append(to_string(pgh.want)).append(" ok ").append(to_string(pgh.state)).push_back('\n');
}
StatusParagraph::StatusParagraph(const std::unordered_map<std::string, std::string>& fields)
: package(fields)
{
std::string status_field = required_field(fields, BinaryParagraphRequiredField::STATUS);
auto b = status_field.begin();
auto mark = b;
auto e = status_field.end();
// Todo: improve error handling
while (b != e && *b != ' ')
++b;
want = [](const std::string& text)
{
if (text == "unknown")
return Want::UNKNOWN;
if (text == "install")
return Want::INSTALL;
if (text == "hold")
return Want::HOLD;
if (text == "deinstall")
return Want::DEINSTALL;
if (text == "purge")
return Want::PURGE;
return Want::ERROR_STATE;
}(std::string(mark, b));
if (std::distance(b, e) < 4)
return;
b += 4;
state = [](const std::string& text)
{
if (text == "not-installed")
return InstallState::NOT_INSTALLED;
if (text == "installed")
return InstallState::INSTALLED;
if (text == "half-installed")
return InstallState::HALF_INSTALLED;
return InstallState::ERROR_STATE;
}(std::string(b, e));
}
std::string to_string(InstallState f)
{
switch (f)
{
case InstallState::HALF_INSTALLED: return "half-installed";
case InstallState::INSTALLED: return "installed";
case InstallState::NOT_INSTALLED: return "not-installed";
default: return "error";
}
}
std::string to_string(Want f)
{
switch (f)
{
case Want::DEINSTALL: return "deinstall";
case Want::HOLD: return "hold";
case Want::INSTALL: return "install";
case Want::PURGE: return "purge";
case Want::UNKNOWN: return "unknown";
default: return "error";
}
}
}
|