diff --git a/configure.ac b/configure.ac index 09ff17f03..42e273f88 100644 --- a/configure.ac +++ b/configure.ac @@ -77,8 +77,6 @@ fi ]) NEED_PROG(curl, curl) -NEED_PROG(bzip2, bzip2) -NEED_PROG(bunzip2, bunzip2) NEED_PROG(shell, sh) AC_PATH_PROG(xmllint, xmllint, false) AC_PATH_PROG(xsltproc, xsltproc, false) @@ -145,6 +143,26 @@ AC_SUBST(aterm_lib) AC_SUBST(aterm_include) AC_SUBST(aterm_bin) +AC_ARG_WITH(bzip2, AC_HELP_STRING([--with-bzip2=PATH], + [prefix of bzip2]), + bzip2=$withval, bzip2=) +if test -z "$bzip2"; then + AC_CHECK_LIB(bz2, BZ2_bzWriteOpen, + [bzip2_lib="-lbz2"], [AC_MSG_ERROR([cannot find -lbz (bzip2)])]) + AC_CHECK_HEADER(bzlib.h, + [bzip2_include=""], [AC_MSG_ERROR([cannot find bzlib.h (bzip2)])]) + AC_PATH_PROG(bzip2_prog, bzip2, + [AC_MSG_ERROR([cannot find bzip2])]) + bzip2_bin=$(dirname $bzip2_prog) +else + bzip2_lib="-L$bzip2/lib -lbz2" + bzip2_include="-I$bzip2/include" + bzip2_bin="$bzip2/bin" +fi +AC_SUBST(bzip2_lib) +AC_SUBST(bzip2_include) +AC_SUBST(bzip2_bin) + AC_CHECK_LIB(pthread, pthread_mutex_init) AC_ARG_ENABLE(init-state, AC_HELP_STRING([--disable-init-state], @@ -203,7 +221,7 @@ AC_CONFIG_FILES([Makefile src/nix-instantiate/Makefile src/nix-env/Makefile src/nix-log2xml/Makefile - src/bsdiff-4.2/Makefile + src/bsdiff-4.3/Makefile scripts/Makefile corepkgs/Makefile corepkgs/nar/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 3167105ff..1cdbc558a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ SUBDIRS = bin2c boost libutil libstore libmain nix-store nix-hash \ - libexpr nix-instantiate nix-env nix-log2xml bsdiff-4.2 + libexpr nix-instantiate nix-env nix-log2xml bsdiff-4.3 EXTRA_DIST = aterm-helper.pl diff --git a/src/bsdiff-4.2/LICENSE b/src/bsdiff-4.2/LICENSE deleted file mode 100644 index c146b5b39..000000000 --- a/src/bsdiff-4.2/LICENSE +++ /dev/null @@ -1,121 +0,0 @@ -BSD Protection License -February 2002 - -Preamble --------- - -The Berkeley Software Distribution ("BSD") license has proven very effective -over the years at allowing for a wide spread of work throughout both -commercial and non-commercial products. For programmers whose primary -intention is to improve the general quality of available software, it is -arguable that there is no better license than the BSD license, as it -permits improvements to be used wherever they will help, without idealogical -or metallic constraint. - -This is of particular value to those who produce reference implementations -of proposed standards: The case of TCP/IP clearly illustrates that freely -and universally available implementations leads the rapid acceptance of -standards -- often even being used instead of a de jure standard (eg, OSI -network models). - -With the rapid proliferation of software licensed under the GNU General -Public License, however, the continued success of this role is called into -question. Given that the inclusion of a few lines of "GPL-tainted" work -into a larger body of work will result in restricted distribution -- and -given that further work will likely build upon the "tainted" portions, -making them difficult to remove at a future date -- there are inevitable -circumstances where authors would, in order to protect their goal of -providing for the widespread usage of their work, wish to guard against -such "GPL-taint". - -In addition, one can imagine that companies which operate by producing and -selling (possibly closed-source) code would wish to protect themselves -against the rise of a GPL-licensed competitor. While under existing -licenses this would mean not releasing their code under any form of open -license, if a license existed under which they could incorporate any -improvements back into their own (commercial) products then they might be -far more willing to provide for non-closed distribution. - -For the above reasons, we put forth this "BSD Protection License": A -license designed to retain the freedom granted by the BSD license to use -licensed works in a wide variety of settings, both non-commercial and -commercial, while protecting the work from having future contributors -restrict that freedom. - -The precise terms and conditions for copying, distribution, and -modification follow. - -BSD PROTECTION LICENSE -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION ----------------------------------------------------------------- - -0. Definitions. - a) "Program", below, refers to any program or work distributed under - the terms of this license. - b) A "work based on the Program", below, refers to either the Program - or any derivative work under copyright law. - c) "Modification", below, refers to the act of creating derivative works. - d) "You", below, refers to each licensee. - -1. Scope. - This license governs the copying, distribution, and modification of the - Program. Other activities are outside the scope of this license; The - act of running the Program is not restricted, and the output from the - Program is covered only if its contents constitute a work based on the - Program. - -2. Verbatim copies. - You may copy and distribute verbatim copies of the Program as you - receive it, in any medium, provided that you conspicuously and - appropriately publish on each copy an appropriate copyright notice; keep - intact all the notices that refer to this License and to the absence of - any warranty; and give any other recipients of the Program a copy of this - License along with the Program. - -3. Modification and redistribution under closed license. - You may modify your copy or copies of the Program, and distribute - the resulting derivative works, provided that you meet the - following conditions: - a) The copyright notice and disclaimer on the Program must be reproduced - and included in the source code, documentation, and/or other materials - provided in a manner in which such notices are normally distributed. - b) The derivative work must be clearly identified as such, in order that - it may not be confused with the original work. - c) The license under which the derivative work is distributed must - expressly prohibit the distribution of further derivative works. - -4. Modification and redistribution under open license. - You may modify your copy or copies of the Program, and distribute - the resulting derivative works, provided that you meet the - following conditions: - a) The copyright notice and disclaimer on the Program must be reproduced - and included in the source code, documentation, and/or other materials - provided in a manner in which such notices are normally distributed. - b) You must clearly indicate the nature and date of any changes made - to the Program. The full details need not necessarily be included in - the individual modified files, provided that each modified file is - clearly marked as such and instructions are included on where the - full details of the modifications may be found. - c) You must cause any work that you distribute or publish, that in whole - or in part contains or is derived from the Program or any part - thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - -5. Implied acceptance. - You may not copy or distribute the Program or any derivative works except - as expressly provided under this license. Consequently, any such action - will be taken as implied acceptance of the terms of this license. - -6. NO WARRANTY. - THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR - REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT, EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE - POSSIBILITY OF SUCH DAMAGES. diff --git a/src/bsdiff-4.2/Makefile.am b/src/bsdiff-4.2/Makefile.am deleted file mode 100644 index 70f2ead7c..000000000 --- a/src/bsdiff-4.2/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -libexec_PROGRAMS = bsdiff bspatch - -bsdiff_SOURCES = bsdiff.c - -bspatch_SOURCES = bspatch.c - -AM_CFLAGS = -O3 -DBZIP2=\"$(bzip2)\" diff --git a/src/bsdiff-4.2/Makefile.old b/src/bsdiff-4.2/Makefile.old deleted file mode 100644 index ce5dd344d..000000000 --- a/src/bsdiff-4.2/Makefile.old +++ /dev/null @@ -1,18 +0,0 @@ -CFLAGS += -O3 -.ifdef BZIP2 -CFLAGS += -DBZIP2=\"${BZIP2}\" -.endif - -PREFIX ?= /usr/local -INSTALL_PROGRAM ?= ${INSTALL} -c -s -m 555 -INSTALL_MAN ?= ${INSTALL} -c -m 444 - -all: bsdiff bspatch -bsdiff: bsdiff.c -bspatch: bspatch.c - -install: - ${INSTALL_PROGRAM} bsdiff bspatch ${PREFIX}/bin -.ifndef WITHOUT_MAN - ${INSTALL_MAN} bsdiff.1 bspatch.1 ${PREFIX}/man/man1 -.endif diff --git a/src/bsdiff-4.2/bsdiff.1 b/src/bsdiff-4.2/bsdiff.1 deleted file mode 100644 index 8d3926d32..000000000 --- a/src/bsdiff-4.2/bsdiff.1 +++ /dev/null @@ -1,36 +0,0 @@ -.Dd May 18, 2003 -.Dt BSDIFF 1 -.Os FreeBSD -.Sh NAME -.Nm bsdiff -.Nd generate a patch between two binary files -.Sh SYNOPSIS -.Nm -.Ao Ar oldfile Ac Ao Ar newfile Ac Ao Ar patchfile Ac -.Sh DESCRIPTION -.Nm -compares -.Ao Ar oldfile Ac -to -.Ao Ar newfile Ac -and writes to -.Ao Ar patchfile Ac -a binary patch suitable for use by bspatch(1). -When -.Ao Ar oldfile Ac -and -.Ao Ar newfile Ac -are two versions of an executable program, the -patches produced are on average a factor of five smaller -than those produced by any other binary patch tool known -to the author. -.Pp -.Nm -uses memory equal to 17 times the size of -.Ao Ar oldfile Ac , -and requires -an absolute minimum working set size of 8 times the size of oldfile. -.Sh SEE ALSO -.Xr bspatch 1 -.Sh AUTHORS -.An Colin Percival Aq cperciva@daemonology.net diff --git a/src/bsdiff-4.2/bspatch.1 b/src/bsdiff-4.2/bspatch.1 deleted file mode 100644 index b243f2b7b..000000000 --- a/src/bsdiff-4.2/bspatch.1 +++ /dev/null @@ -1,32 +0,0 @@ -.Dd May 18, 2003 -.Dt BSPATCH 1 -.Os FreeBSD -.Sh NAME -.Nm bspatch -.Nd apply a patch built with bsdiff(1) -.Sh SYNOPSIS -.Nm -.Ao Ar oldfile Ac Ao Ar newfile Ac Ao Ar patchfile Ac -.Sh DESCRIPTION -.Nm -generates -.Ao Ar newfile Ac -from -.Ao Ar oldfile Ac -and -.Ao Ar patchfile Ac -where -.Ao Ar patchfile Ac -is a binary patch built by bsdiff(1). -.Pp -.Nm -uses memory equal to the size of -.Ao Ar oldfile Ac -plus the size of -.Ao Ar newfile Ac , -but can tolerate a very small working set without a dramatic loss -of performance. -.Sh SEE ALSO -.Xr bsdiff 1 -.Sh AUTHORS -.An Colin Percival Aq cperciva@daemonology.net diff --git a/src/bsdiff-4.2/bspatch.c b/src/bsdiff-4.2/bspatch.c deleted file mode 100644 index 1386a7096..000000000 --- a/src/bsdiff-4.2/bspatch.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - .c -- Binary patcher - - Copyright 2003,2004 Colin Percival - - For the terms under which this work may be distributed, please see - the adjoining file "LICENSE". -*/ - -#ifndef BZIP2 -#define BZIP2 "/usr/bin/bzip2" -#endif - -#include -#include -#include -#include -#include -#include - -ssize_t loopread(int d,void *buf,size_t nbytes) -{ - ssize_t ptr,lenread; - - for(ptr=0;ptrnewsize) errx(1,"Corrupt patch\n"); - if((lenread=loopread(diffpipe,new+newpos,ctrl[0]))<0) - err(1,NULL); - if(lenread!=ctrl[0]) errx(1,"Corrupt patch\n"); - for(i=0;i=0) && (oldpos+inewsize) errx(1,"Corrupt patch\n"); - if((lenread=loopread(extrapipe,new+newpos,ctrl[1]))<0) - err(1,NULL); - if(lenread!=ctrl[1]) errx(1,"Corrupt patch\n"); - - newpos+=ctrl[1]; - oldpos+=ctrl[2]; - }; - }; - - if(loopread(ctrlpipe,buf,1)!=0) errx(1,"Corrupt patch\n"); - if(loopread(diffpipe,buf,1)!=0) errx(1,"Corrupt patch\n"); - if(version==2) - if(loopread(extrapipe,buf,1)!=0) errx(1,"Corrupt patch\n"); - - if(close(ctrlpipe) || close(diffpipe) || - ((version==2) && close(extrapipe))) - err(1,NULL); - for(i=0;i<(version+1)*2;i++) waitpid(pids[i],NULL,0); - - if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) || - (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) - err(1,"%s",argv[2]); - - free(new); - free(old); - - return 0; -} diff --git a/src/bsdiff-4.3/Makefile.am b/src/bsdiff-4.3/Makefile.am new file mode 100644 index 000000000..4b3af0783 --- /dev/null +++ b/src/bsdiff-4.3/Makefile.am @@ -0,0 +1,11 @@ +libexec_PROGRAMS = bsdiff bspatch + +bsdiff_SOURCES = bsdiff.c + +bsdiff_LDADD = ${bzip2_lib} + +bspatch_SOURCES = bspatch.c + +bspatch_LDADD = ${bzip2_lib} + +AM_CFLAGS = -O3 ${bzip2_include} diff --git a/src/bsdiff-4.3/bsdiff.1 b/src/bsdiff-4.3/bsdiff.1 new file mode 100644 index 000000000..ead6c4deb --- /dev/null +++ b/src/bsdiff-4.3/bsdiff.1 @@ -0,0 +1,63 @@ +.\"- +.\" Copyright 2003-2005 Colin Percival +.\" All rights reserved +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted providing that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.1,v 1.1 2005/08/06 01:59:05 cperciva Exp $ +.\" +.Dd May 18, 2003 +.Dt BSDIFF 1 +.Os FreeBSD +.Sh NAME +.Nm bsdiff +.Nd generate a patch between two binary files +.Sh SYNOPSIS +.Nm +.Ao Ar oldfile Ac Ao Ar newfile Ac Ao Ar patchfile Ac +.Sh DESCRIPTION +.Nm +compares +.Ao Ar oldfile Ac +to +.Ao Ar newfile Ac +and writes to +.Ao Ar patchfile Ac +a binary patch suitable for use by bspatch(1). +When +.Ao Ar oldfile Ac +and +.Ao Ar newfile Ac +are two versions of an executable program, the +patches produced are on average a factor of five smaller +than those produced by any other binary patch tool known +to the author. +.Pp +.Nm +uses memory equal to 17 times the size of +.Ao Ar oldfile Ac , +and requires +an absolute minimum working set size of 8 times the size of oldfile. +.Sh SEE ALSO +.Xr bspatch 1 +.Sh AUTHORS +.An Colin Percival Aq cperciva@freebsd.org diff --git a/src/bsdiff-4.2/bsdiff.c b/src/bsdiff-4.3/bsdiff.c similarity index 60% rename from src/bsdiff-4.2/bsdiff.c rename to src/bsdiff-4.3/bsdiff.c index f47226c1e..150a7f79c 100644 --- a/src/bsdiff-4.2/bsdiff.c +++ b/src/bsdiff-4.3/bsdiff.c @@ -1,27 +1,46 @@ -/* - bsdiff.c -- Binary patch generator. +/*- + * Copyright 2003-2005 Colin Percival + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted providing that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ - Copyright 2003 Colin Percival - - For the terms under which this work may be distributed, please see - the adjoining file "LICENSE". -*/ - -#ifndef BZIP2 -#define BZIP2 "/usr/bin/bzip2" +#if 0 +__FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c,v 1.1 2005/08/06 01:59:05 cperciva Exp $"); #endif -#include -#include -#include +#include + +#include #include -#include #include -#include +#include +#include +#include +#include #define MIN(x,y) (((x)<(y)) ? (x) : (y)) -void split(off_t *I,off_t *V,off_t start,off_t len,off_t h) +static void split(off_t *I,off_t *V,off_t start,off_t len,off_t h) { off_t i,j,k,x,tmp,jj,kk; @@ -82,7 +101,7 @@ void split(off_t *I,off_t *V,off_t start,off_t len,off_t h) if(start+len>kk) split(I,V,kk,start+len-kk,h); } -void qsufsort(off_t *I,off_t *V,u_char *old,off_t oldsize) +static void qsufsort(off_t *I,off_t *V,u_char *old,off_t oldsize) { off_t buckets[256]; off_t i,h,len; @@ -120,7 +139,7 @@ void qsufsort(off_t *I,off_t *V,u_char *old,off_t oldsize) for(i=0;i +#include +#include +#include +#include +#include +#include + +static off_t offtin(u_char *buf) +{ + off_t y; + + y=buf[7]&0x7F; + y=y*256;y+=buf[6]; + y=y*256;y+=buf[5]; + y=y*256;y+=buf[4]; + y=y*256;y+=buf[3]; + y=y*256;y+=buf[2]; + y=y*256;y+=buf[1]; + y=y*256;y+=buf[0]; + + if(buf[7]&0x80) y=-y; + + return y; +} + +int main(int argc,char * argv[]) +{ + FILE * f, * cpf, * dpf, * epf; + BZFILE * cpfbz2, * dpfbz2, * epfbz2; + int cbz2err, dbz2err, ebz2err; + int fd; + ssize_t oldsize,newsize; + ssize_t bzctrllen,bzdatalen; + u_char header[32],buf[8]; + u_char *old, *new; + off_t oldpos,newpos; + off_t ctrl[3]; + off_t lenread; + off_t i; + + if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); + + /* Open patch file */ + if ((f = fopen(argv[3], "r")) == NULL) + err(1, "fopen(%s)", argv[3]); + + /* + File format: + 0 8 "BSDIFF40" + 8 8 X + 16 8 Y + 24 8 sizeof(newfile) + 32 X bzip2(control block) + 32+X Y bzip2(diff block) + 32+X+Y ??? bzip2(extra block) + with control block a set of triples (x,y,z) meaning "add x bytes + from oldfile to x bytes from the diff block; copy y bytes from the + extra block; seek forwards in oldfile by z bytes". + */ + + /* Read header */ + if (fread(header, 1, 32, f) < 32) { + if (feof(f)) + errx(1, "Corrupt patch\n"); + err(1, "fread(%s)", argv[3]); + } + + /* Check for appropriate magic */ + if (memcmp(header, "BSDIFF40", 8) != 0) + errx(1, "Corrupt patch\n"); + + /* Read lengths from header */ + bzctrllen=offtin(header+8); + bzdatalen=offtin(header+16); + newsize=offtin(header+24); + if((bzctrllen<0) || (bzdatalen<0) || (newsize<0)) + errx(1,"Corrupt patch\n"); + + /* Close patch file and re-open it via libbzip2 at the right places */ + if (fclose(f)) + err(1, "fclose(%s)", argv[3]); + if ((cpf = fopen(argv[3], "r")) == NULL) + err(1, "fopen(%s)", argv[3]); + if (fseeko(cpf, 32, SEEK_SET)) + err(1, "fseeko(%s, %lld)", argv[3], + (long long)32); + if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) + errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err); + if ((dpf = fopen(argv[3], "r")) == NULL) + err(1, "fopen(%s)", argv[3]); + if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) + err(1, "fseeko(%s, %lld)", argv[3], + (long long)(32 + bzctrllen)); + if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL) + errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err); + if ((epf = fopen(argv[3], "r")) == NULL) + err(1, "fopen(%s)", argv[3]); + if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) + err(1, "fseeko(%s, %lld)", argv[3], + (long long)(32 + bzctrllen + bzdatalen)); + if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) + errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err); + + if(((fd=open(argv[1],O_RDONLY,0))<0) || + ((oldsize=lseek(fd,0,SEEK_END))==-1) || + ((old=malloc(oldsize+1))==NULL) || + (lseek(fd,0,SEEK_SET)!=0) || + (read(fd,old,oldsize)!=oldsize) || + (close(fd)==-1)) err(1,"%s",argv[1]); + if((new=malloc(newsize+1))==NULL) err(1,NULL); + + oldpos=0;newpos=0; + while(newposnewsize) + errx(1,"Corrupt patch\n"); + + /* Read diff string */ + lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]); + if ((lenread < ctrl[0]) || + ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END))) + errx(1, "Corrupt patch\n"); + + /* Add old data to diff string */ + for(i=0;i=0) && (oldpos+inewsize) + errx(1,"Corrupt patch\n"); + + /* Read extra string */ + lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]); + if ((lenread < ctrl[1]) || + ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END))) + errx(1, "Corrupt patch\n"); + + /* Adjust pointers */ + newpos+=ctrl[1]; + oldpos+=ctrl[2]; + }; + + /* Clean up the bzip2 reads */ + BZ2_bzReadClose(&cbz2err, cpfbz2); + BZ2_bzReadClose(&dbz2err, dpfbz2); + BZ2_bzReadClose(&ebz2err, epfbz2); + if (fclose(cpf) || fclose(dpf) || fclose(epf)) + err(1, "fclose(%s)", argv[3]); + + /* Write the new file */ + if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) || + (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) + err(1,"%s",argv[2]); + + free(new); + free(old); + + return 0; +} diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 0a0dfed7e..97466cf9e 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -66,7 +66,7 @@ Hash hashString(HashType ht, const string & s); Hash hashFile(HashType ht, const Path & path); /* Compute the hash of the given path. The hash is defined as - md5(dump(path)). */ + (essentially) hashString(ht, dumpPath(path)). */ Hash hashPath(HashType ht, const Path & path); /* Compress a hash to the specified number of bytes by cyclically diff --git a/substitute.mk b/substitute.mk index 5f9204929..2b7f38610 100644 --- a/substitute.mk +++ b/substitute.mk @@ -11,8 +11,8 @@ -e "s^@system\@^$(system)^g" \ -e "s^@shell\@^$(shell)^g" \ -e "s^@curl\@^$(curl)^g" \ - -e "s^@bzip2\@^$(bzip2)^g" \ - -e "s^@bunzip2\@^$(bunzip2)^g" \ + -e "s^@bzip2\@^$(bzip2_bin)/bzip2^g" \ + -e "s^@bunzip2\@^$(bzip2_bin)/bunzip2^g" \ -e "s^@perl\@^$(perl)^g" \ -e "s^@coreutils\@^$(coreutils)^g" \ -e "s^@tar\@^$(tar)^g" \