Browse Source

Manager: Handle package list errors

master
Riyyi 3 years ago
parent
commit
7672180eb7
  1. 23
      src/package.cpp
  2. 2
      src/package.h

23
src/package.cpp

@ -42,7 +42,13 @@ void Package::install()
void Package::list(const std::vector<std::string>& targets)
{
std::string packages = getPackageList();
auto packagesOrEmpty = getPackageList();
if (!packagesOrEmpty.has_value()) {
return;
}
std::string packages = packagesOrEmpty.value();
if (targets.empty()) {
printf("%s", packages.c_str());
@ -68,11 +74,15 @@ void Package::list(const std::vector<std::string>& targets)
void Package::store()
{
std::string packages = getPackageList();
auto packagesOrEmpty = getPackageList();
if (!packagesOrEmpty.has_value()) {
return;
}
auto packageFile = Util::File::create("./packages");
packageFile.clear();
packageFile.append(packages);
packageFile.append(packagesOrEmpty.value());
packageFile.flush();
}
@ -210,10 +220,11 @@ bool Package::distroDependencies()
return true;
}
std::string Package::getPackageList()
std::optional<std::string> Package::getPackageList()
{
distroDetect();
distroDependencies();
if (!distroDetect() || !distroDependencies()) {
return {};
}
std::string packages;

2
src/package.h

@ -39,7 +39,7 @@ private:
bool findDependency(const std::string& search);
bool distroDetect();
bool distroDependencies();
std::string getPackageList();
std::optional<std::string> getPackageList();
Distro m_distro { Distro::Unsupported };
};

Loading…
Cancel
Save