summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/fileutl.cc9
-rw-r--r--apt-pkg/contrib/mmap.cc15
-rw-r--r--apt-pkg/contrib/mmap.h4
3 files changed, 16 insertions, 12 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 1b087696d..6f515fd67 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.cc,v 1.4 1998/07/12 23:58:48 jgg Exp $
+// $Id: fileutl.cc,v 1.5 1998/07/15 05:56:43 jgg Exp $
/* ######################################################################
File Utilities
@@ -113,7 +113,7 @@ string SafeGetCWD()
/* The most commonly used open mode combinations are given with Mode */
File::File(string FileName,OpenMode Mode, unsigned long Perms)
{
- Flags = 0;
+ Flags = AutoClose;
switch (Mode)
{
case ReadOnly:
@@ -205,9 +205,10 @@ bool File::Close()
{
bool Res = true;
if ((Flags & AutoClose) == AutoClose)
- if (close(iFd) != 0)
+ if (iFd >= 0 && close(iFd) != 0)
Res &= _error->Errno("close","Problem closing the file");
-
+ iFd = -1;
+
if ((Flags & Fail) == Fail && (Flags & DelOnFail) == DelOnFail &&
FileName.empty() == false)
if (unlink(FileName.c_str()) != 0)
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index ccb706eab..22251c95a 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: mmap.cc,v 1.5 1998/07/12 23:58:50 jgg Exp $
+// $Id: mmap.cc,v 1.6 1998/07/15 05:56:44 jgg Exp $
/* ######################################################################
MMap Class - Provides 'real' mmap or a faked mmap using read().
@@ -80,12 +80,13 @@ bool MMap::Map()
// MMap::Close - Close the map /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool MMap::Close(bool DoClose)
+bool MMap::Close(bool DoClose, bool DoSync)
{
if (Fd.IsOpen() == false)
return true;
- Sync();
+ if (DoSync == true)
+ Sync();
if (munmap((char *)Base,iSize) != 0)
_error->Warning("Unable to munmap");
@@ -102,7 +103,7 @@ bool MMap::Close(bool DoClose)
not return till all IO is complete */
bool MMap::Sync()
{
- if ((Flags & ReadOnly) == ReadOnly)
+ if ((Flags & ReadOnly) != ReadOnly)
if (msync((char *)Base,iSize,MS_SYNC) != 0)
return _error->Error("msync","Unable to write mmap");
return true;
@@ -113,7 +114,7 @@ bool MMap::Sync()
/* */
bool MMap::Sync(unsigned long Start,unsigned long Stop)
{
- if ((Flags & ReadOnly) == ReadOnly)
+ if ((Flags & ReadOnly) != ReadOnly)
if (msync((char *)Base+(int)(Start/PAGE_SIZE)*PAGE_SIZE,Stop - Start,MS_SYNC) != 0)
return _error->Error("msync","Unable to write mmap");
return true;
@@ -140,7 +141,9 @@ DynamicMMap::DynamicMMap(File &F,unsigned long Flags,unsigned long WorkSpace) :
DynamicMMap::~DynamicMMap()
{
unsigned long EndOfFile = iSize;
- Close(false);
+ Sync();
+ iSize = WorkSpace;
+ Close(false,false);
ftruncate(Fd.Fd(),EndOfFile);
Fd.Close();
}
diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h
index 0e80c15d2..b935ac411 100644
--- a/apt-pkg/contrib/mmap.h
+++ b/apt-pkg/contrib/mmap.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: mmap.h,v 1.4 1998/07/12 23:58:51 jgg Exp $
+// $Id: mmap.h,v 1.5 1998/07/15 05:56:45 jgg Exp $
/* ######################################################################
MMap Class - Provides 'real' mmap or a faked mmap using read().
@@ -43,7 +43,7 @@ class MMap
void *Base;
bool Map();
- bool Close(bool DoClose = true);
+ bool Close(bool DoClose = true,bool DoSync = true);
public: