]> git.saurik.com Git - apt.git/blobdiff - methods/rred.cc
merged from lp:~donkult/apt/experimental
[apt.git] / methods / rred.cc
index 1a18a381c803351dd46d56f846a4b8e0277fb794..bc941ed049f84a3e0b85379f7505372bbbe1e4f1 100644 (file)
@@ -1,4 +1,6 @@
 // Includes                                                                    /*{{{*/
+#include <config.h>
+
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/mmap.h>
 #include <apt-pkg/error.h>
@@ -51,7 +53,7 @@ protected:
        virtual bool Fetch(FetchItem *Itm);
 
 public:
-       RredMethod() : pkgAcqMethod("1.1",SingleInstance | SendConfig) {};
+       RredMethod() : pkgAcqMethod("1.1",SingleInstance | SendConfig), Debug(false) {};
 };
                                                                                /*}}}*/
 /** \brief applyFile - in reverse order with a tail recursion                  {{{
@@ -239,7 +241,9 @@ RredMethod::State RredMethod::patchFile(FileFd &Patch, FileFd &From,                /*{{{*/
    return result;
 }
                                                                                /*}}}*/
-struct EdCommand {                                                             /*{{{*/
+/* struct EdCommand                                                            {{{*/
+#ifdef _POSIX_MAPPED_FILES
+struct EdCommand {
   size_t data_start;
   size_t data_end;
   size_t data_lines;
@@ -248,17 +252,25 @@ struct EdCommand {                                                                /*{{{*/
   char type;
 };
 #define IOV_COUNT 1024 /* Don't really want IOV_MAX since it can be arbitrarily large */
+#endif
                                                                                /*}}}*/
 RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From,           /*{{{*/
                                        FileFd &out_file, Hashes *hash) const {
 #ifdef _POSIX_MAPPED_FILES
-       MMap ed_cmds(Patch, MMap::ReadOnly);
+       MMap ed_cmds(MMap::ReadOnly);
        if (Patch.gzFd() != NULL) {
-               unsigned long mapSize = Patch.Size();
-               DynamicMMap dyn(0, mapSize, 0);
-               gzread(Patch.gzFd(), dyn.Data(), mapSize);
-               ed_cmds = dyn;
-       }
+               unsigned long long mapSize = Patch.Size();
+               DynamicMMap* dyn = new DynamicMMap(0, mapSize, 0);
+               if (dyn->validData() == false) {
+                       delete dyn;
+                       return MMAP_FAILED;
+               }
+               dyn->AddSize(mapSize);
+               gzread(Patch.gzFd(), dyn->Data(), mapSize);
+               ed_cmds = *dyn;
+       } else
+               ed_cmds = MMap(Patch, MMap::ReadOnly);
+
        MMap in_file(From, MMap::ReadOnly);
 
        if (ed_cmds.Size() == 0 || in_file.Size() == 0)