C++ seems like a less than ideal language for this, but here are some comments:
main.cpp:
totally unnecessary heap allocations of your Pacmanpp objects. They should just be on the stack:
Pacmanpp pacman;
pacman.update();
But if you insist on heap allocation, for the love of god use a smart pointer, as auto pacman = std::make_unique<Pacmanpp>();. This is guaranteed to free the object for you when it goes out of scope. In general, raw new/delete are bad ideas in new, modern C++.
Don't use std::list! It's a horrible inefficient linked list. Just use std::vector. Also, you don't need to explicitly iterate (L39,L58), since the vector constructor can take two iterators:
L43: explicit iterators are disfavored. Prefer for (const auto& s : packages).
Also, strncmp is a pain in the ass. You can compare cstrings to string literals (""s) using ==.
Package.cpp:
complete overusage of this pointer which is not typically necessary. Example: prefer std::string Package::getName() { return name; }.
Lack of const on methods that should be const (don't change the underlying object. checkIfGit, getName, etc. should be marked const.
Default constructor/destructor are not necessary. Destructor especially, but if you need the no-arg constructor in particular for some reason, prefer Package() = default;.
Pacmanpp.cpp:
populateList: inconsistent use of sudo when messing around with that tempfile. In fact, why use a tempfile at all, if you're so system-happy? You could fork/exec and pipe the child process's stdout directly to you. Also, the system command has an extra echo and subshell that aren't necessary but will just fuck up your whitespace. Also, running this method multiple times will duplicate the packages again. It's probably better to return a new vector here, or else remember to clear the member variable before you do this.
curlPackages: L273: more explicit iteration. Easier:
for (const auto& p : packages) {
curlOne(multi, p.getURL(), p.PKGBUILD);
}
removeDuplicates is really just two calls from <algorithm>:
void removeDuplicates(std::vector<Package>& v) {
std::sort(
v.begin(),
v.end(),
[](const auto& a, const auto& b) {
return a.getName() < b.getName();
});
auto it = std::unique(
v.begin(),
v.end(),
[](const auto& a, const auto& b) {
return a.getName == b.getName();
});
v.erase(it, v.end());
}
Also, useless comment. Also, could be made static since it doesn't need any member variables. Could even be a free function.
printSearchResults should take a constref, not a vector by value. Way overdone error checking on std::stoi num, why not std::cin >> num and just check that return value? Way easier. L402: more explicit iteration. Also, could be static, again.
parsePACMAN: holy hell, use a library. libxml2 would work. Some for parseAUR.
Sudo-related stuff: This seems like a huge hack. Is it really necessary? Why not run the whole thing under sudo? Sub-threads should also be privileged, right?
Anyway, this is just off the top of my head, there's probably more.
C++ seems like a less than ideal language for this, but here are some comments:
main.cpp:
totally unnecessary heap allocations of your Pacmanpp objects. They should just be on the stack:
But if you insist on heap allocation, for the love of god use a smart pointer, as
auto pacman = std::make_unique<Pacmanpp>();. This is guaranteed to free the object for you when it goes out of scope. In general, raw new/delete are bad ideas in new, modern C++.Don't use
std::list! It's a horrible inefficient linked list. Just usestd::vector. Also, you don't need to explicitly iterate (L39,L58), since the vector constructor can take two iterators:L43: explicit iterators are disfavored. Prefer
for (const auto& s : packages).Also,
strncmpis a pain in the ass. You can compare cstrings to string literals (""s) using==.Package.cpp:
complete overusage of
thispointer which is not typically necessary. Example: preferstd::string Package::getName() { return name; }.Lack of
conston methods that should be const (don't change the underlying object.checkIfGit,getName, etc. should be marked const.Default constructor/destructor are not necessary. Destructor especially, but if you need the no-arg constructor in particular for some reason, prefer
Package() = default;.Pacmanpp.cpp:
populateList: inconsistent use ofsudowhen messing around with that tempfile. In fact, why use a tempfile at all, if you're sosystem-happy? You could fork/exec and pipe the child process's stdout directly to you. Also, the system command has an extra echo and subshell that aren't necessary but will just fuck up your whitespace. Also, running this method multiple times will duplicate the packages again. It's probably better to return a new vector here, or else remember toclearthe member variable before you do this.curlPackages: L273: more explicit iteration. Easier:removeDuplicatesis really just two calls from<algorithm>:Also, useless comment. Also, could be made static since it doesn't need any member variables. Could even be a free function.
printSearchResultsshould take a constref, not a vector by value. Way overdone error checking onstd::stoinum, why notstd::cin >> numand just check that return value? Way easier. L402: more explicit iteration. Also, could be static, again.parsePACMAN: holy hell, use a library.libxml2would work. Some forparseAUR.Sudo-related stuff: This seems like a huge hack. Is it really necessary? Why not run the whole thing under sudo? Sub-threads should also be privileged, right?
Anyway, this is just off the top of my head, there's probably more.
You've taken your first step into a larger world.
It does not seem like a great idea to "get around" your work IT department without talking to them.
26 invocations of pacman and 26 invocations of grep and 26 open/seek/write/close operations on pkgs.txt?
And that's why you don't guess where your script is:
http://mywiki.wooledge.org/BashFAQ/028