diff options
| author | Julian Andres Klode <jak@debian.org> | 2025-01-14 08:26:23 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-01-14 08:26:23 +0000 |
| commit | ce452d40f499fa56f6ddc15e8871b1262d4e1418 (patch) | |
| tree | cca88ab8b56520eec386921aa51906d7bdf4f385 /apt-pkg/contrib | |
| parent | f9a59225c3b1e025ad93116773cc7825621809c8 (diff) | |
| parent | aa4c681f09f06359c0892329b9e39da77e4f9fda (diff) | |
Merge branch 'fix/cleanup' into 'main'
Drop unused and obsolete macros as well as documentation
See merge request apt-team/apt!428
Diffstat (limited to 'apt-pkg/contrib')
| -rw-r--r-- | apt-pkg/contrib/error.h | 2 | ||||
| -rw-r--r-- | apt-pkg/contrib/fileutl.cc | 471 | ||||
| -rw-r--r-- | apt-pkg/contrib/gpgv.cc | 4 | ||||
| -rw-r--r-- | apt-pkg/contrib/gpgv.h | 10 | ||||
| -rw-r--r-- | apt-pkg/contrib/macros.h | 67 | ||||
| -rw-r--r-- | apt-pkg/contrib/progress.h | 4 | ||||
| -rw-r--r-- | apt-pkg/contrib/strutl.h | 6 |
7 files changed, 281 insertions, 283 deletions
diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 792232010..f61b44b87 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -367,6 +367,6 @@ private: /*{{{*/ APT_PUBLIC GlobalError *_GetErrorObj(); static struct { inline GlobalError* operator ->() { return _GetErrorObj(); } -} _error APT_UNUSED; +} _error [[maybe_unused]]; #endif diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 67c5acee2..e57662abc 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1070,7 +1070,7 @@ struct APT_HIDDEN simple_buffer { /*{{{*/ reset(); } void reset() { bufferend = bufferstart = 0; } - ssize_t read(void *to, unsigned long long requested_size) APT_MUSTCHECK + [[nodiscard]] ssize_t read(void *to, unsigned long long requested_size) { if (size() < requested_size) requested_size = size(); @@ -1080,7 +1080,7 @@ struct APT_HIDDEN simple_buffer { /*{{{*/ bufferstart = bufferend = 0; return requested_size; } - ssize_t write(const void *from, unsigned long long requested_size) APT_MUSTCHECK + [[nodiscard]] ssize_t write(const void *from, unsigned long long requested_size) { if (free() < requested_size) requested_size = free(); @@ -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/gpgv.cc b/apt-pkg/contrib/gpgv.cc index 48d31a44c..237ddc856 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -111,8 +111,6 @@ static bool operator!=(LineBuffer const &buf, std::string_view const exp) noexce clear-signed files (=the complete content of the file is signed and the content isn't encoded) we do a divide and conquer approach here and split up the clear-signed file in message and signature for gpg. - And as a cherry on the cake, we use our apt-key wrapper to do part - of the lifting in regards to merging keyrings. Fun for the whole family. */ #define apt_error(...) apt_msg("ERROR", __VA_ARGS__) #define apt_warning(...) apt_msg("WARNING", __VA_ARGS__) @@ -290,7 +288,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, bool const Debug = _config->FindB("Debug::Acquire::gpgv", false); struct exiter { std::vector<std::string> files; - void operator ()(int code) APT_NORETURN { + [[noreturn]] void operator ()(int code) { std::for_each(files.begin(), files.end(), [](auto f) { unlink(f.c_str()); }); exit(code); diff --git a/apt-pkg/contrib/gpgv.h b/apt-pkg/contrib/gpgv.h index 0b84f6bb7..f4f0a2ac7 100644 --- a/apt-pkg/contrib/gpgv.h +++ b/apt-pkg/contrib/gpgv.h @@ -47,11 +47,11 @@ APT_PUBLIC std::pair<std::string, std::forward_list<std::string>> FindGPGV(bool * @param fd is used as a pipe for the standard output of gpgv * @param key is the specific one to be used instead of using all */ -APT_PUBLIC void ExecGPGV(std::string const &File, std::string const &FileSig, - int const &statusfd, int fd[2], std::vector<std::string> const &KeyFiles) APT_NORETURN; -APT_PUBLIC void ExecGPGV(std::string const &File, std::string const &FileSig, - int const &statusfd, int fd[2], std::string const &Key = "") APT_NORETURN; -inline APT_NORETURN void ExecGPGV(std::string const &File, std::string const &FileSig, +[[noreturn]] APT_PUBLIC void ExecGPGV(std::string const &File, std::string const &FileSig, + int const &statusfd, int fd[2], std::vector<std::string> const &KeyFiles); +[[noreturn]] APT_PUBLIC void ExecGPGV(std::string const &File, std::string const &FileSig, + int const &statusfd, int fd[2], std::string const &Key = ""); +[[noreturn]] inline void ExecGPGV(std::string const &File, std::string const &FileSig, int const &statusfd = -1) { int fd[2]; ExecGPGV(File, FileSig, statusfd, fd); diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index d6f9c2f98..60aba30f4 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -17,16 +17,6 @@ #ifndef MACROS_H #define MACROS_H -/* Useful count macro, use on an array of things and it will return the - number of items in the array */ -#define APT_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - -// Flag Macros -#define FLAG(f) (1L << (f)) -#define SETFLAG(v,f) ((v) |= FLAG(f)) -#define CLRFLAG(v,f) ((v) &=~FLAG(f)) -#define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false) - #ifdef __GNUC__ #define APT_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__) #else @@ -46,30 +36,20 @@ #endif #if APT_GCC_VERSION >= 0x0300 - #define APT_DEPRECATED __attribute__ ((deprecated)) - #define APT_DEPRECATED_MSG(X) __attribute__ ((deprecated(X))) // __attribute__((const)) is too dangerous for us, we end up using it wrongly #define APT_PURE __attribute__((pure)) - #define APT_NORETURN __attribute__((noreturn)) #define APT_PRINTF(n) __attribute__((format(printf, n, n + 1))) #define APT_WEAK __attribute__((weak)); - #define APT_UNUSED __attribute__((unused)) #else - #define APT_DEPRECATED - #define APT_DEPRECATED_MSG #define APT_PURE - #define APT_NORETURN #define APT_PRINTF(n) #define APT_WEAK - #define APT_UNUSED #endif #if APT_GCC_VERSION > 0x0302 #define APT_NONNULL(...) __attribute__((nonnull(__VA_ARGS__))) - #define APT_MUSTCHECK __attribute__((warn_unused_result)) #else #define APT_NONNULL(...) - #define APT_MUSTCHECK #endif #if APT_GCC_VERSION >= 0x0400 @@ -98,21 +78,9 @@ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #define APT_IGNORE_DEPRECATED_POP \ _Pragma("GCC diagnostic pop") - /* gcc has various problems with this shortcut, so prefer the long form */ - #define APT_IGNORE_DEPRECATED(XXX) \ - APT_IGNORE_DEPRECATED_PUSH \ - XXX \ - APT_IGNORE_DEPRECATED_POP #else #define APT_IGNORE_DEPRECATED_PUSH #define APT_IGNORE_DEPRECATED_POP - #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 @@ -135,8 +103,37 @@ struct AptScopeWrapper { }; template <class F> AptScopeWrapper(F) -> AptScopeWrapper<F>; -#define PASTE2(a, b) a##b -#define PASTE(a, b) PASTE2(a, b) -#define DEFER(lambda) AptScopeWrapper PASTE(defer, __LINE__){lambda}; +#define APT_PASTE2(a, b) a##b +#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 +#define APT_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#define FLAG(f) (1L << (f)) +#define SETFLAG(v,f) ((v) |= FLAG(f)) +#define CLRFLAG(v,f) ((v) &=~FLAG(f)) +#define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false) +#if APT_GCC_VERSION >= 0x0300 + #define APT_DEPRECATED __attribute__ ((deprecated)) + #define APT_DEPRECATED_MSG(X) __attribute__ ((deprecated(X))) + #define APT_NORETURN __attribute__((noreturn)) + #define APT_UNUSED __attribute__((unused)) + #define APT_MUSTCHECK __attribute__((warn_unused_result)) +#else + #define APT_DEPRECATED + #define APT_DEPRECATED_MSG(X) + #define APT_NORETURN + #define APT_UNUSED + #define APT_MUSTCHECK +#endif +#define APT_IGNORE_DEPRECATED(XXX) XXX +#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) {}; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 91f5fe44b..fdaa23766 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -56,7 +56,7 @@ namespace APT { APT_PUBLIC bool UTF8ToCodeset(const char *codeset, const std::string &orig, std::string *dest); APT_PUBLIC char *_strstrip(char *String); APT_PUBLIC char *_strrstrip(char *String); // right strip only -APT_DEPRECATED_MSG("Use SubstVar to avoid memory headaches") APT_PUBLIC char *_strtabexpand(char *String,size_t Len); +[[deprecated("Use SubstVar to avoid memory headaches")]] APT_PUBLIC char *_strtabexpand(char *String,size_t Len); APT_PUBLIC bool ParseQuoteWord(const char *&String,std::string &Res); APT_PUBLIC bool ParseCWord(const char *&String,std::string &Res); APT_PUBLIC std::string QuoteString(const std::string &Str,const char *Bad); @@ -97,8 +97,8 @@ APT_PUBLIC std::string TimeRFC1123(time_t Date, bool const NumericTimezone); * parsing is successful, undefined otherwise. * @return \b true if parsing was successful, otherwise \b false. */ -APT_PUBLIC bool RFC1123StrToTime(const std::string &str,time_t &time) APT_MUSTCHECK; -APT_PUBLIC bool FTPMDTMStrToTime(const char* const str,time_t &time) APT_MUSTCHECK; +[[nodiscard]] APT_PUBLIC bool RFC1123StrToTime(const std::string &str,time_t &time); +[[nodiscard, deprecated("Unused and untested in src:apt")]] APT_PUBLIC bool FTPMDTMStrToTime(const char *str, time_t &time); APT_PUBLIC std::string LookupTag(const std::string &Message,const char *Tag,const char *Default = 0); APT_PUBLIC int StringToBool(const std::string &Text,int Default = -1); APT_PUBLIC bool ReadMessages(int Fd, std::vector<std::string> &List); |
