Skip to content

Commit

Permalink
3 things
Browse files Browse the repository at this point in the history
- Added upgrade as the default command.
- Fixed dependency lookups ignoring MakeDepends
- Upgrading your system ignores any errors, and continues with the other packages, It will tell you about it after.
  • Loading branch information
BurntRanch committed Mar 8, 2024
1 parent f91a8ff commit aad7e06
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
30 changes: 23 additions & 7 deletions src/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ string getUrl(rapidjson::Value& pkgJson, bool returnGit = false) {
}

TaurPkg_t parsePkg(rapidjson::Value& pkgJson, bool returnGit = false) {
if (pkgJson.HasMember("Depends") && pkgJson["Depends"].IsArray()) {
if (pkgJson.HasMember("Depends") && pkgJson["Depends"].IsArray() && pkgJson.HasMember("MakeDepends") && pkgJson["MakeDepends"].IsArray()) {
const rapidjson::Value& dependsArray = pkgJson["Depends"].GetArray();
const rapidjson::Value& makeDependsArray = pkgJson["MakeDepends"].GetArray();

vector<string> depends;
for (size_t i = 0; i < dependsArray.Size(); i++)
depends.push_back(dependsArray[i].GetString());
for (size_t i = 0; i < makeDependsArray.Size(); i++) {
if (std::find(depends.begin(), depends.end(), makeDependsArray[i].GetString()) != depends.end())
continue;
depends.push_back(makeDependsArray[i].GetString());
}

return (TaurPkg_t) { pkgJson["Name"].GetString(), pkgJson["Version"].GetString(), getUrl(pkgJson, returnGit), depends };
}
Expand Down Expand Up @@ -263,11 +269,16 @@ bool TaurBackend::install_pkg(TaurPkg_t pkg, string extracted_path, bool useGit)
TaurPkg_t depend = oDepend.value();

string filename = path(this->config.cacheDir) / depend.url.substr(depend.url.rfind("/") + 1);

if (useGit)
filename = filename.substr(0, filename.rfind(".git"));
else
filename = filename.substr(0, filename.rfind(".tar.gz"));

bool downloadStatus = this->download_pkg(depend.url, filename);

if (!downloadStatus) {
std::cerr << "Failed to download dependency of " << pkg.name << " (Source: " << depend.url << ")" << std::endl;
std::cerr << "====[ ERROR ]==== Failed to download dependency of " << pkg.name << " (Source: " << depend.url << ")" << std::endl;
return false;
}

Expand All @@ -276,7 +287,7 @@ bool TaurBackend::install_pkg(TaurPkg_t pkg, string extracted_path, bool useGit)
bool installStatus = this->install_pkg(depend, out_path, useGit);

if (!installStatus) {
std::cerr << "Failed to install dependency of " << pkg.name << " (" << depend.name << ")" << std::endl;
std::cerr << "====[ ERROR ]==== Failed to install dependency of " << pkg.name << " (" << depend.name << ")" << std::endl;
return false;
}
}
Expand All @@ -301,6 +312,7 @@ bool TaurBackend::update_all_pkgs(path cacheDir, bool useGit) {
vector<TaurPkg_t> onlinePkgs = this->fetch_pkgs(pkgNames, useGit);

int updatedPkgs = 0;
int attemptedDownloads = 0;

if (onlinePkgs.size() != pkgs.size())
std::cout << "Couldn't get all packages! Still trying to update the others." << std::endl;
Expand All @@ -326,21 +338,25 @@ bool TaurBackend::update_all_pkgs(path cacheDir, bool useGit) {
}

std::cout << "Upgrading package " << pkgs[pkgIndex].name << " from version " << pkgs[pkgIndex].version << " to version " << onlinePkgs[i].version << "!" << std::endl;

attemptedDownloads++;

bool downloadSuccess = this->download_pkg(onlinePkgs[i].url, cacheDir / onlinePkgs[i].name);

if (!downloadSuccess)
return false;
continue;

bool installSuccess = this->install_pkg(onlinePkgs[i], cacheDir / onlinePkgs[i].name, useGit);

if (!installSuccess)
return false;
continue;

updatedPkgs++;
}

std::cout << "Upgraded " << updatedPkgs << " packages." << std::endl;
std::cout << "Upgraded " << updatedPkgs << "/" << attemptedDownloads << " packages." << std::endl;

if (attemptedDownloads < updatedPkgs)
std::cout << "Some packages failed to download, Please redo this command and log the issue." << std::endl << "If it is an issue with TabAUR, feel free to open an issue in GitHub." << std::endl;

return true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ int parsearg_op(int opt){
}

int parseargs(int argc, char* argv[]){
// default
operation.op = OP_SYSUPGRADE;

int opt;
int option_index = 0;
int result;
Expand Down Expand Up @@ -198,8 +201,8 @@ int main(int argc, char* argv[]) {
return (removePkg(operation.args[0], &backend)) ? 0 : 1;
case OP_QUERY:
return (queryPkgs(&backend)) ? 0 : 1;
//case OP_UPDATE_ALL:
// return (updateAll(&backend)) ? 0 : 1;
case OP_SYSUPGRADE:
return (updateAll(&backend)) ? 0 : 1;
}

return 3;
Expand Down

0 comments on commit aad7e06

Please sign in to comment.