Deleted Added
full compact
extract.c (96388) extract.c (96392)
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 5 unchanged lines hidden (view full) ---

14 * Jordan K. Hubbard
15 * 18 July 1993
16 *
17 * This is the package extraction code for the add module.
18 *
19 */
20
21#include <sys/cdefs.h>
1/*
2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 5 unchanged lines hidden (view full) ---

14 * Jordan K. Hubbard
15 * 18 July 1993
16 *
17 * This is the package extraction code for the add module.
18 *
19 */
20
21#include <sys/cdefs.h>
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/add/extract.c 96388 2002-05-11 03:48:49Z alfred $");
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/add/extract.c 96392 2002-05-11 04:17:55Z alfred $");
23
24#include <err.h>
25#include "lib.h"
26#include "add.h"
27
28
29#define STARTSTRING "tar cf - "
30#define TOOBIG(str) (((int)strlen(str) + FILENAME_MAX + where_count > maxargs) \
31 || ((int)strlen(str) + FILENAME_MAX + perm_count > maxargs))
32
33#define PUSHOUT(todir) /* push out string */ \
34 if (where_count > (int)sizeof(STARTSTRING)-1) { \
35 strcat(where_args, "|tar --unlink -xf - -C "); \
36 strcat(where_args, todir); \
37 if (system(where_args)) { \
38 cleanup(0); \
39 errx(2, \
40 "%s: can not invoke %ld byte tar pipeline: %s", \
23
24#include <err.h>
25#include "lib.h"
26#include "add.h"
27
28
29#define STARTSTRING "tar cf - "
30#define TOOBIG(str) (((int)strlen(str) + FILENAME_MAX + where_count > maxargs) \
31 || ((int)strlen(str) + FILENAME_MAX + perm_count > maxargs))
32
33#define PUSHOUT(todir) /* push out string */ \
34 if (where_count > (int)sizeof(STARTSTRING)-1) { \
35 strcat(where_args, "|tar --unlink -xf - -C "); \
36 strcat(where_args, todir); \
37 if (system(where_args)) { \
38 cleanup(0); \
39 errx(2, \
40 "%s: can not invoke %ld byte tar pipeline: %s", \
41 __FUNCTION__, \
41 __func__, \
42 (long)strlen(where_args), where_args); \
43 } \
44 strcpy(where_args, STARTSTRING); \
45 where_count = sizeof(STARTSTRING)-1; \
46 } \
47 if (perm_count) { \
48 apply_perms(todir, perm_args); \
49 perm_args[0] = 0;\

--- 35 unchanged lines hidden (view full) ---

85 char *where_args, *perm_args, *last_chdir;
86 int maxargs, where_count = 0, perm_count = 0, add_count;
87 Boolean preserve;
88
89 maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */
90 where_args = alloca(maxargs);
91 if (!where_args) {
92 cleanup(0);
42 (long)strlen(where_args), where_args); \
43 } \
44 strcpy(where_args, STARTSTRING); \
45 where_count = sizeof(STARTSTRING)-1; \
46 } \
47 if (perm_count) { \
48 apply_perms(todir, perm_args); \
49 perm_args[0] = 0;\

--- 35 unchanged lines hidden (view full) ---

85 char *where_args, *perm_args, *last_chdir;
86 int maxargs, where_count = 0, perm_count = 0, add_count;
87 Boolean preserve;
88
89 maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */
90 where_args = alloca(maxargs);
91 if (!where_args) {
92 cleanup(0);
93 errx(2, "%s: can't get argument list space", __FUNCTION__);
93 errx(2, "%s: can't get argument list space", __func__);
94 }
95 perm_args = alloca(maxargs);
96 if (!perm_args) {
97 cleanup(0);
94 }
95 perm_args = alloca(maxargs);
96 if (!perm_args) {
97 cleanup(0);
98 errx(2, "%s: can't get argument list space", __FUNCTION__);
98 errx(2, "%s: can't get argument list space", __func__);
99 }
100
101 strcpy(where_args, STARTSTRING);
102 where_count = sizeof(STARTSTRING)-1;
103 perm_args[0] = 0;
104
105 last_chdir = 0;
106 preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;

--- 20 unchanged lines hidden (view full) ---

127 last_file = p->name;
128 if (Verbose)
129 printf("extract: %s/%s\n", Directory, p->name);
130 if (!Fake) {
131 char try[FILENAME_MAX];
132
133 if (strrchr(p->name,'\'')) {
134 cleanup(0);
99 }
100
101 strcpy(where_args, STARTSTRING);
102 where_count = sizeof(STARTSTRING)-1;
103 perm_args[0] = 0;
104
105 last_chdir = 0;
106 preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE;

--- 20 unchanged lines hidden (view full) ---

127 last_file = p->name;
128 if (Verbose)
129 printf("extract: %s/%s\n", Directory, p->name);
130 if (!Fake) {
131 char try[FILENAME_MAX];
132
133 if (strrchr(p->name,'\'')) {
134 cleanup(0);
135 errx(2, "%s: Bogus filename \"%s\"", __FUNCTION__, p->name);
135 errx(2, "%s: Bogus filename \"%s\"", __func__, p->name);
136 }
137
138 /* first try to rename it into place */
139 snprintf(try, FILENAME_MAX, "%s/%s", Directory, p->name);
140 if (fexists(try)) {
141 (void)chflags(try, 0); /* XXX hack - if truly immutable, rename fails */
142 if (preserve && PkgName) {
143 char pf[FILENAME_MAX];

--- 12 unchanged lines hidden (view full) ---

156 if (rename(p->name, try) == 0) {
157 /* try to add to list of perms to be changed and run in bulk. */
158 if (p->name[0] == '/' || TOOBIG(p->name)) {
159 PUSHOUT(Directory);
160 }
161 add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
162 if (add_count < 0 || add_count > maxargs - perm_count) {
163 cleanup(0);
136 }
137
138 /* first try to rename it into place */
139 snprintf(try, FILENAME_MAX, "%s/%s", Directory, p->name);
140 if (fexists(try)) {
141 (void)chflags(try, 0); /* XXX hack - if truly immutable, rename fails */
142 if (preserve && PkgName) {
143 char pf[FILENAME_MAX];

--- 12 unchanged lines hidden (view full) ---

156 if (rename(p->name, try) == 0) {
157 /* try to add to list of perms to be changed and run in bulk. */
158 if (p->name[0] == '/' || TOOBIG(p->name)) {
159 PUSHOUT(Directory);
160 }
161 add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
162 if (add_count < 0 || add_count > maxargs - perm_count) {
163 cleanup(0);
164 errx(2, "%s: oops, miscounted strings!", __FUNCTION__);
164 errx(2, "%s: oops, miscounted strings!", __func__);
165 }
166 perm_count += add_count;
167 }
168 else {
169 /* rename failed, try copying with a big tar command */
170 if (last_chdir != Directory) {
171 if (last_chdir == NULL) {
172 PUSHOUT(Directory);
173 } else {
174 PUSHOUT(last_chdir);
175 }
176 last_chdir = Directory;
177 }
178 else if (p->name[0] == '/' || TOOBIG(p->name)) {
179 PUSHOUT(Directory);
180 }
181 add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
182 if (add_count < 0 || add_count > maxargs - where_count) {
183 cleanup(0);
165 }
166 perm_count += add_count;
167 }
168 else {
169 /* rename failed, try copying with a big tar command */
170 if (last_chdir != Directory) {
171 if (last_chdir == NULL) {
172 PUSHOUT(Directory);
173 } else {
174 PUSHOUT(last_chdir);
175 }
176 last_chdir = Directory;
177 }
178 else if (p->name[0] == '/' || TOOBIG(p->name)) {
179 PUSHOUT(Directory);
180 }
181 add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
182 if (add_count < 0 || add_count > maxargs - where_count) {
183 cleanup(0);
184 errx(2, "%s: oops, miscounted strings!", __FUNCTION__);
184 errx(2, "%s: oops, miscounted strings!", __func__);
185 }
186 where_count += add_count;
187 add_count = snprintf(&perm_args[perm_count],
188 maxargs - perm_count,
189 "'%s' ", p->name);
190 if (add_count < 0 || add_count > maxargs - perm_count) {
191 cleanup(0);
185 }
186 where_count += add_count;
187 add_count = snprintf(&perm_args[perm_count],
188 maxargs - perm_count,
189 "'%s' ", p->name);
190 if (add_count < 0 || add_count > maxargs - perm_count) {
191 cleanup(0);
192 errx(2, "%s: oops, miscounted strings!", __FUNCTION__);
192 errx(2, "%s: oops, miscounted strings!", __func__);
193 }
194 perm_count += add_count;
195 }
196 }
197 break;
198
199 case PLIST_CWD:
200 if (Verbose)
201 printf("extract: CWD to %s\n", p->name);
202 PUSHOUT(Directory);
203 if (strcmp(p->name, ".")) {
204 if (!Fake && make_hierarchy(p->name) == FAIL) {
205 cleanup(0);
193 }
194 perm_count += add_count;
195 }
196 }
197 break;
198
199 case PLIST_CWD:
200 if (Verbose)
201 printf("extract: CWD to %s\n", p->name);
202 PUSHOUT(Directory);
203 if (strcmp(p->name, ".")) {
204 if (!Fake && make_hierarchy(p->name) == FAIL) {
205 cleanup(0);
206 errx(2, "%s: unable to cwd to '%s'", __FUNCTION__, p->name);
206 errx(2, "%s: unable to cwd to '%s'", __func__, p->name);
207 }
208 Directory = p->name;
209 }
210 else
211 (const char *)Directory = home;
212 break;
213
214 case PLIST_CMD:
215 if ((strstr(p->name, "%B") || strstr(p->name, "%F") ||
216 strstr(p->name, "%f")) && last_file == NULL) {
217 cleanup(0);
218 errx(2, "%s: no last file specified for '%s' command",
207 }
208 Directory = p->name;
209 }
210 else
211 (const char *)Directory = home;
212 break;
213
214 case PLIST_CMD:
215 if ((strstr(p->name, "%B") || strstr(p->name, "%F") ||
216 strstr(p->name, "%f")) && last_file == NULL) {
217 cleanup(0);
218 errx(2, "%s: no last file specified for '%s' command",
219 __FUNCTION__, p->name);
219 __func__, p->name);
220 }
221 if (strstr(p->name, "%D") && Directory == NULL) {
222 cleanup(0);
223 errx(2, "%s: no directory specified for '%s' command",
220 }
221 if (strstr(p->name, "%D") && Directory == NULL) {
222 cleanup(0);
223 errx(2, "%s: no directory specified for '%s' command",
224 __FUNCTION__, p->name);
224 __func__, p->name);
225 }
226 format_cmd(cmd, p->name, Directory, last_file);
227 PUSHOUT(Directory);
228 if (Verbose)
229 printf("extract: execute '%s'\n", cmd);
230 if (!Fake && system(cmd))
231 warnx("command '%s' failed", cmd);
232 break;

--- 30 unchanged lines hidden ---
225 }
226 format_cmd(cmd, p->name, Directory, last_file);
227 PUSHOUT(Directory);
228 if (Verbose)
229 printf("extract: execute '%s'\n", cmd);
230 if (!Fake && system(cmd))
231 warnx("command '%s' failed", cmd);
232 break;

--- 30 unchanged lines hidden ---