2 * Copyright (c) 2019 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * This code uses concepts and configuration based on 'synth', by
8 * John R. Marino <draco@marino.st>, which was written in ada.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
20 * 3. Neither the name of The DragonFly Project nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific, prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 typedef struct pinfo {
45 static int pinfocmp(const void *s1, const void *s2);
46 static void scanit(const char *path, const char *subpath,
47 int *countp, pinfo_t ***list_tailp);
48 pinfo_t *pinfofind(pinfo_t **ary, int count, char *spath);
51 DoRebuildRepo(int ask)
56 if (askyn("Rebuild the repository? ") == 0)
59 asprintf(&buf, "pkg repo -o %s %s", PackagesPath, RepositoryPath);
60 printf("Rebuilding repository\n");
62 printf("Rebuild failed\n");
64 printf("Rebuild succeeded\n");
69 DoUpgradePkgs(pkg_t *pkgs __unused, int ask __unused)
71 dfatal("Not Implemented");
75 PurgeDistfiles(pkg_t *pkgs)
87 printf("Scanning distfiles... ");
92 scanit(DistFilesPath, NULL, &count, &list_tail);
93 printf("Checking %d distfiles\n", count);
96 ary = calloc(count, sizeof(pinfo_t *));
97 for (i = 0; i < count; ++i) {
101 ddassert(list == NULL);
102 qsort(ary, count, sizeof(pinfo_t *), pinfocmp);
104 for (; pkgs; pkgs = pkgs->bnext) {
105 if (pkgs->distfiles == NULL || pkgs->distfiles[0] == 0)
107 ddprintf(0, "distfiles %s\n", pkgs->distfiles);
108 dstr = strtok(pkgs->distfiles, " \t");
111 if (pkgs->distsubdir && pkgs->distsubdir[0]) {
112 asprintf(&buf, "%s/%s",
113 pkgs->distsubdir, dstr);
114 item = pinfofind(ary, count, buf);
115 ddprintf(0, "TEST %s %p\n", buf, item);
119 item = pinfofind(ary, count, dstr);
120 ddprintf(0, "TEST %s %p\n", dstr, item);
126 if (strrchr(dstr, ':') == NULL)
128 *strrchr(dstr, ':') = 0;
130 dstr = strtok(NULL, " \t");
135 for (i = 0; i < count; ++i) {
137 if (item->foundit == 0) {
141 if (askyn("Delete %d of %d items? ", delcount, count)) {
142 printf("Deleting %d/%d obsolete source distfiles\n",
144 for (i = 0; i < count; ++i) {
146 if (item->foundit == 0) {
147 asprintf(&buf, "%s/%s",
148 DistFilesPath, item->spath);
150 printf("Cannot delete %s\n", buf);
161 RemovePackages(pkg_t *pkgs __unused)
163 dfatal("Not Implemented");
167 pinfocmp(const void *s1, const void *s2)
169 const pinfo_t *item1 = *(const pinfo_t *const*)s1;
170 const pinfo_t *item2 = *(const pinfo_t *const*)s2;
172 return (strcmp(item1->spath, item2->spath));
176 pinfofind(pinfo_t **ary, int count, char *spath)
189 res = strcmp(spath, item->spath);
202 scanit(const char *path, const char *subpath,
203 int *countp, pinfo_t ***list_tailp)
212 if ((dir = opendir(path)) != NULL) {
213 while ((den = readdir(dir)) != NULL) {
214 if (den->d_namlen == 1 && den->d_name[0] == '.')
216 if (den->d_namlen == 2 && den->d_name[0] == '.' &&
217 den->d_name[1] == '.')
219 asprintf(&npath, "%s/%s", path, den->d_name);
220 if (lstat(npath, &st) < 0) {
224 if (S_ISDIR(st.st_mode)) {
226 asprintf(&spath, "%s/%s",
227 subpath, den->d_name);
232 scanit(npath, den->d_name,
236 } else if (S_ISREG(st.st_mode)) {
237 item = calloc(1, sizeof(*item));
239 asprintf(&item->spath, "%s/%s",
240 subpath, den->d_name);
242 item->spath = strdup(den->d_name);
245 *list_tailp = &item->next;
247 ddprintf(0, "scan %s\n", item->spath);