|
Lines 71-76
int rematch(const char *, const char *,
|
Link Here
|
|---|
|
static char *rmspace(char *); | static char *rmspace(char *); |
| |
void initialize_portage_env(void); | void initialize_portage_env(void); |
|
void initialize_overlays (char portdir_overlay[]); |
void initialize_ebuild_flat(void); | void initialize_ebuild_flat(void); |
void reinitialize_ebuild_flat(void); | void reinitialize_ebuild_flat(void); |
void reinitialize_as_needed(void); | void reinitialize_as_needed(void); |
|
|
static char pretend = 0; | static char pretend = 0; |
static char reinitialize = 0; | static char reinitialize = 0; |
static char reinitialize_metacache = 0; | static char reinitialize_metacache = 0; |
static char portdir[_Q_PATH_MAX] = "/usr/portage"; |
|
static char portarch[20] = ""; | static char portarch[20] = ""; |
static char portvdb[] = "var/db/pkg"; | static char portvdb[] = "var/db/pkg"; |
static char portcachedir[] = "metadata/cache"; | static char portcachedir[] = "metadata/cache"; |
static char portroot[_Q_PATH_MAX] = "/"; | static char portroot[_Q_PATH_MAX] = "/"; |
static char config_protect[_Q_PATH_MAX] = "/etc/"; | static char config_protect[_Q_PATH_MAX] = "/etc/"; |
| |
|
typedef struct overlay_t overlay_t; |
|
struct overlay_t { |
|
char name[64]; |
|
char path[_Q_PATH_MAX]; |
|
struct overlay_t *next; |
|
}; |
|
|
|
static overlay_t *overlay_gentoo = NULL; |
|
|
char pkgdir[512] = "/usr/portage/packages/"; | char pkgdir[512] = "/usr/portage/packages/"; |
char port_tmpdir[512] = "/var/tmp/portage/"; | char port_tmpdir[512] = "/var/tmp/portage/"; |
| |
|
|
getopt_long(argc, argv, ex A ## _FLAGS, a ## _long_opts, NULL) | getopt_long(argc, argv, ex A ## _FLAGS, a ## _long_opts, NULL) |
/* display usage and exit */ | /* display usage and exit */ |
static void usage(int status, const char *flags, struct option const opts[], | static void usage(int status, const char *flags, struct option const opts[], |
const char *help[], int blabber) |
const char *help[], int blabber) |
{ | { |
unsigned long i; | unsigned long i; |
if (blabber == 0) { | if (blabber == 0) { |
|
Lines 199-208
static void usage(int status, const char
|
Link Here
|
|---|
|
for (i = 0; opts[i].name; ++i) { | for (i = 0; opts[i].name; ++i) { |
assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */ | assert(help[i] != NULL); /* this assert is a life saver when adding new applets. */ |
if (opts[i].has_arg == no_argument) | if (opts[i].has_arg == no_argument) |
printf(" -%c, --%-15s%s*%s %s\n", opts[i].val, |
printf(" -%c, --%-16s%s*%s %s\n", opts[i].val, |
opts[i].name, RED, NORM, _(help[i])); | opts[i].name, RED, NORM, _(help[i])); |
else | else |
printf(" -%c, --%-8s %s<arg>%s %s*%s %s\n", opts[i].val, |
printf(" -%c, --%-9s %s<arg>%s %s*%s %s\n", opts[i].val, |
opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i])); | opts[i].name, DKBLUE, NORM, RED, NORM, _(help[i])); |
} | } |
exit(status); | exit(status); |
|
Lines 213-219
static void version_barf(const char *Id)
|
Link Here
|
|---|
|
# define VERSION "cvs" | # define VERSION "cvs" |
#endif | #endif |
printf("portage-utils-%s: compiled on %s\n%s\n" | printf("portage-utils-%s: compiled on %s\n%s\n" |
"%s written for Gentoo by <solar and vapier @ gentoo.org>\n", |
"%s written for Gentoo by <solar and vapier @ gentoo.org>\n" |
|
"modified for overlay support by samuelethiec @ hotmail.com\n", |
VERSION, __DATE__, Id, argv0); | VERSION, __DATE__, Id, argv0); |
exit(EXIT_SUCCESS); | exit(EXIT_SUCCESS); |
} | } |
|
Lines 298-336
static char *remove_extra_space(char *st
|
Link Here
|
|---|
|
void freeargv(int, char **); | void freeargv(int, char **); |
void freeargv(int argc, char **argv) { | void freeargv(int argc, char **argv) { |
int i; | int i; |
if (argc > 0) { |
if (argc > 0) { |
for (i = 0; i < argc; i++) |
for (i = 0; i < argc; i++) |
free(argv[i]); |
free(argv[i]); |
free(argv); |
free(argv); |
} |
} |
} | } |
| |
void makeargv(char *string, int *argc, char ***argv); | void makeargv(char *string, int *argc, char ***argv); |
void makeargv(char *string, int *argc, char ***argv) { | void makeargv(char *string, int *argc, char ***argv) { |
int curc = 2; | int curc = 2; |
char *q, *p, *str; |
char *q, *p, *str; |
(*argv) = (char **) malloc(sizeof(char **) * curc); | (*argv) = (char **) malloc(sizeof(char **) * curc); |
| |
*argc = 1; |
*argc = 1; |
(*argv)[0] = xstrdup(argv0); | (*argv)[0] = xstrdup(argv0); |
q = xstrdup(string); |
q = xstrdup(string); |
str = q; | str = q; |
| |
remove_extra_space(str); |
remove_extra_space(str); |
rmspace(str); | rmspace(str); |
| |
while (str) { | while (str) { |
if ((p = strchr(str, ' ')) != NULL) | if ((p = strchr(str, ' ')) != NULL) |
*(p++) = '\0'; | *(p++) = '\0'; |
| |
if (*argc == curc) { |
if (*argc == curc) { |
curc *= 2; | curc *= 2; |
(*argv) = (char **) realloc(*argv, sizeof(char **) * curc); | (*argv) = (char **) realloc(*argv, sizeof(char **) * curc); |
} |
} |
(*argv)[*argc] = xstrdup(str); |
(*argv)[*argc] = xstrdup(str); |
(*argc)++; |
(*argc)++; |
str = p; |
str = p; |
} |
} |
free(q); | free(q); |
} | } |
| |
|
Lines 453-469
char *strincr_var(const char *name, char
|
Link Here
|
|---|
|
return (char *) value; | return (char *) value; |
} | } |
| |
|
void initialize_overlays (char portdir_overlay[]) |
|
{ |
|
short merror = 0; |
|
char buf[BUFSIZE], file[_Q_PATH_MAX], *s, *p, *t; |
|
overlay_t *cur_overlay; |
|
FILE *repo_nameFP; |
|
s = portdir_overlay; |
|
cur_overlay = overlay_gentoo; |
|
|
|
while (*s) { |
|
cur_overlay->next = (overlay_t *) xmalloc ( sizeof (*cur_overlay->next)); |
|
cur_overlay = cur_overlay->next; |
|
cur_overlay->next = NULL; |
|
|
|
if ( (p=strchr(s,' '))) |
|
*p = 0; |
|
|
|
strncpy(cur_overlay->path, s, sizeof(cur_overlay->path)); |
|
|
|
/* find the name for the overlay */ |
|
strncpy(file, cur_overlay->path, _Q_PATH_MAX); |
|
strncat(file, "/profiles/repo_name", _Q_PATH_MAX); |
|
if (( repo_nameFP = fopen(file, "r") )) |
|
{ |
|
if ( ! ( fgets(buf, sizeof(buf),repo_nameFP)) ) |
|
merror++; |
|
|
|
rmspace(buf); |
|
if ( (t = strchr(buf,'\n'))) |
|
*t = 0; |
|
|
|
strncpy(cur_overlay->name, buf, sizeof(cur_overlay->name)); |
|
|
|
fclose(repo_nameFP); |
|
|
|
} else |
|
merror++; |
|
|
|
if (merror) { |
|
/* delete trailing '/' */ |
|
t = cur_overlay->path + strlen(cur_overlay->path) - 1; |
|
if ( *t == '/' ) |
|
*t = 0; |
|
|
|
strncat(cur_overlay->name, basename(cur_overlay->path), sizeof(cur_overlay->name)); |
|
merror=0; |
|
} |
|
|
|
if (p) |
|
s = p+1; |
|
else |
|
break; |
|
} |
|
|
|
} |
|
|
|
|
void initialize_portage_env(void) | void initialize_portage_env(void) |
{ | { |
char nocolor = 0; | char nocolor = 0; |
int i, f; | int i, f; |
struct stat st; | struct stat st; |
FILE *fp; | FILE *fp; |
|
char tmp_portdir[_Q_PATH_MAX]; |
|
char portdir_overlay[2048] = ""; |
|
|
char buf[BUFSIZE], *s, *p; | char buf[BUFSIZE], *s, *p; |
| |
char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX]; | char profile[_Q_PATH_MAX], portage_file[_Q_PATH_MAX]; |
|
|
const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"}; | const char *files[] = {portage_file, "/etc/make.globals", "/etc/make.conf"}; |
typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types; | typedef enum { _Q_BOOL, _Q_STR, _Q_ISTR } var_types; |
|
|
struct { | struct { |
const char *name; | const char *name; |
const size_t name_len; | const size_t name_len; |
|
Lines 471-489
void initialize_portage_env(void)
|
Link Here
|
|---|
|
char *value; | char *value; |
const size_t value_len; | const size_t value_len; |
} vars_to_read[] = { | } vars_to_read[] = { |
{"ACCEPT_LICENSE", 14, _Q_STR, accept_license, sizeof(accept_license)}, |
{"ACCEPT_LICENSE", 14, _Q_STR, accept_license, sizeof(accept_license) }, |
{"INSTALL_MASK", 12, _Q_ISTR, install_mask, sizeof(install_mask)}, |
{"INSTALL_MASK", 12, _Q_ISTR, install_mask, sizeof(install_mask) }, |
{"ARCH", 4, _Q_STR, portarch, sizeof(portarch)}, |
{"ARCH", 4, _Q_STR, portarch, sizeof(portarch) }, |
{"CONFIG_PROTECT", 14, _Q_STR, config_protect, sizeof(config_protect)}, |
{"CONFIG_PROTECT", 14, _Q_STR, config_protect, sizeof(config_protect) }, |
{"NOCOLOR", 7, _Q_BOOL, &nocolor, 1}, |
{"NOCOLOR", 7, _Q_BOOL, &nocolor, 1 }, |
{"FEATURES",8, _Q_ISTR, features, sizeof(features)}, |
{"FEATURES", 8, _Q_ISTR, features, sizeof(features) }, |
{"PORTDIR", 7, _Q_STR, portdir, sizeof(portdir)}, |
{"PORTDIR", 7, _Q_STR, tmp_portdir, sizeof(tmp_portdir) }, |
{"PORTAGE_BINHOST", 15, _Q_STR, binhost, sizeof(binhost)}, |
{"PORTDIR_OVERLAY", 15, _Q_ISTR, portdir_overlay, sizeof(portdir_overlay) }, |
{"PORTAGE_TMPDIR", 14, _Q_STR, port_tmpdir, sizeof(port_tmpdir)}, |
{"PORTAGE_BINHOST", 15, _Q_STR, binhost, sizeof(binhost) }, |
{"PKGDIR", 6, _Q_STR, pkgdir, sizeof(pkgdir)}, |
{"PORTAGE_TMP", 9, _Q_STR, port_tmpdir, sizeof(port_tmpdir) }, |
{"ROOT", 4, _Q_STR, portroot, sizeof(portroot)} |
{"PKGDIR", 6, _Q_STR, pkgdir, sizeof(pkgdir) }, |
|
{"ROOT", 4, _Q_STR, portroot, sizeof(portroot) } |
}; | }; |
| |
|
overlay_gentoo = (overlay_t*) xmalloc(sizeof(*overlay_gentoo)); |
|
strcpy(overlay_gentoo->name,"gentoo"); |
|
strcpy(overlay_gentoo->path,"/usr/portage"); |
|
overlay_gentoo->next = NULL; |
|
|
|
|
if ((p = strchr(portroot, '/')) != NULL) | if ((p = strchr(portroot, '/')) != NULL) |
if (strlen(p) != 1) | if (strlen(p) != 1) |
strncat(portroot, "/", sizeof(portroot)); | strncat(portroot, "/", sizeof(portroot)); |
|
Lines 575-580
void initialize_portage_env(void)
|
Link Here
|
|---|
|
no_colors(); | no_colors(); |
else | else |
color_remap(); | color_remap(); |
|
|
|
|
|
strncpy(overlay_gentoo->path, tmp_portdir, sizeof(overlay_gentoo->path)); |
|
|
|
/* now we initiliase the overlay chained list with overlay_gentoo the first 'item' */ |
|
initialize_overlays(portdir_overlay); |
|
|
} | } |
| |
enum { | enum { |
|
Lines 603-621
const char *initialize_flat(int cache_ty
|
Link Here
|
|---|
|
int a, b, c, d, e, i; | int a, b, c, d, e, i; |
int frac, secs, count; | int frac, secs, count; |
FILE *fp; | FILE *fp; |
|
overlay_t *cur_overlay; |
| |
a = b = c = d = e = i = 0; | a = b = c = d = e = i = 0; |
count = frac = secs = 0; | count = frac = secs = 0; |
|
cur_overlay = overlay_gentoo; |
| |
cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE); | cache_file = (cache_type == CACHE_EBUILD ? CACHE_EBUILD_FILE : CACHE_METADATA_FILE); |
| |
if (chdir(portdir) != 0) { |
if (chdir(overlay_gentoo->path) != 0) { |
warnp("chdir to PORTDIR '%s' failed", portdir); |
warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path); |
goto ret; | goto ret; |
} | } |
| |
if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) { | if (cache_type == CACHE_METADATA && chdir(portcachedir) != 0) { |
warnp("chdir to portage cache '%s/%s' failed", portdir, portcachedir); |
warnp("chdir to paludis cache '%s/%s' failed", overlay_gentoo->path, portcachedir); |
goto ret; | goto ret; |
} | } |
| |
|
Lines 631-694
const char *initialize_flat(int cache_ty
|
Link Here
|
|---|
|
| |
unlink(cache_file); | unlink(cache_file); |
if (errno != ENOENT) { | if (errno != ENOENT) { |
warnfp("unlinking '%s/%s' failed", portdir, cache_file); |
warnfp("unlinking '%s/%s' failed", overlay_gentoo->path, cache_file); |
goto ret; | goto ret; |
} | } |
| |
if ((fp = fopen(cache_file, "w")) == NULL) { | if ((fp = fopen(cache_file, "w")) == NULL) { |
warnfp("opening '%s/%s' failed", portdir, cache_file); |
warnfp("opening '%s/%s' failed", overlay_gentoo->path, cache_file); |
goto ret; | goto ret; |
} | } |
| |
gettimeofday(&start, NULL); | gettimeofday(&start, NULL); |
| |
if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0) |
do { |
goto ret; |
if ( cur_overlay == overlay_gentoo || chdir(cur_overlay->path) == 0) { |
|
if ((a = scandir(".", &category, filter_hidden, alphasort)) < 0) |
for (i = 0 ; i < a; i++) { |
|
stat(category[i]->d_name, &st); |
|
if (!S_ISDIR(st.st_mode)) |
|
continue; |
|
if (strchr(category[i]->d_name, '-') == NULL) |
|
if ((strncmp(category[i]->d_name, "virtual", 7)) != 0) |
|
continue; | continue; |
| |
if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0) |
for (i = 0 ; i < a; i++) { |
continue; |
stat(category[i]->d_name, &st); |
for (c = 0; c < b; c++) { |
if (!S_ISDIR(st.st_mode)) |
char de[_Q_PATH_MAX]; |
continue; |
|
if (strchr(category[i]->d_name, '-') == NULL) |
|
if ((strncmp(category[i]->d_name, "virtual", 7)) != 0) |
|
continue; |
| |
snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name); |
if ((b = scandir(category[i]->d_name, &pn, filter_hidden, alphasort)) < 0) |
|
continue; |
|
for (c = 0; c < b; c++) { |
|
char de[_Q_PATH_MAX]; |
| |
if (stat(de, &st) < 0) |
snprintf(de, sizeof(de), "%s/%s", category[i]->d_name, pn[c]->d_name); |
continue; |
|
| |
switch (cache_type) { |
if (stat(de, &st) < 0) |
case CACHE_EBUILD: |
continue; |
if (!S_ISDIR(st.st_mode)) |
|
continue; |
switch (cache_type) { |
break; |
case CACHE_EBUILD: |
case CACHE_METADATA: |
if (!S_ISDIR(st.st_mode)) |
if (S_ISREG(st.st_mode)) |
continue; |
fprintf(fp, "%s\n", de); |
break; |
continue; |
case CACHE_METADATA: |
break; |
if (S_ISREG(st.st_mode)) |
} |
fprintf(fp, "%s\n", de); |
if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0) |
continue; |
continue; |
break; |
for (d = 0 ; d < e; d++) { |
} |
if ((p = strrchr(eb[d]->d_name, '.')) != NULL) |
if ((e = scandir(de, &eb, filter_hidden, alphasort)) < 0) |
if (strcmp(p, ".ebuild") == 0) { |
continue; |
count++; |
for (d = 0 ; d < e; d++) { |
fprintf(fp, "%s/%s/%s\n", category[i]->d_name, pn[c]->d_name, eb[d]->d_name); |
if ((p = strrchr(eb[d]->d_name, '.')) != NULL) |
|
if (strcmp(p, ".ebuild") == 0) { |
|
count++; |
|
fprintf(fp, "%s::%s/%s/%s\n", cur_overlay->name, category[i]->d_name, pn[c]->d_name, eb[d]->d_name); |
|
} |
} | } |
|
while(d--) |
|
free(eb[d]); |
|
free(eb); |
|
} |
|
while(b--) |
|
free(pn[b]); |
|
free(pn); |
} | } |
while(d--) free(eb[d]); |
} else |
free(eb); |
warnp("chdir to PORTDIR '%s' failed, skipping the %s repository", cur_overlay->path, cur_overlay->name); |
} |
|
while(b--) free(pn[b]); |
} while ( (cur_overlay = cur_overlay->next)); |
free(pn); |
|
} |
|
fclose(fp); | fclose(fp); |
while(a--) free(category[a]); | while(a--) free(category[a]); |
free(category); | free(category); |
|
Lines 699-705
const char *initialize_flat(int cache_ty
|
Link Here
|
|---|
|
if (start.tv_usec > finish.tv_usec) { | if (start.tv_usec > finish.tv_usec) { |
finish.tv_usec += 1000000; | finish.tv_usec += 1000000; |
finish.tv_sec--; | finish.tv_sec--; |
|
|
} | } |
frac = (finish.tv_usec - start.tv_usec); | frac = (finish.tv_usec - start.tv_usec); |
secs = (finish.tv_sec - start.tv_sec); | secs = (finish.tv_sec - start.tv_sec); |
|
Lines 708-714
const char *initialize_flat(int cache_ty
|
Link Here
|
|---|
|
| |
warn("Finished %u entries in %d.%06d seconds", count, secs, frac); | warn("Finished %u entries in %d.%06d seconds", count, secs, frac); |
if (secs > 100) | if (secs > 100) |
warn("You should consider a faster file system such as reiserfs for PORTDIR='%s'", portdir); |
warn("You should consider a faster file system such as reiserfs for PORTDIR='%s'", overlay_gentoo->path); |
ret: | ret: |
return cache_file; | return cache_file; |
} | } |
|
|
| |
void reinitialize_ebuild_flat(void) | void reinitialize_ebuild_flat(void) |
{ | { |
if ((chdir(portdir)) != 0) { |
if ((chdir(overlay_gentoo->path)) != 0) { |
warnp("chdir to PORTDIR '%s' failed", portdir); |
warnp("chdir to PORTDIR '%s' failed", overlay_gentoo->path); |
return; | return; |
} | } |
unlink(CACHE_EBUILD_FILE); | unlink(CACHE_EBUILD_FILE); |
|
Lines 900-918
void cache_free(portage_cache *cache)
|
Link Here
|
|---|
|
| |
char *grab_vdb_item(const char *, const char *, const char *); | char *grab_vdb_item(const char *, const char *, const char *); |
char *grab_vdb_item(const char *item, const char *CATEGORY, const char *PF) { | char *grab_vdb_item(const char *item, const char *CATEGORY, const char *PF) { |
static char buf[_Q_PATH_MAX]; |
static char buf[_Q_PATH_MAX]; |
char *p; |
char *p; |
FILE *fp; |
FILE *fp; |
| |
snprintf(buf, sizeof(buf), "%s%s/%s/%s/%s", portroot, portvdb, CATEGORY, PF, item); | snprintf(buf, sizeof(buf), "%s%s/%s/%s/%s", portroot, portvdb, CATEGORY, PF, item); |
if ((fp = fopen(buf, "r")) == NULL) | if ((fp = fopen(buf, "r")) == NULL) |
return NULL; |
return NULL; |
fgets(buf, sizeof(buf), fp); | fgets(buf, sizeof(buf), fp); |
if ((p = strchr(buf, '\n')) != NULL) |
if ((p = strchr(buf, '\n')) != NULL) |
*p = 0; | *p = 0; |
fclose(fp); | fclose(fp); |
rmspace(buf); | rmspace(buf); |
|
|
return buf; | return buf; |
} | } |
| |
|
Lines 922-928
queue *get_vdb_atoms(void) {
|
Link Here
|
|---|
|
int dfd, i; | int dfd, i; |
| |
char buf[_Q_PATH_MAX]; | char buf[_Q_PATH_MAX]; |
static char savecwd[_POSIX_PATH_MAX]; |
static char savecwd[_POSIX_PATH_MAX]; |
| |
struct dirent **cat; | struct dirent **cat; |
struct dirent **pf; | struct dirent **pf; |
|
Lines 930-936
queue *get_vdb_atoms(void) {
|
Link Here
|
|---|
|
depend_atom *atom = NULL; | depend_atom *atom = NULL; |
queue *cpf = NULL; | queue *cpf = NULL; |
| |
getcwd(savecwd, sizeof(savecwd)); |
getcwd(savecwd, sizeof(savecwd)); |
| |
assert(chdir(savecwd) == 0); | assert(chdir(savecwd) == 0); |
| |
|
Lines 974-980
queue *get_vdb_atoms(void) {
|
Link Here
|
|---|
|
snprintf(buf, sizeof(buf), "%s/%s-%s", atom->CATEGORY, atom->PN, atom->PV); | snprintf(buf, sizeof(buf), "%s/%s-%s", atom->CATEGORY, atom->PN, atom->PV); |
atom_implode(atom); | atom_implode(atom); |
cpf = add_set(buf, "0", cpf); | cpf = add_set(buf, "0", cpf); |
|
|
} | } |
chdir(".."); | chdir(".."); |
while(dfd--) free(pf[dfd]); | while(dfd--) free(pf[dfd]); |
|
|
return cpf; | return cpf; |
} | } |
| |
|
/* free overlays */ |
|
void free_overlays(overlay_t *overlay); |
|
void free_overlays(overlay_t *overlay) |
|
{ |
|
if ( overlay->next ) |
|
free_overlays(overlay->next); |
|
free(overlay); |
|
} |
|
|
void cleanup() { | void cleanup() { |
reinitialize_as_needed(); | reinitialize_as_needed(); |
free_sets(virtuals); | free_sets(virtuals); |
|
free_overlays(overlay_gentoo); |
fclose(stderr); | fclose(stderr); |
} | } |
| |