-
Notifications
You must be signed in to change notification settings - Fork 0
/
Package.cpp
115 lines (103 loc) · 2.52 KB
/
Package.cpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include "Package.h"
using namespace std;
Package::Package(string PackageOrigin, unordered_map<string,Package> &Scope)
{
FILE *Pipe;
char Buffer[128];
string GetFlavorCmd = (string) "pkg info " +
(string) PackageOrigin +
(string) "| grep 'flavor :' | cut -f 4 -w";
string GetAutomaticStateCmd = (string) "pkg query -e '%o=" +
(string) PackageOrigin +
(string) "' %a";
string GetDependencies;
Origin = PackageOrigin;
cout << " Computing flavor of package...";
Pipe = popen(GetFlavorCmd.c_str(),"r");
if(!Pipe)
{
cerr << "Error while retrieving flavor of package " + Origin + "." << endl;
exit(1);
}
Buffer[1] = 0;
fgets(Buffer,128,Pipe);
pclose(Pipe);
Buffer[strlen(Buffer) - 1] = 0;
Flavor = string(Buffer);
cout << Flavor + "." << endl;
cout << " Computing automatic state of package...";
Pipe = popen(GetAutomaticStateCmd.c_str(),"r");
if(!Pipe)
{
cerr << "Error while retrieving automatic state of package " + Origin + "." << endl;
exit(1);
}
fgets(Buffer,2,Pipe);
pclose(Pipe);
Automatic = (bool) (Buffer[0] - '0');
if(Automatic) cout << "true." << endl;
else cout << "false." << endl;
cout << " Computing dependencies..." << endl;
GetDependencies = (string) "pkg query -e \"\%o=" +
(string) Origin +
(string) "\" \%do";
Pipe = popen(GetDependencies.c_str(),"r");
if(!Pipe)
{
cerr << "Error while retrieving dependencies." << endl;
exit(1);
}
while(fgets(Buffer,128,Pipe))
{
Buffer[strlen(Buffer) - 1] = 0;
try
{
Dependencies.push_back(&(Scope.at(Buffer)));
cout << " " << Buffer << " is outdated." << endl;
}
catch(...)
{
};
}
pclose(Pipe);
}
void Package::SimulateUpdate(unsigned int RecursionDegree)
{
for(auto PkgPtr: Dependencies) PkgPtr->SimulateUpdate(RecursionDegree + 1);
if(Outdated)
{
string ToBeUpdated = string(RecursionDegree, ' ') +
(string) Origin +
"\n";
cout << ToBeUpdated;
Outdated = false;
}
}
void Package::Update()
{
for(auto PkgPtr: Dependencies) PkgPtr->Update();
if(Outdated)
{
string UpdateCommand = (string) "cd " +
(string) PORTSDIR +
(string) "/" +
(string) Origin +
(string) " && make build deinstall install clean";
if(!Flavor.empty())
{
UpdateCommand += " FLAVOR=" +
(string) Flavor;
}
if(Automatic)
{
UpdateCommand += " INSTALLS_DEPENDS=-A";
}
Outdated = false;
if(system(UpdateCommand.c_str()))
{
cerr << "Error while updating port " << Origin << "." << endl;
exit(2);
}
}
}