1 /* $NetBSD: pl.c,v 1.1.1.4 2009/11/05 18:39:03 joerg Exp $ */
10 __RCSID("$NetBSD: pl.c,v 1.1.1.4 2009/11/05 18:39:03 joerg Exp $");
13 * FreeBSD install - a package for the installation and maintainance
14 * of non-core utilities.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
28 * Routines for dealing with the packing list.
38 #include <nbcompat/md5.h>
44 * Check that any symbolic link is relative to the prefix
47 CheckSymlink(char *name
, char *prefix
, size_t prefixcc
)
49 char newtgt
[MaxPathSize
];
50 char oldtgt
[MaxPathSize
];
56 if ((cc
= readlink(name
, oldtgt
, sizeof(oldtgt
) - 1)) > 0) {
58 if (strncmp(oldtgt
, prefix
, prefixcc
) == 0 && oldtgt
[prefixcc
] == '/') {
59 for (slashc
= 0, slash
= &name
[prefixcc
+ 1]; (slash
= strchr(slash
, '/')) != (char *) NULL
; slash
++, slashc
++) {
61 for (cc
= i
= 0; i
< slashc
; i
++) {
62 strlcpy(&newtgt
[cc
], "../", sizeof(newtgt
) - cc
);
65 strlcpy(&newtgt
[cc
], &oldtgt
[prefixcc
+ 1], sizeof(newtgt
) - cc
);
66 (void) fprintf(stderr
, "Full pathname symlink `%s' is target of `%s' - adjusting to `%s'\n", oldtgt
, name
, newtgt
);
67 if (unlink(name
) != 0) {
68 warn("can't unlink `%s'", name
);
69 } else if (symlink(newtgt
, name
) != 0) {
70 warn("can't symlink `%s' called `%s'", newtgt
, name
);
77 * Check a list for files that require preconversion
80 check_list(package_t
*pkg
, const char *PkgName
)
85 char buf
[ChecksumHeaderLen
+ LegibleChecksumLen
];
86 char target
[MaxPathSize
+ SymlinkHeaderLen
];
87 char name
[MaxPathSize
];
92 /* Open Package Database for writing */
93 if (update_pkgdb
&& !pkgdb_open(ReadWrite
))
94 err(EXIT_FAILURE
, "can't open pkgdb");
96 for (p
= pkg
->head
; p
; p
= p
->next
) {
109 errx(2, "@pkgdir without preceding @cwd found");
111 errx(2, "@pkgdir without preceding @name found");
113 add_pkgdir(pkgname
, cwd
, p
->name
);
114 /* mkdir_p(cwd, p->name); */
119 * pkgdb handling - usually, we enter files
120 * into the pkgdb as soon as they hit the disk,
121 * but as they are present before pkg_create
122 * starts, it's ok to do this somewhere here
125 errx(2, "file without preceding @cwd found");
127 char *s
, t
[MaxPathSize
];
129 (void) snprintf(t
, sizeof(t
), "%s%s%s",
131 (strcmp(cwd
, "/") == 0) ? "" : "/",
134 s
= pkgdb_retrieve(t
);
136 warnx("Overwriting %s - "
137 "pkg %s bogus/conflicting?", t
, s
);
139 pkgdb_store(t
, PkgName
);
143 /* prepend DESTDIR if set? - HF */
144 (void) snprintf(name
, sizeof(name
), "%s%s%s",
146 (strcmp(cwd
, "/") == 0) ? "" : "/",
148 if (lstat(name
, &st
) < 0) {
149 warnx("can't stat `%s'", name
);
152 switch (st
.st_mode
& S_IFMT
) {
154 warnx("Warning - directory `%s' in PLIST", name
);
158 CheckSymlink(name
, cwd
, strlen(cwd
));
160 (void) strlcpy(target
, SYMLINK_HEADER
,
162 if ((cc
= readlink(name
, &target
[SymlinkHeaderLen
],
163 sizeof(target
) - SymlinkHeaderLen
- 1)) < 0) {
164 warnx("can't readlink `%s'", name
);
167 target
[SymlinkHeaderLen
+ cc
] = 0x0;
168 tmp
= new_plist_entry();
169 tmp
->name
= xstrdup(target
);
170 tmp
->type
= PLIST_COMMENT
;
173 if (p
== pkg
->tail
) {
180 warnx("Warning - char special device `%s' in PLIST", name
);
183 warnx("Warning - block special device `%s' in PLIST", name
);
186 (void) strlcpy(buf
, CHECKSUM_HEADER
,
188 if (MD5File(name
, &buf
[ChecksumHeaderLen
]) != (char *) NULL
) {
189 tmp
= new_plist_entry();
190 tmp
->name
= xstrdup(buf
);
191 tmp
->type
= PLIST_COMMENT
; /* PLIST_MD5 - HF */
194 if (p
== pkg
->tail
) {