Skip to content

Commit

Permalink
parallel package remove
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed May 20, 2024
1 parent 9c3ad6f commit 426e997
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/ccode/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs* jobs_new() {
j->current = 0;
j->finished = 0;
j->total = 0;
j->parallel = 4; /* Change as needed */
j->parallel = JOB_PARALLEL;
j->jobs = (job*)malloc(j->max * sizeof(job));
pthread_mutex_init(&j->mutex, NULL);
pthread_cond_init(&j->cond, NULL);
Expand Down
3 changes: 0 additions & 3 deletions src/data/package.vala
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public class package {
string files = readfile_cached (get_storage () + "/files/" + name);
return ssplit (files, "\n");
}
error_add (_ ("Package archive is missing."));
error (2);
return {};
}
string files = pkgfile.readfile ("files");
Expand All @@ -103,7 +101,6 @@ public class package {
string links = readfile_cached (get_storage () + "/links/" + name);
return ssplit (links, "\n");
}
error_add (_ ("Package archive is missing."));
return {};
}
string links = pkgfile.readfile ("links");
Expand Down
4 changes: 2 additions & 2 deletions src/include/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ typedef struct _jobs {
pthread_cond_t cond; /* Condition variable for signaling job completion */
} jobs;

#define MAX_JOB 1024

#define MAX_JOB 1024*1024
#define JOB_PARALLEL 8
void jobs_unref(jobs *j);
void jobs_add(jobs* j, void (*callback)(void*,...), void* ctx, void* args, ...);
void jobs_run(jobs* j);
Expand Down
29 changes: 16 additions & 13 deletions src/operations/package-manager/remove.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,40 @@ private static int remove_main (string[] args) {
}else {
info (_ ("Resolve reverse dependency done: %s").printf (join (" ", pkgs)));
}
jobs j = new jobs();
foreach (string pkg in pkgs) {
if (is_installed_package (pkg)) {
package p = get_installed_package (pkg);
remove_single (p);
package *p = get_installed_package (pkg);
//remove_single (p);
j.add((void*)remove_single, (void*)p);
}else {
warning (_ ("Package %s is not installed. Skip removing.").printf (pkg));
}
}
j.run();
set_value_readonly ("OPERATION", "postrm");
sysconf_main (args);
return 0;
}

private static int remove_single (package p) {
print (colorize (_ ("Removing: %s"), yellow).printf (p.name));
private static int remove_single (package *p) {
print (colorize (_ ("Removing: %s"), yellow).printf (p->name));
if (!get_bool ("without-files")) {
foreach (string file in p.list_links ()) {
foreach (string file in p->list_links ()) {
if (file.length > 3) {
file=ssplit (file, " ")[0];
info (_ ("Removing: %s").printf (file));
remove_file (DESTDIR + "/" + file);
}
}
foreach (string file in p.list_files ()) {
foreach (string file in p->list_files ()) {
if (file.length > 41) {
file=file[41:];
info (_ ("Removing: %s").printf (file));
remove_file (DESTDIR + "/" + file);
}
}
foreach (string file in p.list_links ()) {
foreach (string file in p->list_links ()) {
if (file.length > 3) {
file=ssplit (file, " ")[0];
string dir = sdirname (file);
Expand All @@ -72,7 +75,7 @@ private static int remove_single (package p) {
}
}
}
foreach (string file in p.list_files ()) {
foreach (string file in p->list_files ()) {
if (file.length > 41) {
file=file[41:];
string dir = sdirname (file);
Expand All @@ -83,11 +86,11 @@ private static int remove_single (package p) {
}
}
if (!get_bool ("without-metadata")) {
remove_file (get_storage () + "/metadata/" + p.name + ".yaml");
remove_file (get_storage () + "/files/" + p.name);
remove_file (get_storage () + "/links/" + p.name);
if (isdir (get_storage () + "/sysconf/" + p.name)) {
remove_all (get_storage () + "/sysconf/" + p.name);
remove_file (get_storage () + "/metadata/" + p->name + ".yaml");
remove_file (get_storage () + "/files/" + p->name);
remove_file (get_storage () + "/links/" + p->name);
if (isdir (get_storage () + "/sysconf/" + p->name)) {
remove_all (get_storage () + "/sysconf/" + p->name);
}
}
return 0;
Expand Down

0 comments on commit 426e997

Please sign in to comment.