Merge pull request 'Fixed repo adding; Implemented check for repeating packages inside repository' (#35) from YanTheKaller/ubl-settings-repomanager:master into master

Reviewed-on: #35
pull/39/head^2 v2.5
Dmitry Razumov 2 years ago
commit 7d6bdfb859

@ -408,44 +408,43 @@ void on_repo_add_new(GtkWidget *self, dictionary *dict){
name = window->path;
if (!name||strcmp(name,"")!=0){
GtkTreeIter *iter = yon_repo_append(widgets, name, YON_REPO_LINE_REPO_TYPE);
struct dirent *de;
GtkTreeIter child;
char *reponame = yon_char_new(name);
yon_char_divide(reponame,yon_char_find_last(reponame,'/'));
char *searchpath = yon_char_unite(name,"/",reponame,"/x86_64/",NULL);
DIR *directory = opendir(searchpath);
if (directory){
char *found_packages = NULL;
while ((de = readdir(directory)))
{
if (strstr(de->d_name,"pkg.tar.")&&!strstr(de->d_name,".sig")){
char *filename = yon_char_unite(searchpath,"/",de->d_name,NULL);
FILE *file = popen(get_package_info_command(filename),"r");
char *cur_string=g_malloc0(sizeof(char)*4096);
char *packname=NULL, *packver=NULL, *packarch=NULL, *packdepends=NULL;
while (fgets(cur_string,4096,file)){
char *stringe = yon_char_divide_search(cur_string,"\n",-1);
char *p = yon_char_divide_search(stringe,":",-1);
if (strstr(p,"Name")) packname = yon_char_new(stringe);
else if (strstr(p,"Version")) packver = yon_char_new(stringe);
else if (strstr(p,"Architecture")) packarch = yon_char_new(stringe);
else if (strstr(p,"Depends On")) packdepends = yon_char_new(stringe);
else if (strstr(p,"Depends On")) packdepends = yon_char_new(stringe);
if (iter){
struct dirent *de;
GtkTreeIter child;
char *reponame = yon_char_new(name);
yon_char_divide(reponame,yon_char_find_last(reponame,'/'));
char *searchpath = yon_char_unite(name,"/",reponame,"/x86_64/",NULL);
DIR *directory = opendir(searchpath);
if (directory){
char *found_packages = NULL;
while ((de = readdir(directory)))
{
if (strstr(de->d_name,"pkg.tar.")&&!strstr(de->d_name,".sig")){
char *filename = yon_char_unite(searchpath,"/",de->d_name,NULL);
FILE *file = popen(get_package_info_command(filename),"r");
char *cur_string=g_malloc0(sizeof(char)*4096);
char *packname=NULL, *packver=NULL, *packarch=NULL, *packdepends=NULL;
while (fgets(cur_string,4096,file)){
char *stringe = yon_char_divide_search(cur_string,"\n",-1);
char *p = yon_char_divide_search(stringe,":",-1);
if (strstr(p,"Name")) packname = yon_char_new(stringe);
else if (strstr(p,"Version")) packver = yon_char_new(stringe);
else if (strstr(p,"Architecture")) packarch = yon_char_new(stringe);
else if (strstr(p,"Depends On")) packdepends = yon_char_new(stringe);
else if (strstr(p,"Depends On")) packdepends = yon_char_new(stringe);
}
gtk_tree_store_append(main_config.tree_store,&child,iter);
gtk_tree_store_set(main_config.tree_store,&child,0,document_no_edits,1,yon_char_unite(packname,"-",packver,"-",packarch,NULL),2,filename,3,0,9,packname,10,packver,11,packarch,12,packdepends,-1);
found_packages = yon_char_unite(found_packages ? yon_char_append(found_packages," ") : "",de->d_name,NULL);
}
gtk_tree_store_append(main_config.tree_store,&child,iter);
gtk_tree_store_set(main_config.tree_store,&child,0,document_no_edits,1,yon_char_unite(packname,"-",packver,"-",packarch,NULL),2,filename,3,0,9,packname,10,packver,11,packarch,12,packdepends,-1);
found_packages = yon_char_unite(found_packages ? yon_char_append(found_packages,",") : "",de->d_name,NULL);
}
}
yon_window_config_add_custom_parameter(window->path,"repos",found_packages,YON_TYPE_STRING);
gtk_tree_store_set(main_config.tree_store,iter,0,folder_no_edits,2,window->path,3,0,9,reponame,-1);
} else {
gtk_tree_store_set(main_config.tree_store,iter,0,folder_added,2,window->path,3,1,9,reponame,-1);
yon_window_config_add_custom_parameter(window->path,"repos",found_packages,YON_TYPE_STRING);
gtk_tree_store_set(main_config.tree_store,iter,0,folder_no_edits,2,window->path,3,0,9,reponame,-1);
} else {
gtk_tree_store_set(main_config.tree_store,iter,0,folder_added,2,window->path,3,1,9,reponame,-1);
}
yon_ubl_status_box_render(OPERATION_DONE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
} else {
yon_ubl_status_box_render(EMPTY_NAME_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
}
}
}
}
@ -468,7 +467,6 @@ void on_repo_new (GtkWidget *self, main_window *widgets){
dictionary *dict = yon_dictionary_new_with_data("",widgets);
dict = yon_dictionary_append_with_data(dict,"",window);
on_repo_add_new(self,dict);
yon_ubl_status_box_render(OPERATION_DONE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
void on_repo_add_file(GtkWidget *self, main_window *widgets){
@ -600,6 +598,16 @@ GtkTreeIter *yon_repo_append(main_window *widgets, char *name, YON_REPO_LINE_TYP
GtkTreeModel *model = GTK_TREE_MODEL(main_config.tree_store);
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepoTree)),&model,&parentIter)){
if (type==YON_REPO_LINE_REPO_TYPE){
GtkTreeIter ater;
char *repo_path;
int valid = gtk_tree_model_get_iter_first(model,&ater);
for (;valid;valid=gtk_tree_model_iter_next(model,&ater)){
gtk_tree_model_get(model,&ater,2,&repo_path,-1);
if (!strcmp(repo_path,name)){
yon_ubl_status_box_render(REPO_ALREADY_EXISTS_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
return NULL;
}
}
gtk_tree_store_append(main_config.tree_store,&iter,NULL);
gtk_tree_store_set(main_config.tree_store,&iter,0, folder_no_edits, 1, name_short,2,name,3,1,4,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
@ -608,15 +616,36 @@ GtkTreeIter *yon_repo_append(main_window *widgets, char *name, YON_REPO_LINE_TYP
GtkTreeIter branch;
if (gtk_tree_model_iter_parent(model,&branch,&parentIter)){
GtkTreeIter repo;
gtk_tree_store_append(main_config.tree_store,&iter,&branch);
gtk_tree_store_set(main_config.tree_store,&iter,0, document_no_edits, 1, name_short,2,name,3,1,4,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
char *filename;
int valid = gtk_tree_model_iter_nth_child(model,&repo,&branch,0);
for (;valid;valid=gtk_tree_model_iter_next(model,&repo)){
gtk_tree_model_get(model,&repo,1,&filename,-1);
if (!strcmp(yon_char_divide_search(yon_char_new(name_short),".pkg.tar",-1), filename)){
yon_ubl_status_box_render(ALREADY_EXIST,BACKGROUND_IMAGE_FAIL_TYPE);
return NULL;
}
free(filename);
}
gtk_tree_store_append(main_config.tree_store,&iter,&branch);
gtk_tree_store_set(main_config.tree_store,&iter,0, document_no_edits, 1, name_short,2,name,3,1,4,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
} else {
gtk_tree_store_append(main_config.tree_store,&iter,&parentIter);
gtk_tree_store_set(main_config.tree_store,&iter,0, document_no_edits, 1, name_short,2,name,3,1,4,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
GtkTreeIter repo;
char *filename;
int valid = gtk_tree_model_iter_nth_child(model,&repo,&parentIter,0);
for (;valid;valid=gtk_tree_model_iter_next(model,&repo)){
gtk_tree_model_get(model,&repo,1,&filename,-1);
if (!strcmp(yon_char_divide_search(yon_char_new(name_short),".pkg.tar",-1), filename)){
yon_ubl_status_box_render(ALREADY_EXIST,BACKGROUND_IMAGE_FAIL_TYPE);
return NULL;
}
free(filename);
}
gtk_tree_store_append(main_config.tree_store,&iter,&parentIter);
gtk_tree_store_set(main_config.tree_store,&iter,0, document_no_edits, 1, name_short,2,name,3,1,4,fls,-1);
retIter = gtk_tree_iter_copy(&iter);
}
yon_ubl_status_box_render(OPERATION_DONE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
}
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(widgets->RepoTree)),&iter);
@ -712,12 +741,12 @@ void yon_add_file(main_window *widgets){
}
int add = 1;
GtkTreeIter *iter = yon_repo_append(widgets,filename,YON_REPO_LINE_FILE_TYPE);
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(widgets->RepoTree),gtk_tree_model_get_path(GTK_TREE_MODEL(main_config.tree_store),iter));
gtk_tree_store_set(main_config.tree_store,iter,0,document_added,1,yon_char_unite(packname,"-",packver,"-",packarch,NULL),2,filename,3,add,9,packname,10,packver,11,packarch,12,packdepends,-1);
if (iter){
gtk_tree_view_expand_to_path(GTK_TREE_VIEW(widgets->RepoTree),gtk_tree_model_get_path(GTK_TREE_MODEL(main_config.tree_store),iter));
gtk_tree_store_set(main_config.tree_store,iter,0,document_added,1,yon_char_unite(packname,"-",packver,"-",packarch,NULL),2,filename,3,add,9,packname,10,packver,11,packarch,12,packdepends,-1);
}
}
on_tree_selection_changed(NULL,widgets);
yon_ubl_status_box_render(OPERATION_DONE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
on_close_subwindow(chooser);

@ -39,7 +39,7 @@
#define LocaleName "ubl-settings-repomanager"
typedef char* string;
#define get_package_info_command(filename) yon_char_unite("LC_ALL=EN pacman -Q --info --file ",filename," ||sed -e 's/ */ /g' -e 's/ : /:/g' -e 's/\\n/ /g'",NULL)
#define get_package_info_command(filename) yon_char_unite("LC_ALL=EN pacman -Q --info --file ",filename," |sed -e 's/ */ /g' -e 's/ : /:/g' -e 's/\\n/ /g'",NULL)
#define get_saved_package_info_command(path,filename) yon_char_unite("LC_ALL=EN pacman -Q --info --file $(find \"",path,"\" -name *",filename,"* -not -name *.sig |head -n 1)|sed -e 's/ */ /g' -e 's/ : /:/g' -e 's/\\n/ /g'",NULL)
#define get_gpg_keys_command yon_char_unite(yon_ubl_check_root()==1 ? yon_char_unite("su - ",yon_ubl_root_user_get()," -c \"gpg --list-signatures\"",NULL):"gpg --list-signatures"," | grep '^sig 3' | cut -d' ' -f10,11,13- | sort -u |sed -e 's/[0-9]*-[0-9]*-[0-9]* //g'",NULL)

@ -80,4 +80,6 @@
#define DIGITAL_SIGNATURE_LABEL _("Digital signature")
#define PACKAGE_LABEL _("package")
#define REPOSITORY_LABEL _("repository")
#define REPOSITORY_LABEL _("repository")
#define ALREADY_EXIST _("This package already exists in that repository")
#define REPO_ALREADY_EXISTS_LABEL _("This repository has already been added")

@ -326,3 +326,11 @@ msgstr ""
#: source/ubl-strings.h:83
msgid "repository"
msgstr ""
#: source/ubl-strings.h:84
msgid "This package already exists in that repository"
msgstr ""
#: source/ubl-strings.h:84
msgid "This repository has already been added"
msgstr ""

@ -332,4 +332,12 @@ msgstr "пакет"
#: source/ubl-strings.h:83
msgid "repository"
msgstr "репозиторий"
msgstr "репозиторий"
#: source/ubl-strings.h:84
msgid "This package already exists in that repository"
msgstr "Этот пакет уже присутствует в выбранном репозитории"
#: source/ubl-strings.h:84
msgid "This repository has already been added"
msgstr "Этот репозиторий уже был добавлен"
Loading…
Cancel
Save