Fixed installing issue with no set remote

- Added default remote repo
- Fixed adding and removing remote repos
This commit is contained in:
David Allen 2023-05-27 13:47:52 -06:00
parent 8b1f1374d8
commit 996c47466e
6 changed files with 46 additions and 29 deletions

View file

@ -23,8 +23,10 @@ namespace gdpm::constants::error{
DIRECTORY_EXISTS,
DIRECTORY_NOT_FOULD,
HOST_UNREACHABLE,
REMOTE_NOT_FOUND,
EMPTY_RESPONSE,
INVALID_ARGS,
INVALID_ARG_COUNT,
INVALID_CONFIG,
INVALID_KEY,
HTTP_RESPONSE_ERROR,

View file

@ -47,7 +47,7 @@ namespace gdpm::package {
bool enable_cache = true;
bool enable_sync = true;
bool skip_prompt = false;
string remote_source = "";
string remote_source = "origin";
install_method_e install_method = GLOBAL_LINK_LOCAL;
};

View file

@ -15,7 +15,7 @@ namespace gdpm::remote{
GDPM_DLL_EXPORT error _handle_remote(config::context& config, const args_t& args, const opts_t& opts);
GDPM_DLL_EXPORT void set_repositories(config::context& context, const repository_map& repos);
GDPM_DLL_EXPORT void add_repositories(config::context& context, const repository_map& repos);
GDPM_DLL_EXPORT void remove_respositories(config::context& context, const repo_names& name);
GDPM_DLL_EXPORT void remove_respositories(config::context& context, const repo_names& names);
GDPM_DLL_EXPORT void move_repository(config::context& context, int old_position, int new_position);
GDPM_DLL_EXPORT void print_repositories(const config::context& context);
}

0
src/README.md Normal file
View file

View file

@ -90,6 +90,16 @@ namespace gdpm::package{
return error();
}
/* Check if provided param is in remote sources*/
if(!config.remote_sources.contains(params.remote_source)){
error error(
constants::error::NOT_FOUND,
"Remote resource not found in config."
);
log::error(error);
return error;
}
/* Try and obtain all requested packages. */
std::vector<string_pair> dir_pairs;
task_list tasks;
@ -161,7 +171,7 @@ namespace gdpm::package{
/* Check if we already have a stored temporary file before attempting to download */
if(std::filesystem::exists(tmp_zip) && std::filesystem::is_regular_file(tmp_zip)){
log::println("Found cached package. Skipping download.", p.title);
log::info("Found cached package. Skipping download.", p.title);
}
else{
/* Download all the package files and place them in tmp directory. */
@ -226,7 +236,7 @@ namespace gdpm::package{
if(p_cache.empty()){
error error(
constants::error::NOT_FOUND,
"\nCould not find any packages to remove."
"Could not find any packages to remove."
);
log::error(error);
return error;

View file

@ -11,14 +11,6 @@ namespace gdpm::remote{
const args_t& args,
const opts_t& opts
){
log::println("_handle_remote");
for(const auto& arg : args){
log::println("arg: {}", arg);
}
for(const auto& opt : opts){
log::println("opt: {}:{}", opt.first, utils::join(opt.second));
}
/* Check if enough arguments are supplied */
size_t argc = args.size();
if (argc < 1){
@ -28,19 +20,30 @@ namespace gdpm::remote{
/* Check which subcommand is supplied */
string sub_command = args.front();
args_t argv(args.begin()+1, args.end());
if(argv.size() < 2){
if(sub_command == "add"){
if(args.size() < 3 || args.empty()){
error error(
constants::error::INVALID_ARGS,
"Invalid number of args"
constants::error::INVALID_ARG_COUNT,
"Invalid number of args."
);
log::error(error);
return error;
}
string name = argv[1];
string url = argv[2];
if(sub_command == "add") add_repositories(config, {{name, url}});
else if (sub_command == "remove") remove_respositories(config, argv);
string name = args[1];
string url = args[2];
add_repositories(config, {{name, url}});
}
else if (sub_command == "remove") {
if(args.size() < 2 || args.empty()){
error error(
constants::error::INVALID_ARG_COUNT,
"Invalid number of args."
);
log::error(error);
return error;
}
remove_respositories(config, {args.begin()+1, args.end()});
}
// else if (sub_command == "set") set_repositories(config::context &context, const repository_map &repos)
else if (sub_command == "list") print_repositories(config);
else{
@ -79,9 +82,12 @@ namespace gdpm::remote{
config::context& config,
const repo_names& names
){
std::for_each(names.end(), names.begin(), [&config](const string& repo){
config.remote_sources.erase(repo);
});
for(auto it = names.begin(); it != names.end();){
if(config.remote_sources.contains(*it)){
config.remote_sources.erase(*it);
}
it++;
}
}
@ -94,10 +100,9 @@ namespace gdpm::remote{
}
void print_repositories(const config::context& config){
log::println("Remote sources:");
const auto &rs = config.remote_sources;
std::for_each(rs.begin(), rs.end(), [](const string_pair& p){
log::println("\t{}: {}", p.first, p.second);
log::println("{}: {}", p.first, p.second);
});
}
}