From owner-p4-projects@FreeBSD.ORG Wed Aug 11 18:25:56 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id CBE611065B2E; Wed, 11 Aug 2010 18:25:55 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BD21D1065881 for ; Wed, 11 Aug 2010 18:25:52 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id A0B648FC1F for ; Wed, 11 Aug 2010 18:25:52 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id o7BIPq8G083837 for ; Wed, 11 Aug 2010 18:25:52 GMT (envelope-from ivoras@FreeBSD.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id o7BIPqT5083833 for perforce@freebsd.org; Wed, 11 Aug 2010 18:25:52 GMT (envelope-from ivoras@FreeBSD.org) Date: Wed, 11 Aug 2010 18:25:52 GMT Message-Id: <201008111825.o7BIPqT5083833@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to ivoras@FreeBSD.org using -f From: Ivan Voras To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 182118 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2010 18:25:56 -0000 http://p4web.freebsd.org/@@182118?ac=10 Change 182118 by ivoras@ursaminor on 2010/08/09 01:20:17 Better handling of symlinks, better style(9) compliance. Affected files ... .. //depot/projects/soc2010/pkg_patch/src/patch/Makefile#32 edit .. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#22 edit .. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#22 edit .. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#31 edit .. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#31 edit .. //depot/projects/soc2010/pkg_patch/src/patch/main.c#32 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#30 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#30 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.c#15 edit .. //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.h#14 edit .. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#30 edit .. //depot/projects/soc2010/pkg_patch/src/patch/support.c#29 edit .. //depot/projects/soc2010/pkg_patch/src/patch/updateweb.c#10 edit .. //depot/projects/soc2010/pkg_patch/src/patch/updateweb.h#10 edit Differences ... ==== //depot/projects/soc2010/pkg_patch/src/patch/Makefile#32 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#22 (text+ko) ==== @@ -49,7 +49,7 @@ return (-1); } if (access(PKGPATCH_BACKUP_DIR, F_OK) != 0) { - if (mkdir(PKGPATCH_BACKUP_DIR, 0644) != 0) { + if (mkdir(PKGPATCH_BACKUP_DIR, 0730) != 0) { warnx("Cannot mkdir: %s", PKGPATCH_BACKUP_DIR); return (-1); } @@ -429,19 +429,19 @@ warnx("Cannot resolve %s on a live pkg", pl->filename); } snprintf(newfile, PATH_MAX, "%s%s", tmp, pext); - if (pl->method == PPMETHOD_CP) + if (pl->method == PPMETHOD_CP || pl->method == PPMETHOD_LN) snprintf(patchfile, PATH_MAX, "%s/%s", dpatch, pl->filename); else if (pl->method == PPMETHOD_BSDIFF) - snprintf(patchfile, PATH_MAX, "%s/%s.bsdiff", dpatch, - pl->filename); + snprintf(patchfile, PATH_MAX, "%s/%s.%s", dpatch, + pl->filename, BSDIFF_EXT); else errx(1, "Unknown patch method: %d", (int)(pl->method)); if (Verbose > 2) - printf("Raw patching %s to %s using %s\n", tmp, newfile, + printf("Patching %s to %s using %s\n", tmp, newfile, patchfile); if (pl->method == PPMETHOD_BSDIFF) { - char cmd[3*PATH_MAX]; + char cmd[3 * PATH_MAX]; snprintf(cmd, sizeof(cmd), "%s \"%s\" \"%s\" \"%s\"", _PATH_BSPATCH, tmp, newfile, patchfile); @@ -449,9 +449,15 @@ if (fpvect[n_patched_files] == NULL) err(1, "Cannot popen: %s", cmd); n_patched_files++; - } else - if (cp(tmp, newfile) != 0) - err(1, "Cannot copy %s to %s", tmp, newfile); + } else if (pl->method == PPMETHOD_LN) { + if (copy_file_absolute(patchfile, newfile) != 0) + err(1, "Cannot symlink %s to %s", patchfile, + newfile); + } else { + if (cp(patchfile, newfile) != 0) + err(1, "Cannot copy %s to %s", patchfile, + newfile); + } } for (i = 0; i < n_patched_files; i++) if (pclose(fpvect[i]) != 0) @@ -475,12 +481,22 @@ break; } strncat(newfile, pext, PATH_MAX); + if (issymlink(newfile)) + /* Symlinks are relative and point to wrong files at this point */ + continue; if (MD5File(newfile, live_md5) == NULL) err(1, "Cannot MD5 file: %s", newfile); - if (strncmp(live_md5, target_md5, sizeof(live_md5)) != 0) - errx(1, "MD5 mismatch for %s: expected %s, got %s", - pl->filename, target_md5, live_md5); - snprintf(tmp, PATH_MAX, "%s/%s", dpatch, pl->filename); + if (strncmp(live_md5, target_md5, sizeof(live_md5)) != 0) { + warnx("MD5 mismatch for %s: expected %s, got %s", + newfile, target_md5, live_md5); + abort(); + goto error_cleanup; + } + if (pl->method == PPMETHOD_BSDIFF) + snprintf(tmp, PATH_MAX, "%s/%s.%s", dpatch, + pl->filename, BSDIFF_EXT); + else + snprintf(tmp, PATH_MAX, "%s/%s", dpatch, pl->filename); if (copy_file_attrs(tmp, NULL, newfile) != 0) { warn("Cannot copy file attributes from %s to %s", tmp, newfile); @@ -560,6 +576,8 @@ } } /* Plaudite, amici, comoedia finita est. */ + if (Verbose > 1) + printf("All is well.\n"); return; error_cleanup: /* Remove temp patch files, restore backed-up package. */ ==== //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#22 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#31 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#31 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/main.c#32 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#30 (text+ko) ==== @@ -170,9 +170,6 @@ else method = "cp"; - /* - * XXX: Possibly reimplement with libarchive. - */ snprintf(tmp, PATH_MAX, "%s/%s", dpatch, PKGPATCH_FNAME); fp = fopen(tmp, "w"); if (fp == NULL) @@ -196,7 +193,8 @@ n_changed_files = 0; SLIST_FOREACH(fl, &flchanged, linkage) if (fl->filename[0] != '+') { - fprintf(fp, "@patch [method=%s] %s\n", method, + fprintf(fp, "@patch [method=%s] %s\n", + S_ISLNK(fl->st.st_mode) ? "ln" : method, fl->filename); n_changed_files++; } @@ -234,8 +232,8 @@ snprintf(tmp, PATH_MAX, "%s/%s", dnew, fl->filename); snprintf(tmp2, PATH_MAX, "%s/%s", dpatch, fl->filename); if (copy_file_absolute(tmp, tmp2) != 0) - err(1, "[3] Cannot copy file: %s to file: %s", tmp, - tmp2); + err(1, "[3] Cannot copy file: %s to file: %s", + tmp, tmp2); } } else { /* @@ -244,15 +242,28 @@ * I've observed linear or better processing time improvments * with this simple trick. */ - FILE **fpvect = calloc(n_changed_files, sizeof(*fpvect)); + FILE **fpvect; int n = 0; + fpvect = calloc(n_changed_files, sizeof(*fpvect)); if (fpvect == NULL) err(1, "calloc() failed"); /* Start jobs */ SLIST_FOREACH(fl, &flchanged, linkage) { if (fl->filename[0] == '+') continue; + if (S_ISLNK(fl->st.st_mode)) { + snprintf(tmp, PATH_MAX, "%s/%s", dnew, + fl->filename); + snprintf(tmp2, PATH_MAX, "%s/%s", dpatch, + fl->filename); + if (copy_file_absolute(tmp, tmp2) != 0) + err(1, "[4] Cannot copy file: " + "%s to file: %s", tmp, tmp2); + + fpvect[n++] = NULL; + continue; + } if (Verbose > 1) printf("bsdiff for %s\n", fl->filename); snprintf(tmp, PATH_MAX, @@ -272,6 +283,10 @@ SLIST_FOREACH(fl, &flchanged, linkage) { if (fl->filename[0] == '+') continue; + if (fpvect[n] == NULL) { + n++; + continue; + } if (pclose(fpvect[n]) < 0) err(1, "pclose() failed for bsdiff of %s", fl->filename); ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#30 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.c#15 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.h#14 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#30 (text+ko) ==== @@ -48,6 +48,9 @@ #ifndef PKG_FORMAT_EXT #define PKG_FORMAT_EXT "tbz" #endif +#ifndef BSDIFF_EXT +#define BSDIFF_EXT "bsdiff" +#endif #ifndef PKGNAME_MAX #define PKGNAME_MAX 200 @@ -99,7 +102,7 @@ SLIST_ENTRY(pkgjoinlist) linkage; }; -enum PPMETHOD { PPMETHOD_UNKNOWN, PPMETHOD_CP, PPMETHOD_BSDIFF }; +enum PPMETHOD { PPMETHOD_UNKNOWN, PPMETHOD_CP, PPMETHOD_BSDIFF, PPMETHOD_LN }; STAILQ_HEAD(pplist_head, pplist); struct pplist { @@ -160,5 +163,7 @@ int check_conflicts(Package *pnew, char **pkglist); enum CMP_NAME compare_package_names(char *pkg1, char *pkg2); enum CMP_NAME check_dependencies(Package *pnew, char **pkglist); +char *find_filename(char *fullname); + #endif ==== //depot/projects/soc2010/pkg_patch/src/patch/support.c#29 (text+ko) ==== @@ -77,7 +77,7 @@ cp(char *from, char *to) { int fd1, fd2, rval = 0; - size_t bs = 1*1024*1024; + size_t bs = 1 * 1024 * 1024; char *buf; fd1 = open(from, O_RDONLY); @@ -404,7 +404,7 @@ return (errno); if (S_ISDIR(st.st_mode)) { - if (mkdir(to, 0600) != 0) { + if (mkdir(to, 0700) != 0) { if (errno != EEXIST) return (-errno); } @@ -580,6 +580,10 @@ if (strcmp(p5, "bsdiff") == 0) pl->method = PPMETHOD_BSDIFF; + else if (strcmp(p5, "cp") == 0) + pl->method = PPMETHOD_CP; + else if (strcmp(p5, "ln") == 0) + pl->method = PPMETHOD_LN; } } } else { @@ -671,7 +675,7 @@ return NULL; while (archive_read_next_header(arc, &entry) == ARCHIVE_OK) { FILE *fplist; - size_t bs = 16*1024; + size_t bs = 16 * 1024; char *buf; if (strncmp(archive_entry_pathname(entry), CONTENTS_FNAME, @@ -722,7 +726,7 @@ for (i = 0; pkglist[i] != NULL; i++) { if (strncmp(pl->name, pkglist[i], PKGNAME_MAX) == 0) - return (i+1); + return (i + 1); } } pl = pl->next; @@ -809,3 +813,16 @@ * if needed. */ return (best); } + + +/* Return a char* pointer to the filename portion of the given full filename */ +char * +find_filename(char *fullname) +{ + char *p; + + p = strrchr(fullname, '/'); + if (p == NULL) + return (fullname); + return (p + 1); +} ==== //depot/projects/soc2010/pkg_patch/src/patch/updateweb.c#10 (text+ko) ==== ==== //depot/projects/soc2010/pkg_patch/src/patch/updateweb.h#10 (text+ko) ====