]> git.saurik.com Git - apt.git/commitdiff
FildFd: Introduce a Flush() function and call it from Close()
authorJulian Andres Klode <jak@debian.org>
Sun, 27 Dec 2015 13:25:11 +0000 (14:25 +0100)
committerJulian Andres Klode <jak@debian.org>
Sun, 27 Dec 2015 15:19:33 +0000 (16:19 +0100)
The flush function can be used for buffered writers.

apt-pkg/contrib/fileutl.cc
apt-pkg/contrib/fileutl.h

index 8fdd6a5dda0e464223d7f33c806c7a8564018898..ecc8c83fd3b7a4ae5af660205bdf66fb280712b8 100644 (file)
@@ -1055,6 +1055,10 @@ public:
       *To = '\0';
       return InitialTo;
    }
+   virtual bool InternalFlush()
+   {
+      return true;
+   }
    virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) = 0;
    virtual bool InternalWriteError() { return filefd->FileFdErrno("write",_("Write error")); }
    virtual bool InternalSeek(unsigned long long const To)
@@ -2070,6 +2074,15 @@ char* FileFd::ReadLine(char *To, unsigned long long const Size)
    return d->InternalReadLine(To, Size);
 }
                                                                        /*}}}*/
+// FileFd::Flush - Flush the file                                      /*{{{*/
+bool FileFd::Flush()
+{
+   if (d == nullptr)
+      return true;
+
+   return d->InternalFlush();
+}
+                                                                       /*}}}*/
 // FileFd::Write - Write to the file                                   /*{{{*/
 bool FileFd::Write(const void *From,unsigned long long Size)
 {
@@ -2223,6 +2236,8 @@ unsigned long long FileFd::Size()
 /* */
 bool FileFd::Close()
 {
+   if (Flush() == false)
+      return false;
    if (iFd == -1)
       return true;
 
index 57d3ab8412f58cab599c6380c7ad13c26b364080..8cfb2e989eb97f15cfd80d57888f040d7c6ec412 100644 (file)
@@ -85,6 +85,7 @@ class FileFd
    }   
    bool Read(void *To,unsigned long long Size,unsigned long long *Actual = 0);
    char* ReadLine(char *To, unsigned long long const Size);
+   bool Flush();
    bool Write(const void *From,unsigned long long Size);
    bool static Write(int Fd, const void *From, unsigned long long Size);
    bool Seek(unsigned long long To);