Bug#291338: apt: md5/sha1 checksum routines should work if length of file is unknown
On Thu, 20 Jan 2005, Anthony Towns wrote:
> Package: apt
> Version: 0.5.4
> Severity: wishlist
> Tags: patch
>
> SHA1Summation::AddFD should work on pipes as well as regular files
> so files don't need to be uncompressed to disk to be summed. This
> impacts python-apt too, since it doesn't offer a cumulative interface
> to SHA1Summation.
>
> Easy fix seems like it'd be:
>
> bool SHA1Summation::AddFD(int Fd,unsigned long Size)
> {
> unsigned char Buf[64 * 64];
> int Res = 0;
> - while (Size != 0)
> + int ToEOF = (Size == 0);
> + while (Size != 0 || ToEOF);
> {
> - Res = read(Fd,Buf,MIN(Size,sizeof(Buf)));
> - if (Res < 0 || (unsigned) Res != MIN(Size,sizeof(Buf)))
> + int n = sizeof(Buf);
> + if (!ToEOF) n = MIN(Size,n);
> + Res = read(Fd,Buf,n);
> + if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
> return false;
> + if (ToEOF && Res == 0) // EOF
> + break;
> Size -= Res;
> Add(Buf,Res);
> }
> return true;
> }
I have no problem with this; it's similiar to how dpkg does it(separate far to
indicate processing until eof is hit(dpkg does it with limit == -1, HTH)
Reply to: