]> git.saurik.com Git - apt.git/blobdiff - methods/rred.cc
vendor/debian/makefile: apply 6f3c4e33 for debian/makefile as well
[apt.git] / methods / rred.cc
index bf9294d96c328f7669df43e5a0fbb2bd716a481d..7c65f8f9223a30d15d552d27d7dfb4ebdc90a852 100644 (file)
@@ -15,7 +15,6 @@
 #include <utime.h>
 #include <stdio.h>
 #include <errno.h>
-#include <zlib.h>
 #include <apti18n.h>
                                                                                /*}}}*/
 /** \brief RredMethod - ed-style incremential patch method                     {{{
@@ -227,6 +226,21 @@ struct EdCommand {
   char type;
 };
 #define IOV_COUNT 1024 /* Don't really want IOV_MAX since it can be arbitrarily large */
+static ssize_t retry_writev(int fd, const struct iovec *iov, int iovcnt) {
+       ssize_t Res;
+       errno = 0;
+       ssize_t i = 0;
+       do {
+               Res = writev(fd, iov + i, iovcnt);
+               if (Res < 0 && errno == EINTR)
+                       continue;
+               if (Res < 0)
+                       return _error->Errno("writev",_("Write error"));
+               iovcnt -= Res;
+               i += Res;
+       } while (Res > 0 && iovcnt > 0);
+       return i;
+}
 #endif
                                                                                /*}}}*/
 RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From,           /*{{{*/
@@ -235,7 +249,9 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From,                /*{{{*/
        MMap ed_cmds(Patch, MMap::ReadOnly);
        MMap in_file(From, MMap::ReadOnly);
 
-       if (ed_cmds.Size() == 0 || in_file.Size() == 0)
+       unsigned long long const ed_size = ed_cmds.Size();
+       unsigned long long const in_size = in_file.Size();
+       if (ed_size == 0 || in_size == 0)
                return MMAP_FAILED;
 
        EdCommand* commands = 0;
@@ -244,10 +260,10 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From,              /*{{{*/
 
        const char* begin = (char*) ed_cmds.Data();
        const char* end = begin;
-       const char* ed_end = (char*) ed_cmds.Data() + ed_cmds.Size();
+       const char* ed_end = (char*) ed_cmds.Data() + ed_size;
 
        const char* input = (char*) in_file.Data();
-       const char* input_end = (char*) in_file.Data() + in_file.Size();
+       const char* input_end = (char*) in_file.Data() + in_size;
 
        size_t i;
 
@@ -331,7 +347,12 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From,               /*{{{*/
                }
                if(command_count == command_alloc) {
                        command_alloc = (command_alloc + 64) * 3 / 2;
-                       commands = (EdCommand*) realloc(commands, command_alloc * sizeof(EdCommand));
+                       EdCommand* newCommands = (EdCommand*) realloc(commands, command_alloc * sizeof(EdCommand));
+                       if (newCommands == NULL) {
+                               free(commands);
+                               return MMAP_FAILED;
+                       }
+                       commands = newCommands;
                }
                commands[command_count++] = cmd;
        }
@@ -370,7 +391,7 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From,                /*{{{*/
                        hash->Add((const unsigned char*) begin, input - begin);
 
                        if(++iov_size == IOV_COUNT) {
-                               writev(out_file.Fd(), iov, IOV_COUNT);
+                               retry_writev(out_file.Fd(), iov, IOV_COUNT);
                                iov_size = 0;
                        }
                }
@@ -395,7 +416,7 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From,                /*{{{*/
                                iov[iov_size].iov_len);
 
                                if(++iov_size == IOV_COUNT) {
-                                       writev(out_file.Fd(), iov, IOV_COUNT);
+                                       retry_writev(out_file.Fd(), iov, IOV_COUNT);
                                        iov_size = 0;
                                }
                        }
@@ -410,15 +431,15 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From,              /*{{{*/
        }
 
        if(iov_size) {
-               writev(out_file.Fd(), iov, iov_size);
+               retry_writev(out_file.Fd(), iov, iov_size);
                iov_size = 0;
        }
 
        for(i = 0; i < iov_size; i += IOV_COUNT) {
                if(iov_size - i < IOV_COUNT)
-                       writev(out_file.Fd(), iov + i, iov_size - i);
+                       retry_writev(out_file.Fd(), iov + i, iov_size - i);
                else
-                       writev(out_file.Fd(), iov + i, IOV_COUNT);
+                       retry_writev(out_file.Fd(), iov + i, IOV_COUNT);
        }
 
        delete [] iov;