Deleted Added
full compact
pl.c (123602) pl.c (131277)
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 * Routines for dealing with the packing list.
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 * Routines for dealing with the packing list.
18 *
19 */
20
21#include <sys/cdefs.h>
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/create/pl.c 123602 2003-12-17 13:36:05Z nectar $");
22__FBSDID("$FreeBSD: head/usr.sbin/pkg_install/create/pl.c 131277 2004-06-29 18:56:59Z eik $");
23
24#include "lib.h"
25#include "create.h"
26#include <errno.h>
27#include <err.h>
28#include <md5.h>
29
23
24#include "lib.h"
25#include "create.h"
26#include <errno.h>
27#include <err.h>
28#include <md5.h>
29
30/* Add an MD5 checksum entry for a file or link */
31void
32add_cksum(Package *pkg, PackingList p, const char *fname)
33{
34 char *cp = NULL, buf[33];
35
36 if (issymlink(fname)) {
37 int len;
38 char lnk[FILENAME_MAX];
39
40 if ((len = readlink(fname, lnk, FILENAME_MAX)) > 0)
41 cp = MD5Data((unsigned char *)lnk, len, buf);
42 } else if (isfile(fname)) {
43 /* Don't record MD5 checksum for device nodes and such */
44 cp = MD5File(fname, buf);
45 }
46
47 if (cp != NULL) {
48 PackingList tmp = new_plist_entry();
49
50 tmp->name = copy_string(strconcat("MD5:", cp));
51 tmp->type = PLIST_COMMENT;
52 tmp->next = p->next;
53 tmp->prev = p;
54 p->next = tmp;
55 if (pkg->tail == p)
56 pkg->tail = tmp;
57 }
58}
59
30/* Check a list for files that require preconversion */
31void
32check_list(const char *home, Package *pkg)
33{
34 const char *where = home;
35 const char *there = NULL;
60/* Check a list for files that require preconversion */
61void
62check_list(const char *home, Package *pkg)
63{
64 const char *where = home;
65 const char *there = NULL;
36 char *cp, name[FILENAME_MAX], buf[33];
66 char name[FILENAME_MAX];
37 PackingList p;
38
39 for (p = pkg->head; p != NULL; p = p->next)
40 switch (p->type) {
41 case PLIST_CWD:
42 where = p->name;
43 break;
44
45 case PLIST_IGNORE:
46 p = p->next;
47 break;
48
49 case PLIST_SRC:
50 there = p->name;
51 break;
52
53 case PLIST_FILE:
67 PackingList p;
68
69 for (p = pkg->head; p != NULL; p = p->next)
70 switch (p->type) {
71 case PLIST_CWD:
72 where = p->name;
73 break;
74
75 case PLIST_IGNORE:
76 p = p->next;
77 break;
78
79 case PLIST_SRC:
80 there = p->name;
81 break;
82
83 case PLIST_FILE:
54 cp = NULL;
55 sprintf(name, "%s/%s", there ? there : where, p->name);
56 if (issymlink(name)) {
57 int len;
58 char lnk[FILENAME_MAX];
84 if (there)
85 snprintf(name, sizeof(name), "%s/%s", there, p->name);
86 else
87 snprintf(name, sizeof(name), "%s%s/%s",
88 BaseDir && where && where[0] == '/' ? BaseDir : "", where, p->name);
59
89
60 if ((len = readlink(name, lnk, FILENAME_MAX)) > 0)
61 cp = MD5Data((unsigned char *)lnk, len, buf);
62 } else if (isfile(name)) {
63 /* Don't record MD5 checksum for device nodes and such */
64 cp = MD5File(name, buf);
65 }
66
67 if (cp != NULL) {
68 PackingList tmp = new_plist_entry();
69
70 tmp->name = copy_string(strconcat("MD5:", cp));
71 tmp->type = PLIST_COMMENT;
72 tmp->next = p->next;
73 tmp->prev = p;
74 p->next = tmp;
75 if (pkg->tail == p)
76 pkg->tail = tmp;
77 p = tmp;
78 }
90 add_cksum(pkg, p, name);
79 break;
80 default:
81 break;
82 }
83}
84
85static int
86trylink(const char *from, const char *to)

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

212 }
213 /*
214 * Otherwise, try along the actual extraction path..
215 */
216 else {
217 if (p->name[0] == '/')
218 mythere = root;
219 else mythere = there;
91 break;
92 default:
93 break;
94 }
95}
96
97static int
98trylink(const char *from, const char *to)

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

224 }
225 /*
226 * Otherwise, try along the actual extraction path..
227 */
228 else {
229 if (p->name[0] == '/')
230 mythere = root;
231 else mythere = there;
220 sprintf(fn, "%s/%s", mythere ? mythere : where, p->name);
232 if (mythere)
233 snprintf(fn, sizeof(fn), "%s/%s", mythere, p->name);
234 else
235 snprintf(fn, sizeof(fn), "%s%s/%s",
236 BaseDir && where && where[0] == '/' ? BaseDir : "", where, p->name);
221 if (lstat(fn, &stb) == 0 && stb.st_dev == curdir &&
222 S_ISREG(stb.st_mode)) {
223 /*
224 * If we can link it to the playpen, that avoids a copy
225 * and saves time.
226 */
227 if (trylink(fn, p->name) == 0) {
228 p = p->next;

--- 29 unchanged lines hidden ---
237 if (lstat(fn, &stb) == 0 && stb.st_dev == curdir &&
238 S_ISREG(stb.st_mode)) {
239 /*
240 * If we can link it to the playpen, that avoids a copy
241 * and saves time.
242 */
243 if (trylink(fn, p->name) == 0) {
244 p = p->next;

--- 29 unchanged lines hidden ---