From 257e8d668c044fb0e9ad8e4b53afd32e07404831 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 29 Nov 2011 12:14:31 +0100 Subject: split up the OpenMode into OpenMode and CompressionMode and provide ReadOnly, WriteOnly and ReadWrite as flags alongside the additional flags as decompression will be one-way later, but certain parts really depend on Write* openmodes being ReadWrite opens, so we will have to fail for those. --- apt-pkg/contrib/fileutl.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'apt-pkg/contrib/fileutl.h') diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 0d0451a46..fa8f92272 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -44,8 +44,24 @@ class FileFd gzFile gz; public: - enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,WriteTemp,ReadOnlyGzip, - WriteAtomic}; + enum OpenMode { + ReadOnly = (1 << 0), + WriteOnly = (1 << 1), + ReadWrite = ReadOnly | WriteOnly, + + Create = (1 << 2), + Exclusive = (1 << 3), + Atomic = Exclusive | (1 << 4), + Empty = (1 << 5), + + WriteEmpty = ReadWrite | Create | Empty, + WriteExists = ReadWrite, + WriteAny = ReadWrite | Create, + WriteTemp = ReadWrite | Create | Exclusive, + ReadOnlyGzip, + WriteAtomic = ReadWrite | Create | Atomic + }; + enum CompressMode { Auto, None, Gzip, Bzip2, Lzma, Xz }; inline bool Read(void *To,unsigned long long Size,bool AllowEof) { @@ -77,8 +93,14 @@ class FileFd return T; } - bool Open(std::string FileName,OpenMode Mode,unsigned long Perms = 0666); - bool OpenDescriptor(int Fd, OpenMode Mode, bool AutoClose=false); + bool Open(std::string FileName,OpenMode Mode,CompressMode Compress,unsigned long Perms = 0666); + inline bool Open(std::string const &FileName,OpenMode Mode,unsigned long Perms = 0666) { + return Open(FileName, Mode, None, Perms); + }; + bool OpenDescriptor(int Fd, OpenMode Mode, CompressMode Compress, bool AutoClose=false); + inline bool OpenDescriptor(int Fd, OpenMode Mode, bool AutoClose=false) { + return OpenDescriptor(Fd, Mode, None, AutoClose); + }; bool Close(); bool Sync(); -- cgit v1.2.3