aboutsummaryrefslogtreecommitdiffstats
path: root/main/debootstrap
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2012-12-18 06:20:25 -0600
committerWilliam Pitcock <nenolod@dereferenced.org>2012-12-18 06:20:47 -0600
commit5ff3b9694b5ddf23fec62ec57614e705f6d153a7 (patch)
tree55feec28624bb5356b87e5d1e724ca18b63f7a16 /main/debootstrap
parent119185999980a6a6a78506a6b49e1a70ab55ad03 (diff)
downloadaports-5ff3b9694b5ddf23fec62ec57614e705f6d153a7.tar.bz2
aports-5ff3b9694b5ddf23fec62ec57614e705f6d153a7.tar.xz
main/debootstrap: sync pkgdetails.c from bootstrap-base-udeb in debian sid
Diffstat (limited to 'main/debootstrap')
-rw-r--r--main/debootstrap/APKBUILD4
-rw-r--r--main/debootstrap/pkgdetails.c194
2 files changed, 168 insertions, 30 deletions
diff --git a/main/debootstrap/APKBUILD b/main/debootstrap/APKBUILD
index 72cc143bc6..2043eb84b1 100644
--- a/main/debootstrap/APKBUILD
+++ b/main/debootstrap/APKBUILD
@@ -1,7 +1,7 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=debootstrap
pkgver=1.0.44
-pkgrel=0
+pkgrel=1
pkgdesc="Debian/Ubuntu bootstrap scripts"
url="http://packages.qa.debian.org/d/debootstrap.html"
arch="all"
@@ -43,4 +43,4 @@ package() {
install -Dm755 pkgdetails "$pkgdir"/usr/lib/debootstrap/pkgdetails
}
md5sums="73d965abf163b31002f754e3a5322a52 debootstrap_1.0.44.tar.gz
-cff11c88c5176c0ccb714e2d378f4d35 pkgdetails.c"
+66b6fb6d862ba4886701c9b056088479 pkgdetails.c"
diff --git a/main/debootstrap/pkgdetails.c b/main/debootstrap/pkgdetails.c
index 8403afb4c8..99ee1900aa 100644
--- a/main/debootstrap/pkgdetails.c
+++ b/main/debootstrap/pkgdetails.c
@@ -2,10 +2,41 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <stdarg.h>
+#include <errno.h>
#define MAX_LINE 1000
#define MAX_PKGS 100
+char *checksum_field=NULL;
+
+static void oom_die(void)
+{
+ fputs("Out of memory!\n", stderr);
+ exit(1);
+}
+
+static char *xvasprintf(const char *fmt, va_list ap) {
+ char *ret;
+
+ if (vasprintf (&ret, fmt, ap) < 0) {
+ if (errno == ENOMEM)
+ oom_die();
+ return NULL;
+ }
+ return ret;
+}
+
+static char *xasprintf(const char *fmt, ...) {
+ va_list ap;
+ char *ret;
+
+ va_start(ap, fmt);
+ ret = xvasprintf(fmt, ap);
+ va_end(ap);
+ return ret;
+}
+
static char *fieldcpy(char *dst, char *fld) {
while (*fld && *fld != ':')
fld++;
@@ -15,16 +46,36 @@ static char *fieldcpy(char *dst, char *fld) {
return strcpy(dst, fld);
}
+static void outputdeps(char *deps) {
+ char *pch = deps;
+
+ while (1) {
+ while (isspace(*pch)) pch++;
+ if (!*pch) break;
+
+ while (*pch && *pch != '(' && *pch != '|' && *pch != ','
+ && !isspace(*pch))
+ {
+ fputc(*pch++, stdout);
+ }
+ fputc('\n', stdout);
+ while (*pch && *pch++ != ',') (void)NULL;
+ }
+}
+
static void dogetdeps(char *pkgsfile, char **in_pkgs, int pkgc) {
char buf[MAX_LINE];
char cur_pkg[MAX_LINE];
char cur_deps[MAX_LINE];
+ char cur_predeps[MAX_LINE];
+ char prev_pkg[MAX_LINE];
char *pkgs[MAX_PKGS];
int i;
int skip;
FILE *f;
+ int output_pkg = -1;
- cur_pkg[0] = cur_deps[0] = '\0';
+ cur_pkg[0] = cur_deps[0] = cur_predeps[0] = prev_pkg[0] = '\0';
for (i = 0; i < pkgc; i++) pkgs[i] = in_pkgs[i];
@@ -38,40 +89,39 @@ static void dogetdeps(char *pkgsfile, char **in_pkgs, int pkgc) {
while (fgets(buf, sizeof(buf), f)) {
if (*buf && buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
if (strncasecmp(buf, "Package:", 8) == 0) {
+ int any = 0;
skip = 1;
fieldcpy(cur_pkg, buf);
- int any = 0;
+ if (strcmp(cur_pkg, prev_pkg) != 0) {
+ if (output_pkg != -1)
+ pkgs[output_pkg] = NULL;
+ if (cur_deps[0])
+ outputdeps(cur_deps);
+ if (cur_predeps[0])
+ outputdeps(cur_predeps);
+ strcpy(prev_pkg, cur_pkg);
+ }
+ cur_deps[0] = cur_predeps[0] = '\0';
+ output_pkg = -1;
for (i = 0; i < pkgc; i++) {
if (!pkgs[i]) continue;
any = 1;
if (strcmp(cur_pkg, pkgs[i]) == 0) {
skip = 0;
- pkgs[i] = NULL;
+ output_pkg = i;
break;
}
}
if (!any) break;
- } else if (!skip &&
- (strncasecmp(buf, "Depends:", 8) == 0 ||
- strncasecmp(buf, "Pre-Depends:", 12) == 0))
- {
- char *pch;
+ } else if (!skip && strncasecmp(buf, "Depends:", 8) == 0)
fieldcpy(cur_deps, buf);
- pch = cur_deps;
- while (1) {
- while (isspace(*pch)) pch++;
- if (!*pch) break;
-
- while (*pch && *pch != '(' && *pch != '|' && *pch != ','
- && !isspace(*pch))
- {
- fputc(*pch++, stdout);
- }
- fputc('\n', stdout);
- while (*pch && *pch++ != ',') (void)NULL;
- }
- }
+ else if (!skip && strncasecmp(buf, "Pre-Depends:", 12) == 0)
+ fieldcpy(cur_predeps, buf);
}
+ if (cur_deps[0])
+ outputdeps(cur_deps);
+ if (cur_predeps[0])
+ outputdeps(cur_predeps);
fclose(f);
}
@@ -84,13 +134,16 @@ static void dopkgmirrorpkgs(int uniq, char *mirror, char *pkgsfile,
char cur_ver[MAX_LINE];
char cur_arch[MAX_LINE];
char cur_size[MAX_LINE];
- char cur_md5[MAX_LINE];
+ char cur_checksum[MAX_LINE];
char cur_filename[MAX_LINE];
+ char prev_pkg[MAX_LINE];
char *pkgs[MAX_PKGS];
int i;
FILE *f;
+ char *output = NULL;
+ int output_pkg = -1;
- cur_pkg[0] = cur_ver[0] = cur_arch[0] = cur_filename[0] = '\0';
+ cur_field[0] = cur_pkg[0] = cur_ver[0] = cur_arch[0] = cur_filename[0] = prev_pkg[0] = '\0';
for (i = 0; i < pkgc; i++) pkgs[i] = in_pkgs[i];
@@ -106,14 +159,25 @@ static void dopkgmirrorpkgs(int uniq, char *mirror, char *pkgsfile,
}
if (strncasecmp(buf, "Package:", 8) == 0) {
fieldcpy(cur_pkg, buf);
+ if (strcmp(cur_pkg, prev_pkg) != 0) {
+ if (output)
+ fputs(output, stdout);
+ if (uniq && output_pkg != -1)
+ pkgs[output_pkg] = NULL;
+ strcpy(prev_pkg, cur_pkg);
+ }
+ free(output);
+ output = NULL;
+ output_pkg = -1;
} else if (strncasecmp(buf, "Version:", 8) == 0) {
fieldcpy(cur_ver, buf);
} else if (strncasecmp(buf, "Architecture:", 13) == 0) {
fieldcpy(cur_arch, buf);
} else if (strncasecmp(buf, "Size:", 5) == 0) {
fieldcpy(cur_size, buf);
- } else if (strncasecmp(buf, "MD5sum:", 7) == 0) {
- fieldcpy(cur_md5, buf);
+ } else if (strncasecmp(buf, checksum_field, strlen(checksum_field)) == 0
+ && buf[strlen(checksum_field)] == ':') {
+ fieldcpy(cur_checksum, buf);
} else if (strncasecmp(buf, "Filename:", 9) == 0) {
fieldcpy(cur_filename, buf);
} else if (!*buf) {
@@ -122,14 +186,20 @@ static void dopkgmirrorpkgs(int uniq, char *mirror, char *pkgsfile,
if (!pkgs[i]) continue;
any = 1;
if (strcmp(cur_field, pkgs[i]) == 0) {
- printf("%s %s %s %s %s %s %s\n", cur_pkg, cur_ver, cur_arch, mirror, cur_filename, cur_md5, cur_size);
- if (uniq) pkgs[i] = NULL;
+ free(output);
+ output = xasprintf("%s %s %s %s %s %s %s\n", cur_pkg, cur_ver, cur_arch, mirror, cur_filename, cur_checksum, cur_size);
+ output_pkg = i;
break;
}
}
if (!any) break;
+ cur_field[0] = '\0';
}
}
+ if (output)
+ fputs(output, stdout);
+ if (uniq && output_pkg != -1)
+ pkgs[output_pkg] = NULL;
fclose(f);
/* any that weren't found are returned as "pkg -" */
@@ -142,6 +212,61 @@ static void dopkgmirrorpkgs(int uniq, char *mirror, char *pkgsfile,
}
}
+static void dopkgstanzas(char *pkgsfile, char **pkgs, int pkgc)
+{
+ char buf[MAX_LINE];
+ char *accum;
+ size_t accum_size = 0, accum_alloc = MAX_LINE * 2;
+ char cur_pkg[MAX_LINE];
+ FILE *f;
+
+ accum = malloc(accum_alloc);
+ if (!accum)
+ oom_die();
+
+ f = fopen(pkgsfile, "r");
+ if (f == NULL) {
+ perror(pkgsfile);
+ free(accum);
+ exit(1);
+ }
+ while (fgets(buf, sizeof(buf), f)) {
+ if (*buf) {
+ size_t len = strlen(buf);
+ if (accum_size + len + 1 > accum_alloc) {
+ accum_alloc = (accum_size + len + 1) * 2;
+ accum = realloc(accum, accum_alloc);
+ if (!accum)
+ oom_die();
+ }
+ strcpy(accum + accum_size, buf);
+ accum_size += len;
+ }
+ if (*buf && buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
+ if (strncasecmp(buf, "Package:", 8) == 0) {
+ fieldcpy(cur_pkg, buf);
+ } else if (!*buf) {
+ int i;
+ for (i = 0; i < pkgc; i++) {
+ if (!pkgs[i]) continue;
+ if (strcmp(cur_pkg, pkgs[i]) == 0) {
+ fputs(accum, stdout);
+ if (accum[accum_size - 1] != '\n')
+ fputs("\n\n", stdout);
+ else if (accum[accum_size - 2] != '\n')
+ fputc('\n', stdout);
+ break;
+ }
+ }
+ *accum = '\0';
+ accum_size = 0;
+ }
+ }
+ fclose(f);
+
+ free(accum);
+}
+
static int dotranslatewgetpercent(int low, int high, int end, char *str) {
int ch;
int val, lastval;
@@ -169,6 +294,11 @@ static int dotranslatewgetpercent(int low, int high, int end, char *str) {
}
int main(int argc, char *argv[]) {
+ checksum_field=getenv("DEBOOTSTRAP_CHECKSUM_FIELD");
+ if (checksum_field == NULL) {
+ checksum_field="MD5sum";
+ }
+
if ((argc == 6 || argc == 5) && strcmp(argv[1], "WGET%") == 0) {
if (dotranslatewgetpercent(atoi(argv[2]), atoi(argv[3]),
atoi(argv[4]), argc == 6 ? argv[5] : NULL))
@@ -198,11 +328,19 @@ int main(int argc, char *argv[]) {
}
dopkgmirrorpkgs(0, argv[3], argv[4], argv[2], argv+i, argc-i);
exit(0);
+ } else if (argc >= 4 && strcmp(argv[1], "STANZAS") == 0) {
+ int i;
+ for (i = 3; argc - i > MAX_PKGS; i += MAX_PKGS) {
+ dopkgstanzas(argv[2], argv+i, MAX_PKGS);
+ }
+ dopkgstanzas(argv[2], argv+i, argc-i);
+ exit(0);
} else {
fprintf(stderr, "usage: %s PKGS mirror packagesfile pkgs..\n", argv[0]);
fprintf(stderr, " or: %s FIELD field mirror packagesfile pkgs..\n",
argv[0]);
fprintf(stderr, " or: %s GETDEPS packagesfile pkgs..\n", argv[0]);
+ fprintf(stderr, " or: %s STANZAS packagesfile pkgs..\n", argv[0]);
fprintf(stderr, " or: %s WGET%% low high end reason\n", argv[0]);
exit(1);
}