extract.c (93520) | extract.c (96388) |
---|---|
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 93520 2002-04-01 09:39:07Z obrien $"); | 22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/add/extract.c 96388 2002-05-11 03:48:49Z 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); \ | 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, __FUNCTION__ ": can not invoke %ld byte tar pipeline: %s", \ | 39 errx(2, \ 40 "%s: can not invoke %ld byte tar pipeline: %s", \ 41 __FUNCTION__, \ |
40 (long)strlen(where_args), where_args); \ 41 } \ 42 strcpy(where_args, STARTSTRING); \ 43 where_count = sizeof(STARTSTRING)-1; \ 44 } \ 45 if (perm_count) { \ 46 apply_perms(todir, perm_args); \ 47 perm_args[0] = 0;\ --- 35 unchanged lines hidden (view full) --- 83 char *where_args, *perm_args, *last_chdir; 84 int maxargs, where_count = 0, perm_count = 0, add_count; 85 Boolean preserve; 86 87 maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */ 88 where_args = alloca(maxargs); 89 if (!where_args) { 90 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); |
91 errx(2, __FUNCTION__ ": can't get argument list space"); | 93 errx(2, "%s: can't get argument list space", __FUNCTION__); |
92 } 93 perm_args = alloca(maxargs); 94 if (!perm_args) { 95 cleanup(0); | 94 } 95 perm_args = alloca(maxargs); 96 if (!perm_args) { 97 cleanup(0); |
96 errx(2, __FUNCTION__ ": can't get argument list space"); | 98 errx(2, "%s: can't get argument list space", __FUNCTION__); |
97 } 98 99 strcpy(where_args, STARTSTRING); 100 where_count = sizeof(STARTSTRING)-1; 101 perm_args[0] = 0; 102 103 last_chdir = 0; 104 preserve = find_plist_option(pkg, "preserve") ? TRUE : FALSE; --- 20 unchanged lines hidden (view full) --- 125 last_file = p->name; 126 if (Verbose) 127 printf("extract: %s/%s\n", Directory, p->name); 128 if (!Fake) { 129 char try[FILENAME_MAX]; 130 131 if (strrchr(p->name,'\'')) { 132 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); |
133 errx(2, __FUNCTION__ ": Bogus filename \"%s\"", p->name); | 135 errx(2, "%s: Bogus filename \"%s\"", __FUNCTION__, p->name); |
134 } 135 136 /* first try to rename it into place */ 137 snprintf(try, FILENAME_MAX, "%s/%s", Directory, p->name); 138 if (fexists(try)) { 139 (void)chflags(try, 0); /* XXX hack - if truly immutable, rename fails */ 140 if (preserve && PkgName) { 141 char pf[FILENAME_MAX]; --- 12 unchanged lines hidden (view full) --- 154 if (rename(p->name, try) == 0) { 155 /* try to add to list of perms to be changed and run in bulk. */ 156 if (p->name[0] == '/' || TOOBIG(p->name)) { 157 PUSHOUT(Directory); 158 } 159 add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name); 160 if (add_count < 0 || add_count > maxargs - perm_count) { 161 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); |
162 errx(2, __FUNCTION__ ": oops, miscounted strings!"); | 164 errx(2, "%s: oops, miscounted strings!", __FUNCTION__); |
163 } 164 perm_count += add_count; 165 } 166 else { 167 /* rename failed, try copying with a big tar command */ 168 if (last_chdir != Directory) { 169 if (last_chdir == NULL) { 170 PUSHOUT(Directory); 171 } else { 172 PUSHOUT(last_chdir); 173 } 174 last_chdir = Directory; 175 } 176 else if (p->name[0] == '/' || TOOBIG(p->name)) { 177 PUSHOUT(Directory); 178 } 179 add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name); 180 if (add_count < 0 || add_count > maxargs - where_count) { 181 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); |
182 errx(2, __FUNCTION__ ": oops, miscounted strings!"); | 184 errx(2, "%s: oops, miscounted strings!", __FUNCTION__); |
183 } 184 where_count += add_count; 185 add_count = snprintf(&perm_args[perm_count], 186 maxargs - perm_count, 187 "'%s' ", p->name); 188 if (add_count < 0 || add_count > maxargs - perm_count) { 189 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); |
190 errx(2, __FUNCTION__ ": oops, miscounted strings!"); | 192 errx(2, "%s: oops, miscounted strings!", __FUNCTION__); |
191 } 192 perm_count += add_count; 193 } 194 } 195 break; 196 197 case PLIST_CWD: 198 if (Verbose) 199 printf("extract: CWD to %s\n", p->name); 200 PUSHOUT(Directory); 201 if (strcmp(p->name, ".")) { 202 if (!Fake && make_hierarchy(p->name) == FAIL) { 203 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); |
204 errx(2, __FUNCTION__ ": unable to cwd to '%s'", p->name); | 206 errx(2, "%s: unable to cwd to '%s'", __FUNCTION__, p->name); |
205 } 206 Directory = p->name; 207 } 208 else 209 (const char *)Directory = home; 210 break; 211 212 case PLIST_CMD: 213 if ((strstr(p->name, "%B") || strstr(p->name, "%F") || 214 strstr(p->name, "%f")) && last_file == NULL) { 215 cleanup(0); | 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); |
216 errx(2, __FUNCTION__ ": no last file specified for '%s' command", p->name); | 218 errx(2, "%s: no last file specified for '%s' command", 219 __FUNCTION__, p->name); |
217 } 218 if (strstr(p->name, "%D") && Directory == NULL) { 219 cleanup(0); | 220 } 221 if (strstr(p->name, "%D") && Directory == NULL) { 222 cleanup(0); |
220 errx(2, __FUNCTION__ ": no directory specified for '%s' command", p->name); | 223 errx(2, "%s: no directory specified for '%s' command", 224 __FUNCTION__, p->name); |
221 } 222 format_cmd(cmd, p->name, Directory, last_file); 223 PUSHOUT(Directory); 224 if (Verbose) 225 printf("extract: execute '%s'\n", cmd); 226 if (!Fake && system(cmd)) 227 warnx("command '%s' failed", cmd); 228 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 --- |