reorder includes: add <config.h> if needed and include it at first
[ntk/apt.git] / apt-pkg / pkgcachegen.cc
index 8e088ba..1cae231 100644 (file)
@@ -11,6 +11,7 @@
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
 #define APT_COMPATIBILITY 986
+#include <config.h>
 
 #include <apt-pkg/pkgcachegen.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/macros.h>
-
 #include <apt-pkg/tagfile.h>
 
-#include <apti18n.h>
-
 #include <vector>
-
 #include <sys/stat.h>
 #include <unistd.h>
 #include <errno.h>
 #include <stdio.h>
+
+#include <apti18n.h>
                                                                        /*}}}*/
 typedef vector<pkgIndexFile *>::iterator FileIterator;
 template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
@@ -1169,16 +1168,32 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
    SPtr<DynamicMMap> Map;
    if (Writeable == true && CacheFile.empty() == false)
    {
+      _error->PushToStack();
       unlink(CacheFile.c_str());
       CacheF = new FileFd(CacheFile,FileFd::WriteAtomic);
       fchmod(CacheF->Fd(),0644);
       Map = CreateDynamicMMap(CacheF, MMap::Public);
       if (_error->PendingError() == true)
-        return false;
-      if (Debug == true)
+      {
+        delete CacheF.UnGuard();
+        delete Map.UnGuard();
+        if (Debug == true)
+           std::clog << "Open filebased MMap FAILED" << std::endl;
+        Writeable = false;
+        if (AllowMem == false)
+        {
+           _error->MergeWithStack();
+           return false;
+        }
+        _error->RevertToStack();
+      }
+      else if (Debug == true)
+      {
+        _error->MergeWithStack();
         std::clog << "Open filebased MMap" << std::endl;
+      }
    }
-   else
+   if (Writeable == false || CacheFile.empty() == true)
    {
       // Just build it in memory..
       Map = CreateDynamicMMap(NULL);