summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2024-12-26 19:41:53 +0000
committerDavid Kalnischkies <david@kalnischkies.de>2025-01-05 22:16:08 +0000
commitf73593a4034d9eec0ec4466b8e173d4a4daece1f (patch)
tree9cab47b9426e3e9fff80682b86f8449e3d9c9b53 /apt-pkg/contrib
parent427f95cedadb5323d35e5174d4592cbdd9c602f4 (diff)
Drop usage of macro APT_OVERRIDE for simple override
We were rather inconsistent in using it and as our public headers contain deduction guides (a c++17 feature) it seems silly to try to hide a c++11 feature in a macro, so lets stop this charade and drop the macro and while we are changing all these lines lets apply [[nodiscard]] (another c++17 feature) and other suggestions from clang-tidy and formatting for a little more consistency.
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/fileutl.cc467
-rw-r--r--apt-pkg/contrib/macros.h16
-rw-r--r--apt-pkg/contrib/progress.h4
3 files changed, 247 insertions, 240 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 67c5acee2..a72766e8d 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1298,63 +1298,63 @@ public:
explicit BufferedWriteFileFdPrivate(FileFdPrivate *Priv) :
FileFdPrivate(Priv->filefd), wrapped(Priv) {};
- virtual APT::Configuration::Compressor get_compressor() const APT_OVERRIDE
+ [[nodiscard]] APT::Configuration::Compressor get_compressor() const override
{
return wrapped->get_compressor();
}
- virtual void set_compressor(APT::Configuration::Compressor const &compressor) APT_OVERRIDE
+ void set_compressor(APT::Configuration::Compressor const &compressor) override
{
return wrapped->set_compressor(compressor);
}
- virtual unsigned int get_openmode() const APT_OVERRIDE
+ [[nodiscard]] unsigned int get_openmode() const override
{
return wrapped->get_openmode();
}
- virtual void set_openmode(unsigned int openmode) APT_OVERRIDE
+ void set_openmode(unsigned int openmode) override
{
return wrapped->set_openmode(openmode);
}
- virtual bool get_is_pipe() const APT_OVERRIDE
+ [[nodiscard]] bool get_is_pipe() const override
{
return wrapped->get_is_pipe();
}
- virtual void set_is_pipe(bool is_pipe) APT_OVERRIDE
+ void set_is_pipe(bool is_pipe) override
{
FileFdPrivate::set_is_pipe(is_pipe);
wrapped->set_is_pipe(is_pipe);
}
- virtual unsigned long long get_seekpos() const APT_OVERRIDE
+ [[nodiscard]] unsigned long long get_seekpos() const override
{
return wrapped->get_seekpos();
}
- virtual void set_seekpos(unsigned long long seekpos) APT_OVERRIDE
+ void set_seekpos(unsigned long long seekpos) override
{
return wrapped->set_seekpos(seekpos);
}
- virtual bool InternalOpen(int const iFd, unsigned int const Mode) APT_OVERRIDE
+ bool InternalOpen(int const iFd, unsigned int const Mode) override
{
if (InternalFlush() == false)
return false;
return wrapped->InternalOpen(iFd, Mode);
}
- virtual ssize_t InternalUnbufferedRead(void * const To, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) override
{
if (InternalFlush() == false)
return -1;
return wrapped->InternalUnbufferedRead(To, Size);
}
- virtual bool InternalReadError() APT_OVERRIDE
+ bool InternalReadError() override
{
return wrapped->InternalReadError();
}
- virtual char * InternalReadLine(char * To, unsigned long long Size) APT_OVERRIDE
+ char *InternalReadLine(char *To, unsigned long long Size) override
{
if (InternalFlush() == false)
return nullptr;
return wrapped->InternalReadLine(To, Size);
}
- virtual bool InternalFlush() APT_OVERRIDE
+ bool InternalFlush() override
{
while (writebuffer.empty() == false) {
auto written = wrapped->InternalWrite(writebuffer.get(),
@@ -1370,7 +1370,7 @@ public:
writebuffer.reset();
return wrapped->InternalFlush();
}
- virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalWrite(void const *const From, unsigned long long const Size) override
{
// Optimisation: If the buffer is empty and we have more to write than
// would fit in the buffer (or equal number of bytes), write directly.
@@ -1385,45 +1385,45 @@ public:
return written;
}
- virtual bool InternalWriteError() APT_OVERRIDE
+ bool InternalWriteError() override
{
return wrapped->InternalWriteError();
}
- virtual bool InternalSeek(unsigned long long const To) APT_OVERRIDE
+ bool InternalSeek(unsigned long long const To) override
{
if (InternalFlush() == false)
return false;
return wrapped->InternalSeek(To);
}
- virtual bool InternalSkip(unsigned long long Over) APT_OVERRIDE
+ bool InternalSkip(unsigned long long Over) override
{
if (InternalFlush() == false)
return false;
return wrapped->InternalSkip(Over);
}
- virtual bool InternalTruncate(unsigned long long const Size) APT_OVERRIDE
+ bool InternalTruncate(unsigned long long const Size) override
{
if (InternalFlush() == false)
return false;
return wrapped->InternalTruncate(Size);
}
- virtual unsigned long long InternalTell() APT_OVERRIDE
+ unsigned long long InternalTell() override
{
if (InternalFlush() == false)
return -1;
return wrapped->InternalTell();
}
- virtual unsigned long long InternalSize() APT_OVERRIDE
+ unsigned long long InternalSize() override
{
if (InternalFlush() == false)
return -1;
return wrapped->InternalSize();
}
- virtual bool InternalClose(std::string const &FileName) APT_OVERRIDE
+ bool InternalClose(std::string const &FileName) override
{
return wrapped->InternalClose(FileName);
}
- virtual bool InternalAlwaysAutoClose() const APT_OVERRIDE
+ [[nodiscard]] bool InternalAlwaysAutoClose() const override
{
return wrapped->InternalAlwaysAutoClose();
}
@@ -1437,7 +1437,7 @@ class APT_HIDDEN GzipFileFdPrivate: public FileFdPrivate { /*{{{*/
#ifdef HAVE_ZLIB
public:
gzFile gz;
- virtual bool InternalOpen(int const iFd, unsigned int const Mode) APT_OVERRIDE
+ bool InternalOpen(int const iFd, unsigned int const Mode) override
{
if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
gz = gzdopen(iFd, "r+");
@@ -1448,11 +1448,11 @@ public:
filefd->Flags |= FileFd::Compressed;
return gz != nullptr;
}
- virtual ssize_t InternalUnbufferedRead(void * const To, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) override
{
return gzread(gz, To, Size);
}
- virtual bool InternalReadError() APT_OVERRIDE
+ bool InternalReadError() override
{
int err;
char const * const errmsg = gzerror(gz, &err);
@@ -1460,15 +1460,15 @@ public:
return filefd->FileFdError("gzread: %s (%d: %s)", _("Read error"), err, errmsg);
return FileFdPrivate::InternalReadError();
}
- virtual char * InternalReadLine(char * To, unsigned long long Size) APT_OVERRIDE
+ char *InternalReadLine(char *To, unsigned long long Size) override
{
return gzgets(gz, To, Size);
}
- virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalWrite(void const *const From, unsigned long long const Size) override
{
return gzwrite(gz,From,Size);
}
- virtual bool InternalWriteError() APT_OVERRIDE
+ bool InternalWriteError() override
{
int err;
char const * const errmsg = gzerror(gz, &err);
@@ -1476,7 +1476,7 @@ public:
return filefd->FileFdError("gzwrite: %s (%d: %s)", _("Write error"), err, errmsg);
return FileFdPrivate::InternalWriteError();
}
- virtual bool InternalSeek(unsigned long long const To) APT_OVERRIDE
+ bool InternalSeek(unsigned long long const To) override
{
off_t const res = gzseek(gz, To, SEEK_SET);
if (res != (off_t)To)
@@ -1485,7 +1485,7 @@ public:
buffer.reset();
return true;
}
- virtual bool InternalSkip(unsigned long long Over) APT_OVERRIDE
+ bool InternalSkip(unsigned long long Over) override
{
if (Over >= buffer.size())
{
@@ -1505,11 +1505,11 @@ public:
seekpos = res;
return true;
}
- virtual unsigned long long InternalTell() APT_OVERRIDE
+ unsigned long long InternalTell() override
{
return gztell(gz) - buffer.size();
}
- virtual unsigned long long InternalSize() APT_OVERRIDE
+ unsigned long long InternalSize() override
{
unsigned long long filesize = FileFdPrivate::InternalSize();
// only check gzsize if we are actually a gzip file, just checking for
@@ -1543,7 +1543,7 @@ public:
}
return size;
}
- virtual bool InternalClose(std::string const &FileName) APT_OVERRIDE
+ bool InternalClose(std::string const &FileName) override
{
if (gz == nullptr)
return true;
@@ -1564,22 +1564,22 @@ class APT_HIDDEN Bz2FileFdPrivate: public FileFdPrivate { /*{{{*/
#ifdef HAVE_BZ2
BZFILE* bz2;
public:
- virtual bool InternalOpen(int const iFd, unsigned int const Mode) APT_OVERRIDE
- {
- if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
- bz2 = BZ2_bzdopen(iFd, "r+");
- else if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
- bz2 = BZ2_bzdopen(iFd, "w");
- else
- bz2 = BZ2_bzdopen(iFd, "r");
- filefd->Flags |= FileFd::Compressed;
- return bz2 != nullptr;
+bool InternalOpen(int const iFd, unsigned int const Mode) override
+{
+ if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
+ bz2 = BZ2_bzdopen(iFd, "r+");
+ else if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
+ bz2 = BZ2_bzdopen(iFd, "w");
+ else
+ bz2 = BZ2_bzdopen(iFd, "r");
+ filefd->Flags |= FileFd::Compressed;
+ return bz2 != nullptr;
}
- virtual ssize_t InternalUnbufferedRead(void * const To, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) override
{
return BZ2_bzread(bz2, To, Size);
}
- virtual bool InternalReadError() APT_OVERRIDE
+ bool InternalReadError() override
{
int err;
char const * const errmsg = BZ2_bzerror(bz2, &err);
@@ -1587,11 +1587,11 @@ public:
return filefd->FileFdError("BZ2_bzread: %s %s (%d: %s)", filefd->FileName.c_str(), _("Read error"), err, errmsg);
return FileFdPrivate::InternalReadError();
}
- virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalWrite(void const *const From, unsigned long long const Size) override
{
return BZ2_bzwrite(bz2, (void*)From, Size);
}
- virtual bool InternalWriteError() APT_OVERRIDE
+ bool InternalWriteError() override
{
int err;
char const * const errmsg = BZ2_bzerror(bz2, &err);
@@ -1599,8 +1599,8 @@ public:
return filefd->FileFdError("BZ2_bzwrite: %s %s (%d: %s)", filefd->FileName.c_str(), _("Write error"), err, errmsg);
return FileFdPrivate::InternalWriteError();
}
- virtual bool InternalStream() const APT_OVERRIDE { return true; }
- virtual bool InternalClose(std::string const &) APT_OVERRIDE
+ [[nodiscard]] bool InternalStream() const override { return true; }
+ bool InternalClose(std::string const &/*FileName*/) override
{
if (bz2 == nullptr)
return true;
@@ -1626,40 +1626,42 @@ class APT_HIDDEN Lz4FileFdPrivate: public FileFdPrivate { /*{{{*/
// Count of bytes that the decompressor expects to read next, or buffer size.
size_t next_to_load = APT_BUFFER_SIZE;
public:
- virtual bool InternalOpen(int const iFd, unsigned int const Mode) APT_OVERRIDE
+bool InternalOpen(int const iFd, unsigned int const Mode) override
+{
+ if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
+ return _error->Error("lz4 only supports write or read mode");
+
+ if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
{
- if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
- return _error->Error("lz4 only supports write or read mode");
+ res = LZ4F_createCompressionContext(&cctx, LZ4F_VERSION);
+ lz4_buffer.reset(LZ4F_compressBound(APT_BUFFER_SIZE, nullptr) + LZ4_HEADER_SIZE + LZ4_FOOTER_SIZE);
+ }
+ else
+ {
+ res = LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION);
+ lz4_buffer.reset(APT_BUFFER_SIZE);
+ }
- if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly) {
- res = LZ4F_createCompressionContext(&cctx, LZ4F_VERSION);
- lz4_buffer.reset(LZ4F_compressBound(APT_BUFFER_SIZE, nullptr)
- + LZ4_HEADER_SIZE + LZ4_FOOTER_SIZE);
- } else {
- res = LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION);
- lz4_buffer.reset(APT_BUFFER_SIZE);
- }
+ filefd->Flags |= FileFd::Compressed;
- filefd->Flags |= FileFd::Compressed;
+ if (LZ4F_isError(res))
+ return false;
- if (LZ4F_isError(res))
- return false;
+ unsigned int flags = (Mode & (FileFd::WriteOnly | FileFd::ReadOnly));
+ if (backend.OpenDescriptor(iFd, flags, FileFd::None, true) == false)
+ return false;
- unsigned int flags = (Mode & (FileFd::WriteOnly|FileFd::ReadOnly));
- if (backend.OpenDescriptor(iFd, flags, FileFd::None, true) == false)
+ // Write the file header
+ if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
+ {
+ res = LZ4F_compressBegin(cctx, lz4_buffer.buffer, lz4_buffer.buffersize_max, nullptr);
+ if (LZ4F_isError(res) || backend.Write(lz4_buffer.buffer, res) == false)
return false;
+ }
- // Write the file header
- if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
- {
- res = LZ4F_compressBegin(cctx, lz4_buffer.buffer, lz4_buffer.buffersize_max, nullptr);
- if (LZ4F_isError(res) || backend.Write(lz4_buffer.buffer, res) == false)
- return false;
- }
-
- return true;
+ return true;
}
- virtual ssize_t InternalUnbufferedRead(void * const To, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) override
{
/* Keep reading as long as the compressor still wants to read */
while (next_to_load) {
@@ -1697,13 +1699,13 @@ public:
return 0;
}
- virtual bool InternalReadError() APT_OVERRIDE
+ bool InternalReadError() override
{
char const * const errmsg = LZ4F_getErrorName(res);
return filefd->FileFdError("LZ4F: %s %s (%zu: %s)", filefd->FileName.c_str(), _("Read error"), res, errmsg);
}
- virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalWrite(void const *const From, unsigned long long const Size) override
{
unsigned long long const towrite = std::min(APT_BUFFER_SIZE, Size);
@@ -1716,20 +1718,20 @@ public:
return towrite;
}
- virtual bool InternalWriteError() APT_OVERRIDE
+ bool InternalWriteError() override
{
char const * const errmsg = LZ4F_getErrorName(res);
return filefd->FileFdError("LZ4F: %s %s (%zu: %s)", filefd->FileName.c_str(), _("Write error"), res, errmsg);
}
- virtual bool InternalStream() const APT_OVERRIDE { return true; }
+ [[nodiscard]] bool InternalStream() const override { return true; }
- virtual bool InternalFlush() APT_OVERRIDE
+ bool InternalFlush() override
{
return backend.Flush();
}
- virtual bool InternalClose(std::string const &) APT_OVERRIDE
+ bool InternalClose(std::string const &/*FileName*/) override
{
/* Reset variables */
res = 0;
@@ -1785,7 +1787,7 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate /*{{{*/
size_t next_to_load = APT_BUFFER_SIZE;
public:
- virtual bool InternalOpen(int const iFd, unsigned int const Mode) APT_OVERRIDE
+ bool InternalOpen(int const iFd, unsigned int const Mode) override
{
if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
return _error->Error("zstd only supports write or read mode");
@@ -1814,7 +1816,7 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate /*{{{*/
return true;
}
- virtual ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) override
{
/* Keep reading as long as the compressor still wants to read */
while (true)
@@ -1872,13 +1874,13 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate /*{{{*/
return 0;
}
- virtual bool InternalReadError() APT_OVERRIDE
+ bool InternalReadError() override
{
char const *const errmsg = ZSTD_getErrorName(res);
return filefd->FileFdError("ZSTD: %s %s (%zu: %s)", filefd->FileName.c_str(), _("Read error"), res, errmsg);
}
- virtual ssize_t InternalWrite(void const *const From, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalWrite(void const *const From, unsigned long long const Size) override
{
// Drain compressed buffer as far as possible.
ZSTD_outBuffer out = {
@@ -1900,20 +1902,20 @@ class APT_HIDDEN ZstdFileFdPrivate : public FileFdPrivate /*{{{*/
return in.pos;
}
- virtual bool InternalWriteError() APT_OVERRIDE
+ bool InternalWriteError() override
{
char const *const errmsg = ZSTD_getErrorName(res);
return filefd->FileFdError("ZSTD: %s %s (%zu: %s)", filefd->FileName.c_str(), _("Write error"), res, errmsg);
}
- virtual bool InternalStream() const APT_OVERRIDE { return true; }
+ [[nodiscard]] bool InternalStream() const override { return true; }
- virtual bool InternalFlush() APT_OVERRIDE
+ bool InternalFlush() override
{
return backend.Flush();
}
- virtual bool InternalClose(std::string const &) APT_OVERRIDE
+ bool InternalClose(std::string const &/*FileName*/) override
{
/* Reset variables */
res = 0;
@@ -2052,51 +2054,51 @@ class APT_HIDDEN LzmaFileFdPrivate: public FileFdPrivate { /*{{{*/
return 6;
}
public:
- virtual bool InternalOpen(int const iFd, unsigned int const Mode) APT_OVERRIDE
- {
- if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
- return filefd->FileFdError("ReadWrite mode is not supported for lzma/xz files %s", filefd->FileName.c_str());
+bool InternalOpen(int const iFd, unsigned int const Mode) override
+{
+ if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
+ return filefd->FileFdError("ReadWrite mode is not supported for lzma/xz files %s", filefd->FileName.c_str());
- if (lzma == nullptr)
- lzma = new LzmaFileFdPrivate::LZMAFILE(filefd);
- if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
- lzma->file = fdopen(iFd, "w");
- else
- lzma->file = fdopen(iFd, "r");
- filefd->Flags |= FileFd::Compressed;
- if (lzma->file == nullptr)
- return false;
+ if (lzma == nullptr)
+ lzma = new LzmaFileFdPrivate::LZMAFILE(filefd);
+ if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
+ lzma->file = fdopen(iFd, "w");
+ else
+ lzma->file = fdopen(iFd, "r");
+ filefd->Flags |= FileFd::Compressed;
+ if (lzma->file == nullptr)
+ return false;
- lzma_stream tmp_stream = LZMA_STREAM_INIT;
- lzma->stream = tmp_stream;
+ lzma_stream tmp_stream = LZMA_STREAM_INIT;
+ lzma->stream = tmp_stream;
- if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
+ if ((Mode & FileFd::WriteOnly) == FileFd::WriteOnly)
+ {
+ uint32_t const xzlevel = findXZlevel(compressor.CompressArgs);
+ if (compressor.Name == "xz")
{
- uint32_t const xzlevel = findXZlevel(compressor.CompressArgs);
- if (compressor.Name == "xz")
- {
- if (lzma_easy_encoder(&lzma->stream, xzlevel, LZMA_CHECK_CRC64) != LZMA_OK)
- return false;
- }
- else
- {
- lzma_options_lzma options;
- lzma_lzma_preset(&options, xzlevel);
- if (lzma_alone_encoder(&lzma->stream, &options) != LZMA_OK)
- return false;
- }
- lzma->compressing = true;
+ if (lzma_easy_encoder(&lzma->stream, xzlevel, LZMA_CHECK_CRC64) != LZMA_OK)
+ return false;
}
else
{
- uint64_t constexpr memlimit = 1024 * 1024 * 500;
- if (lzma_auto_decoder(&lzma->stream, memlimit, 0) != LZMA_OK)
+ lzma_options_lzma options;
+ lzma_lzma_preset(&options, xzlevel);
+ if (lzma_alone_encoder(&lzma->stream, &options) != LZMA_OK)
return false;
- lzma->compressing = false;
}
- return true;
+ lzma->compressing = true;
+ }
+ else
+ {
+ uint64_t constexpr memlimit = 1024 * 1024 * 500;
+ if (lzma_auto_decoder(&lzma->stream, memlimit, 0) != LZMA_OK)
+ return false;
+ lzma->compressing = false;
+ }
+ return true;
}
- virtual ssize_t InternalUnbufferedRead(void * const To, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) override
{
ssize_t Res;
if (lzma->eof == true)
@@ -2132,11 +2134,11 @@ public:
}
return Res;
}
- virtual bool InternalReadError() APT_OVERRIDE
+ bool InternalReadError() override
{
return filefd->FileFdError("lzma_read: %s (%d)", _("Read error"), lzma->err);
}
- virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalWrite(void const *const From, unsigned long long const Size) override
{
ssize_t Res;
lzma->stream.next_in = (uint8_t *)From;
@@ -2165,12 +2167,12 @@ public:
}
return Res;
}
- virtual bool InternalWriteError() APT_OVERRIDE
+ bool InternalWriteError() override
{
return filefd->FileFdError("lzma_write: %s (%d)", _("Write error"), lzma->err);
}
- virtual bool InternalStream() const APT_OVERRIDE { return true; }
- virtual bool InternalClose(std::string const &) APT_OVERRIDE
+ [[nodiscard]] bool InternalStream() const override { return true; }
+ bool InternalClose(std::string const &/*FileName*/) override
{
delete lzma;
lzma = nullptr;
@@ -2187,117 +2189,118 @@ class APT_HIDDEN PipedFileFdPrivate: public FileFdPrivate /*{{{*/
by executing a specified binary and pipe in/out what we need */
{
public:
- virtual bool InternalOpen(int const, unsigned int const Mode) APT_OVERRIDE
+bool InternalOpen(int const /*iFd*/, unsigned int const Mode) override
+{
+ // collect zombies here in case we reopen
+ if (compressor_pid > 0)
+ ExecWait(compressor_pid, "FileFdCompressor", true);
+
+ if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
+ return filefd->FileFdError("ReadWrite mode is not supported for file %s", filefd->FileName.c_str());
+ if (compressor.Binary == "false")
+ return filefd->FileFdError("libapt has inbuilt support for the %s compression,"
+ " but was forced to ignore it in favor of an external binary – which isn't installed.",
+ compressor.Name.c_str());
+
+ bool const Comp = (Mode & FileFd::WriteOnly) == FileFd::WriteOnly;
+ if (Comp == false && filefd->iFd != -1)
{
- // collect zombies here in case we reopen
- if (compressor_pid > 0)
- ExecWait(compressor_pid, "FileFdCompressor", true);
+ // Handle 'decompression' of empty files
+ struct stat Buf;
+ if (fstat(filefd->iFd, &Buf) != 0)
+ return filefd->FileFdErrno("fstat", "Could not stat fd %d for file %s", filefd->iFd, filefd->FileName.c_str());
+ if (Buf.st_size == 0 && S_ISFIFO(Buf.st_mode) == false)
+ return true;
- if ((Mode & FileFd::ReadWrite) == FileFd::ReadWrite)
- return filefd->FileFdError("ReadWrite mode is not supported for file %s", filefd->FileName.c_str());
- if (compressor.Binary == "false")
- return filefd->FileFdError("libapt has inbuilt support for the %s compression,"
- " but was forced to ignore it in favor of an external binary – which isn't installed.", compressor.Name.c_str());
-
- bool const Comp = (Mode & FileFd::WriteOnly) == FileFd::WriteOnly;
- if (Comp == false && filefd->iFd != -1)
- {
- // Handle 'decompression' of empty files
- struct stat Buf;
- if (fstat(filefd->iFd, &Buf) != 0)
- return filefd->FileFdErrno("fstat", "Could not stat fd %d for file %s", filefd->iFd, filefd->FileName.c_str());
- if (Buf.st_size == 0 && S_ISFIFO(Buf.st_mode) == false)
- return true;
-
- // We don't need the file open - instead let the compressor open it
- // as he properly knows better how to efficiently read from 'his' file
- if (filefd->FileName.empty() == false)
- {
- close(filefd->iFd);
- filefd->iFd = -1;
- }
+ // We don't need the file open - instead let the compressor open it
+ // as he properly knows better how to efficiently read from 'his' file
+ if (filefd->FileName.empty() == false)
+ {
+ close(filefd->iFd);
+ filefd->iFd = -1;
}
+ }
- // Create a data pipe
- int Pipe[2] = {-1,-1};
- if (pipe(Pipe) != 0)
- return filefd->FileFdErrno("pipe",_("Failed to create subprocess IPC"));
- for (int J = 0; J != 2; J++)
- SetCloseExec(Pipe[J],true);
+ // Create a data pipe
+ int Pipe[2] = {-1, -1};
+ if (pipe(Pipe) != 0)
+ return filefd->FileFdErrno("pipe", _("Failed to create subprocess IPC"));
+ for (int J = 0; J != 2; J++)
+ SetCloseExec(Pipe[J], true);
- compressed_fd = filefd->iFd;
- set_is_pipe(true);
+ compressed_fd = filefd->iFd;
+ set_is_pipe(true);
+ if (Comp == true)
+ filefd->iFd = Pipe[1];
+ else
+ filefd->iFd = Pipe[0];
+
+ // The child..
+ compressor_pid = ExecFork();
+ if (compressor_pid == 0)
+ {
if (Comp == true)
- filefd->iFd = Pipe[1];
+ {
+ dup2(compressed_fd, STDOUT_FILENO);
+ dup2(Pipe[0], STDIN_FILENO);
+ }
else
- filefd->iFd = Pipe[0];
-
- // The child..
- compressor_pid = ExecFork();
- if (compressor_pid == 0)
{
- if (Comp == true)
- {
- dup2(compressed_fd,STDOUT_FILENO);
- dup2(Pipe[0],STDIN_FILENO);
- }
- else
- {
- if (compressed_fd != -1)
- dup2(compressed_fd,STDIN_FILENO);
- dup2(Pipe[1],STDOUT_FILENO);
- }
- int const nullfd = open("/dev/null", O_WRONLY);
- if (nullfd != -1)
- {
- dup2(nullfd,STDERR_FILENO);
- close(nullfd);
- }
+ if (compressed_fd != -1)
+ dup2(compressed_fd, STDIN_FILENO);
+ dup2(Pipe[1], STDOUT_FILENO);
+ }
+ int const nullfd = open("/dev/null", O_WRONLY);
+ if (nullfd != -1)
+ {
+ dup2(nullfd, STDERR_FILENO);
+ close(nullfd);
+ }
- SetCloseExec(STDOUT_FILENO,false);
- SetCloseExec(STDIN_FILENO,false);
-
- std::vector<char const*> Args;
- Args.push_back(compressor.Binary.c_str());
- std::vector<std::string> const * const addArgs =
- (Comp == true) ? &(compressor.CompressArgs) : &(compressor.UncompressArgs);
- for (std::vector<std::string>::const_iterator a = addArgs->begin();
- a != addArgs->end(); ++a)
- Args.push_back(a->c_str());
- if (Comp == false && filefd->FileName.empty() == false)
- {
- // commands not needing arguments, do not need to be told about using standard output
- // in reality, only testcases with tools like cat, rev, rot13, … are able to trigger this
- if (compressor.CompressArgs.empty() == false && compressor.UncompressArgs.empty() == false)
- Args.push_back("--stdout");
- if (filefd->TemporaryFileName.empty() == false)
- Args.push_back(filefd->TemporaryFileName.c_str());
- else
- Args.push_back(filefd->FileName.c_str());
- }
- Args.push_back(NULL);
+ SetCloseExec(STDOUT_FILENO, false);
+ SetCloseExec(STDIN_FILENO, false);
- execvp(Args[0],(char **)&Args[0]);
- cerr << _("Failed to exec compressor ") << Args[0] << endl;
- _exit(100);
+ std::vector<char const *> Args;
+ Args.push_back(compressor.Binary.c_str());
+ std::vector<std::string> const *const addArgs =
+ (Comp == true) ? &(compressor.CompressArgs) : &(compressor.UncompressArgs);
+ for (std::vector<std::string>::const_iterator a = addArgs->begin();
+ a != addArgs->end(); ++a)
+ Args.push_back(a->c_str());
+ if (Comp == false && filefd->FileName.empty() == false)
+ {
+ // commands not needing arguments, do not need to be told about using standard output
+ // in reality, only testcases with tools like cat, rev, rot13, … are able to trigger this
+ if (compressor.CompressArgs.empty() == false && compressor.UncompressArgs.empty() == false)
+ Args.push_back("--stdout");
+ if (filefd->TemporaryFileName.empty() == false)
+ Args.push_back(filefd->TemporaryFileName.c_str());
+ else
+ Args.push_back(filefd->FileName.c_str());
}
- if (Comp == true)
- close(Pipe[0]);
- else
- close(Pipe[1]);
+ Args.push_back(NULL);
- return true;
+ execvp(Args[0], (char **)&Args[0]);
+ cerr << _("Failed to exec compressor ") << Args[0] << endl;
+ _exit(100);
}
- virtual ssize_t InternalUnbufferedRead(void * const To, unsigned long long const Size) APT_OVERRIDE
+ if (Comp == true)
+ close(Pipe[0]);
+ else
+ close(Pipe[1]);
+
+ return true;
+ }
+ ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) override
{
return read(filefd->iFd, To, Size);
}
- virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalWrite(void const *const From, unsigned long long const Size) override
{
return write(filefd->iFd, From, Size);
}
- virtual bool InternalClose(std::string const &) APT_OVERRIDE
+ bool InternalClose(std::string const &/*FileName*/) override
{
bool Ret = true;
if (filefd->iFd != -1)
@@ -2317,12 +2320,12 @@ public:
class APT_HIDDEN DirectFileFdPrivate: public FileFdPrivate /*{{{*/
{
public:
- virtual bool InternalOpen(int const, unsigned int const) APT_OVERRIDE { return true; }
- virtual ssize_t InternalUnbufferedRead(void * const To, unsigned long long const Size) APT_OVERRIDE
- {
- return read(filefd->iFd, To, Size);
+bool InternalOpen(int const /*iFd*/, unsigned int const /*Mode*/) override { return true; }
+ssize_t InternalUnbufferedRead(void *const To, unsigned long long const Size) override
+{
+ return read(filefd->iFd, To, Size);
}
- virtual ssize_t InternalWrite(void const * const From, unsigned long long const Size) APT_OVERRIDE
+ ssize_t InternalWrite(void const *const From, unsigned long long const Size) override
{
// files opened read+write are strange and only really "supported" for direct files
if (buffer.size() != 0)
@@ -2332,7 +2335,7 @@ public:
}
return write(filefd->iFd, From, Size);
}
- virtual bool InternalSeek(unsigned long long const To) APT_OVERRIDE
+ bool InternalSeek(unsigned long long const To) override
{
off_t const res = lseek(filefd->iFd, To, SEEK_SET);
if (res != (off_t)To)
@@ -2341,7 +2344,7 @@ public:
buffer.reset();
return true;
}
- virtual bool InternalSkip(unsigned long long Over) APT_OVERRIDE
+ bool InternalSkip(unsigned long long Over) override
{
if (Over >= buffer.size())
{
@@ -2361,7 +2364,7 @@ public:
seekpos = res;
return true;
}
- virtual bool InternalTruncate(unsigned long long const To) APT_OVERRIDE
+ bool InternalTruncate(unsigned long long const To) override
{
if (buffer.size() != 0)
{
@@ -2377,16 +2380,16 @@ public:
return filefd->FileFdError("Unable to truncate to %llu",To);
return true;
}
- virtual unsigned long long InternalTell() APT_OVERRIDE
+ unsigned long long InternalTell() override
{
return lseek(filefd->iFd,0,SEEK_CUR) - buffer.size();
}
- virtual unsigned long long InternalSize() APT_OVERRIDE
+ unsigned long long InternalSize() override
{
return filefd->FileSize();
}
- virtual bool InternalClose(std::string const &) APT_OVERRIDE { return true; }
- virtual bool InternalAlwaysAutoClose() const APT_OVERRIDE { return false; }
+ bool InternalClose(std::string const &/*FileName*/) override { return true; }
+ [[nodiscard]] bool InternalAlwaysAutoClose() const override { return false; }
explicit DirectFileFdPrivate(FileFd * const filefd) : FileFdPrivate(filefd) {}
virtual ~DirectFileFdPrivate() { InternalClose(""); }
diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h
index 7a4c863d7..e0c23b99b 100644
--- a/apt-pkg/contrib/macros.h
+++ b/apt-pkg/contrib/macros.h
@@ -109,12 +109,6 @@
#define APT_IGNORE_DEPRECATED(XXX) XXX
#endif
-#if __cplusplus >= 201103L
- #define APT_OVERRIDE override
-#else
- #define APT_OVERRIDE /* no c++11 standard */
-#endif
-
// These lines are extracted by the makefiles and the buildsystem
// Increasing MAJOR or MINOR results in the need of recompiling all
// reverse-dependencies of libapt-pkg against the new SONAME.
@@ -139,4 +133,14 @@ AptScopeWrapper(F) -> AptScopeWrapper<F>;
#define APT_PASTE(a, b) APT_PASTE2(a, b)
#define DEFER(lambda) AptScopeWrapper APT_PASTE(defer, __LINE__){lambda};
+
+#ifndef APT_COMPILING_APT
+#if APT_PKG_ABI <= 600
+#if __cplusplus >= 201103L
+ #define APT_OVERRIDE override
+#else
+ #define APT_OVERRIDE /* no c++11 standard */
+#endif
+#endif
+#endif
#endif
diff --git a/apt-pkg/contrib/progress.h b/apt-pkg/contrib/progress.h
index d6a698af3..7721530b8 100644
--- a/apt-pkg/contrib/progress.h
+++ b/apt-pkg/contrib/progress.h
@@ -71,12 +71,12 @@ class APT_PUBLIC OpTextProgress : public OpProgress
bool NoUpdate;
bool NoDisplay;
unsigned long LastLen;
- virtual void Update() APT_OVERRIDE;
+ void Update() override;
void Write(const char *S);
public:
- virtual void Done() APT_OVERRIDE;
+ void Done() override;
explicit OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate),
NoDisplay(false), LastLen(0) {};