Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Thu, 26 Sep 2019 19:29:02
Message-Id: 1569526015.9d36886cbbececda954d7de41a59bf1e8733ed1c.grobian@gentoo
1 commit: 9d36886cbbececda954d7de41a59bf1e8733ed1c
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Thu Sep 26 19:26:55 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Thu Sep 26 19:26:55 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=9d36886c
7
8 qpkg: drop weird location choice for binpkgs
9
10 If someone wants to put packages in /var/tmp or $HOME, then -P should be
11 used. Ignoring portage-config pkgdir is odd, if one can't write there,
12 -P is there to the rescue.
13
14 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
15
16 qpkg.c | 61 ++++++++++++++++++++++++-------------------------------------
17 1 file changed, 24 insertions(+), 37 deletions(-)
18
19 diff --git a/qpkg.c b/qpkg.c
20 index 29265f2..85e0940 100644
21 --- a/qpkg.c
22 +++ b/qpkg.c
23 @@ -173,27 +173,13 @@ qpkg_clean(char *dirp)
24 if ((num_all_bytes / KILOBYTE) > 1000)
25 disp_units = MEGABYTE;
26 qprintf(" %s*%s Total space that would be freed in packages "
27 - "directory: %s%s %c%s\n", GREEN, NORM, RED,
28 + "directory: %s%s %ciB%s\n", GREEN, NORM, RED,
29 make_human_readable_str(num_all_bytes, 1, disp_units),
30 disp_units == MEGABYTE ? 'M' : 'K', NORM);
31
32 return 0;
33 }
34
35 -static const char *
36 -qpkg_get_bindir(void)
37 -{
38 - if (qpkg_bindir != NULL)
39 - return qpkg_bindir;
40 - if (getuid() == 0)
41 - return "/var/tmp/binpkgs";
42 - if (getenv("HOME") == NULL)
43 - errp("Your $HOME env var isn't set, aborting");
44 - xasprintf(&qpkg_bindir, "%s/binpkgs", getenv("HOME"));
45 -
46 - return qpkg_bindir;
47 -}
48 -
49 static int
50 check_pkg_install_mask(char *name)
51 {
52 @@ -246,7 +232,7 @@ qpkg_make(depend_atom *atom)
53 return -1;
54 }
55
56 - snprintf(tmpdir, sizeof(tmpdir), "%s/qpkg.XXXXXX", qpkg_get_bindir());
57 + snprintf(tmpdir, sizeof(tmpdir), "%s/qpkg.XXXXXX", qpkg_bindir);
58 if ((i = mkstemp(tmpdir)) == -1) {
59 free(buf);
60 return -2;
61 @@ -308,7 +294,7 @@ qpkg_make(depend_atom *atom)
62
63 unlink(filelist);
64
65 - snprintf(buf, buflen, "%s/%s.tbz2", qpkg_get_bindir(), atom_to_pvr(atom));
66 + snprintf(buf, buflen, "%s/%s.tbz2", qpkg_bindir, atom_to_pvr(atom));
67 if (rename(tbz2, buf)) {
68 warnp("could not move '%s' to '%s'", tbz2, buf);
69 free(buf);
70 @@ -318,7 +304,7 @@ qpkg_make(depend_atom *atom)
71 rmdir(tmpdir);
72
73 stat(buf, &st);
74 - printf("%s%s%s kB\n",
75 + printf("%s%s%s KiB\n",
76 RED, make_human_readable_str(st.st_size, 1, KILOBYTE), NORM);
77
78 free(buf);
79 @@ -334,11 +320,11 @@ int qpkg_main(int argc, char **argv)
80 int i;
81 struct stat st;
82 char buf[BUFSIZE];
83 - const char *bindir;
84 depend_atom *atom;
85 int restrict_chmod = 0;
86 int qclean = 0;
87
88 + qpkg_bindir = pkgdir;
89 while ((i = GETOPT_LONG(QPKG, qpkg, "")) != -1) {
90 switch (i) {
91 case 'E': eclean = qclean = 1; break;
92 @@ -346,8 +332,7 @@ int qpkg_main(int argc, char **argv)
93 case 'p': pretend = 1; break;
94 case 'P':
95 restrict_chmod = 1;
96 - free(qpkg_bindir);
97 - qpkg_bindir = xstrdup(optarg);
98 + qpkg_bindir = optarg;
99 if (access(qpkg_bindir, W_OK) != 0)
100 errp("%s", qpkg_bindir);
101 break;
102 @@ -355,28 +340,29 @@ int qpkg_main(int argc, char **argv)
103 }
104 }
105 if (qclean)
106 - return qpkg_clean(qpkg_bindir == NULL ? pkgdir : qpkg_bindir);
107 + return qpkg_clean(qpkg_bindir);
108
109 if (argc == optind)
110 qpkg_usage(EXIT_FAILURE);
111
112 /* setup temp dirs */
113 - i = 0;
114 - bindir = qpkg_get_bindir();
115 - if (*bindir != '/')
116 - err("'%s' is not a valid package destination", bindir);
117 -retry_mkdir:
118 - if (mkdir(bindir, 0750) == -1) {
119 - lstat(bindir, &st);
120 - if (!S_ISDIR(st.st_mode)) {
121 - unlink(bindir);
122 - if (!i++) goto retry_mkdir;
123 - errp("could not create temp bindir '%s'", bindir);
124 + if (qpkg_bindir[0] != '/')
125 + err("'%s' is not a valid package destination", qpkg_bindir);
126 + for (i = 0; i <= 1; i++) {
127 + if (mkdir(qpkg_bindir, 0750) == -1) {
128 + lstat(qpkg_bindir, &st);
129 + if (!S_ISDIR(st.st_mode)) {
130 + unlink(qpkg_bindir);
131 + continue;
132 + }
133 + if (!restrict_chmod)
134 + if (chmod(qpkg_bindir, 0750))
135 + errp("could not chmod(0750) temp bindir '%s'", qpkg_bindir);
136 }
137 - if (!restrict_chmod)
138 - if (chmod(bindir, 0750))
139 - errp("could not chmod(0750) temp bindir '%s'", bindir);
140 + break;
141 }
142 + if (i == 2)
143 + errp("could not create temp bindir '%s'", qpkg_bindir);
144
145 /* we have to change to the root so that we can feed the full paths
146 * to tar when we create the binary package. */
147 @@ -440,7 +426,8 @@ retry_mkdir:
148 printf(" %s*%s %i package%s could not be matched :/\n",
149 RED, NORM, (int)s, (s > 1 ? "s" : ""));
150 if (pkgs_made)
151 - qprintf(" %s*%s Packages can be found in %s\n", GREEN, NORM, bindir);
152 + qprintf(" %s*%s Packages can be found in %s\n",
153 + GREEN, NORM, qpkg_bindir);
154
155 return (pkgs_made ? EXIT_SUCCESS : EXIT_FAILURE);
156 }