diff options
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/arfile.cc | 160 | ||||
-rw-r--r-- | apt-pkg/contrib/arfile.h | 69 | ||||
-rw-r--r-- | apt-pkg/contrib/configuration.h | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/extracttar.cc | 306 | ||||
-rw-r--r-- | apt-pkg/contrib/extracttar.h | 60 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 26 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.h | 19 | ||||
-rw-r--r-- | apt-pkg/contrib/hashes.cc | 21 | ||||
-rw-r--r-- | apt-pkg/contrib/hashes.h | 53 | ||||
-rw-r--r-- | apt-pkg/contrib/macros.h | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/mmap.h | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/netrc.cc | 9 | ||||
-rw-r--r-- | apt-pkg/contrib/netrc.h | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/progress.h | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/sptr.h | 74 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 55 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 6 |
17 files changed, 617 insertions, 257 deletions
diff --git a/apt-pkg/contrib/arfile.cc b/apt-pkg/contrib/arfile.cc new file mode 100644 index 000000000..3fc3afedb --- /dev/null +++ b/apt-pkg/contrib/arfile.cc @@ -0,0 +1,160 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + AR File - Handle an 'AR' archive + + AR Archives have plain text headers at the start of each file + section. The headers are aligned on a 2 byte boundary. + + Information about the structure of AR files can be found in ar(5) + on a BSD system, or in the binutils source. + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include <config.h> + +#include <apt-pkg/arfile.h> +#include <apt-pkg/error.h> +#include <apt-pkg/fileutl.h> +#include <apt-pkg/strutl.h> + +#include <string> +#include <string.h> +#include <sys/types.h> + +#include <apti18n.h> + /*}}}*/ + +struct ARArchive::MemberHeader +{ + char Name[16]; + char MTime[12]; + char UID[6]; + char GID[6]; + char Mode[8]; + char Size[10]; + char Magic[2]; +}; + +// ARArchive::ARArchive - Constructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +ARArchive::ARArchive(FileFd &File) : List(0), File(File) +{ + LoadHeaders(); +} + /*}}}*/ +// ARArchive::~ARArchive - Destructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +ARArchive::~ARArchive() +{ + while (List != 0) + { + Member *Tmp = List; + List = List->Next; + delete Tmp; + } +} + /*}}}*/ +// ARArchive::LoadHeaders - Load the headers from each file /*{{{*/ +// --------------------------------------------------------------------- +/* AR files are structured with a 8 byte magic string followed by a 60 + byte plain text header then the file data, another header, data, etc */ +bool ARArchive::LoadHeaders() +{ + off_t Left = File.Size(); + + // Check the magic byte + char Magic[8]; + if (File.Read(Magic,sizeof(Magic)) == false) + return false; + if (memcmp(Magic,"!<arch>\012",sizeof(Magic)) != 0) + return _error->Error(_("Invalid archive signature")); + Left -= sizeof(Magic); + + // Read the member list + while (Left > 0) + { + MemberHeader Head; + if (File.Read(&Head,sizeof(Head)) == false) + return _error->Error(_("Error reading archive member header")); + Left -= sizeof(Head); + + // Convert all of the integer members + Member *Memb = new Member(); + if (StrToNum(Head.MTime,Memb->MTime,sizeof(Head.MTime)) == false || + StrToNum(Head.UID,Memb->UID,sizeof(Head.UID)) == false || + StrToNum(Head.GID,Memb->GID,sizeof(Head.GID)) == false || + StrToNum(Head.Mode,Memb->Mode,sizeof(Head.Mode),8) == false || + StrToNum(Head.Size,Memb->Size,sizeof(Head.Size)) == false) + { + delete Memb; + return _error->Error(_("Invalid archive member header %s"), Head.Name); + } + + // Check for an extra long name string + if (memcmp(Head.Name,"#1/",3) == 0) + { + char S[300]; + unsigned long Len; + if (StrToNum(Head.Name+3,Len,sizeof(Head.Size)-3) == false || + Len >= sizeof(S)) + { + delete Memb; + return _error->Error(_("Invalid archive member header")); + } + if (File.Read(S,Len) == false) + { + delete Memb; + return false; + } + S[Len] = 0; + Memb->Name = S; + Memb->Size -= Len; + Left -= Len; + } + else + { + unsigned int I = sizeof(Head.Name) - 1; + for (; Head.Name[I] == ' ' || Head.Name[I] == '/'; I--); + Memb->Name = std::string(Head.Name,I+1); + } + + // Account for the AR header alignment + off_t Skip = Memb->Size % 2; + + // Add it to the list + Memb->Next = List; + List = Memb; + Memb->Start = File.Tell(); + if (File.Skip(Memb->Size + Skip) == false) + return false; + if (Left < (off_t)(Memb->Size + Skip)) + return _error->Error(_("Archive is too short")); + Left -= Memb->Size + Skip; + } + if (Left != 0) + return _error->Error(_("Failed to read the archive headers")); + + return true; +} + /*}}}*/ +// ARArchive::FindMember - Find a name in the member list /*{{{*/ +// --------------------------------------------------------------------- +/* Find a member with the given name */ +const ARArchive::Member *ARArchive::FindMember(const char *Name) const +{ + const Member *Res = List; + while (Res != 0) + { + if (Res->Name == Name) + return Res; + Res = Res->Next; + } + + return 0; +} + /*}}}*/ diff --git a/apt-pkg/contrib/arfile.h b/apt-pkg/contrib/arfile.h new file mode 100644 index 000000000..cf454941e --- /dev/null +++ b/apt-pkg/contrib/arfile.h @@ -0,0 +1,69 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + AR File - Handle an 'AR' archive + + This is a reader for the usual 4.4 BSD AR format. It allows raw + stream access to a single member at a time. Basically all this class + provides is header parsing and verification. It is up to the client + to correctly make use of the stream start/stop points. + + ##################################################################### */ + /*}}}*/ +#ifndef PKGLIB_ARFILE_H +#define PKGLIB_ARFILE_H + +#include <apt-pkg/macros.h> +#include <string> +#ifndef APT_8_CLEANER_HEADERS +#include <apt-pkg/fileutl.h> +#endif + +class FileFd; + +class ARArchive +{ + struct MemberHeader; + public: + struct Member; + + protected: + + // Linked list of members + Member *List; + + bool LoadHeaders(); + + public: + + // The stream file + FileFd &File; + + // Locate a member by name + const Member *FindMember(const char *Name) const; + inline Member *Members() { return List; } + + explicit ARArchive(FileFd &File); + ~ARArchive(); +}; + +// A member of the archive +struct ARArchive::Member +{ + // Fields from the header + std::string Name; + unsigned long MTime; + unsigned long UID; + unsigned long GID; + unsigned long Mode; + unsigned long long Size; + + // Location of the data. + unsigned long long Start; + Member *Next; + + Member() : Start(0), Next(0) {}; +}; + +#endif diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 2a3ae1aa4..b5dfe721f 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -119,7 +119,7 @@ class Configuration void Dump(std::ostream& str, char const * const root, char const * const format, bool const emptyValue); - Configuration(const Item *Root); + explicit Configuration(const Item *Root); Configuration(); ~Configuration(); @@ -130,7 +130,7 @@ class Configuration APT_HIDDEN void clearPatterns(); public: - MatchAgainstConfig(char const * Config); + explicit MatchAgainstConfig(char const * Config); virtual ~MatchAgainstConfig(); /** \brief Returns \b true for a string matching one of the patterns */ diff --git a/apt-pkg/contrib/extracttar.cc b/apt-pkg/contrib/extracttar.cc new file mode 100644 index 000000000..9bb0a55c0 --- /dev/null +++ b/apt-pkg/contrib/extracttar.cc @@ -0,0 +1,306 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + Extract a Tar - Tar Extractor + + Some performance measurements showed that zlib performed quite poorly + in comparison to a forked gzip process. This tar extractor makes use + of the fact that dup'd file descriptors have the same seek pointer + and that gzip will not read past the end of a compressed stream, + even if there is more data. We use the dup property to track extraction + progress and the gzip feature to just feed gzip a fd in the middle + of an AR file. + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include <config.h> + +#include <apt-pkg/configuration.h> +#include <apt-pkg/dirstream.h> +#include <apt-pkg/error.h> +#include <apt-pkg/extracttar.h> +#include <apt-pkg/fileutl.h> +#include <apt-pkg/strutl.h> + +#include <algorithm> +#include <iostream> +#include <string> +#include <fcntl.h> +#include <signal.h> +#include <string.h> +#include <unistd.h> + +#include <apti18n.h> + /*}}}*/ + +using namespace std; + +// The on disk header for a tar file. +struct ExtractTar::TarHeader +{ + char Name[100]; + char Mode[8]; + char UserID[8]; + char GroupID[8]; + char Size[12]; + char MTime[12]; + char Checksum[8]; + char LinkFlag; + char LinkName[100]; + char MagicNumber[8]; + char UserName[32]; + char GroupName[32]; + char Major[8]; + char Minor[8]; +}; + +// ExtractTar::ExtractTar - Constructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +ExtractTar::ExtractTar(FileFd &Fd,unsigned long long Max,string DecompressionProgram) + : File(Fd), MaxInSize(Max), DecompressProg(DecompressionProgram) +{ + GZPid = -1; + Eof = false; +} + /*}}}*/ +// ExtractTar::ExtractTar - Destructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +ExtractTar::~ExtractTar() +{ + // Error close + Done(); +} + /*}}}*/ +// ExtractTar::Done - Reap the gzip sub process /*{{{*/ +bool ExtractTar::Done() +{ + return InFd.Close(); +} + /*}}}*/ +// ExtractTar::StartGzip - Startup gzip /*{{{*/ +// --------------------------------------------------------------------- +/* This creates a gzip sub process that has its input as the file itself. + If this tar file is embedded into something like an ar file then + gzip will efficiently ignore the extra bits. */ +bool ExtractTar::StartGzip() +{ + if (DecompressProg.empty()) + { + InFd.OpenDescriptor(File.Fd(), FileFd::ReadOnly, FileFd::None, false); + return true; + } + + std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors(); + std::vector<APT::Configuration::Compressor>::const_iterator compressor = compressors.begin(); + for (; compressor != compressors.end(); ++compressor) { + if (compressor->Name == DecompressProg) { + return InFd.OpenDescriptor(File.Fd(), FileFd::ReadOnly, *compressor, false); + } + } + + return _error->Error(_("Cannot find a configured compressor for '%s'"), + DecompressProg.c_str()); + +} + /*}}}*/ +// ExtractTar::Go - Perform extraction /*{{{*/ +// --------------------------------------------------------------------- +/* This reads each 512 byte block from the archive and extracts the header + information into the Item structure. Then it resolves the UID/GID and + invokes the correct processing function. */ +bool ExtractTar::Go(pkgDirStream &Stream) +{ + if (StartGzip() == false) + return false; + + // Loop over all blocks + string LastLongLink, ItemLink; + string LastLongName, ItemName; + while (1) + { + bool BadRecord = false; + unsigned char Block[512]; + if (InFd.Read(Block,sizeof(Block),true) == false) + return false; + + if (InFd.Eof() == true) + break; + + // Get the checksum + TarHeader *Tar = (TarHeader *)Block; + unsigned long CheckSum; + if (StrToNum(Tar->Checksum,CheckSum,sizeof(Tar->Checksum),8) == false) + return _error->Error(_("Corrupted archive")); + + /* Compute the checksum field. The actual checksum is blanked out + with spaces so it is not included in the computation */ + unsigned long NewSum = 0; + memset(Tar->Checksum,' ',sizeof(Tar->Checksum)); + for (int I = 0; I != sizeof(Block); I++) + NewSum += Block[I]; + + /* Check for a block of nulls - in this case we kill gzip, GNU tar + does this.. */ + if (NewSum == ' '*sizeof(Tar->Checksum)) + return Done(); + + if (NewSum != CheckSum) + return _error->Error(_("Tar checksum failed, archive corrupted")); + + // Decode all of the fields + pkgDirStream::Item Itm; + if (StrToNum(Tar->Mode,Itm.Mode,sizeof(Tar->Mode),8) == false || + (Base256ToNum(Tar->UserID,Itm.UID,8) == false && + StrToNum(Tar->UserID,Itm.UID,sizeof(Tar->UserID),8) == false) || + (Base256ToNum(Tar->GroupID,Itm.GID,8) == false && + StrToNum(Tar->GroupID,Itm.GID,sizeof(Tar->GroupID),8) == false) || + (Base256ToNum(Tar->Size,Itm.Size,12) == false && + StrToNum(Tar->Size,Itm.Size,sizeof(Tar->Size),8) == false) || + (Base256ToNum(Tar->MTime,Itm.MTime,12) == false && + StrToNum(Tar->MTime,Itm.MTime,sizeof(Tar->MTime),8) == false) || + StrToNum(Tar->Major,Itm.Major,sizeof(Tar->Major),8) == false || + StrToNum(Tar->Minor,Itm.Minor,sizeof(Tar->Minor),8) == false) + return _error->Error(_("Corrupted archive")); + + // Grab the filename and link target: use last long name if one was + // set, otherwise use the header value as-is, but remember that it may + // fill the entire 100-byte block and needs to be zero-terminated. + // See Debian Bug #689582. + if (LastLongName.empty() == false) + Itm.Name = (char *)LastLongName.c_str(); + else + Itm.Name = (char *)ItemName.assign(Tar->Name, sizeof(Tar->Name)).c_str(); + if (Itm.Name[0] == '.' && Itm.Name[1] == '/' && Itm.Name[2] != 0) + Itm.Name += 2; + + if (LastLongLink.empty() == false) + Itm.LinkTarget = (char *)LastLongLink.c_str(); + else + Itm.LinkTarget = (char *)ItemLink.assign(Tar->LinkName, sizeof(Tar->LinkName)).c_str(); + + // Convert the type over + switch (Tar->LinkFlag) + { + case NormalFile0: + case NormalFile: + Itm.Type = pkgDirStream::Item::File; + break; + + case HardLink: + Itm.Type = pkgDirStream::Item::HardLink; + break; + + case SymbolicLink: + Itm.Type = pkgDirStream::Item::SymbolicLink; + break; + + case CharacterDevice: + Itm.Type = pkgDirStream::Item::CharDevice; + break; + + case BlockDevice: + Itm.Type = pkgDirStream::Item::BlockDevice; + break; + + case Directory: + Itm.Type = pkgDirStream::Item::Directory; + break; + + case FIFO: + Itm.Type = pkgDirStream::Item::FIFO; + break; + + case GNU_LongLink: + { + unsigned long long Length = Itm.Size; + unsigned char Block[512]; + while (Length > 0) + { + if (InFd.Read(Block,sizeof(Block),true) == false) + return false; + if (Length <= sizeof(Block)) + { + LastLongLink.append(Block,Block+sizeof(Block)); + break; + } + LastLongLink.append(Block,Block+sizeof(Block)); + Length -= sizeof(Block); + } + continue; + } + + case GNU_LongName: + { + unsigned long long Length = Itm.Size; + unsigned char Block[512]; + while (Length > 0) + { + if (InFd.Read(Block,sizeof(Block),true) == false) + return false; + if (Length < sizeof(Block)) + { + LastLongName.append(Block,Block+sizeof(Block)); + break; + } + LastLongName.append(Block,Block+sizeof(Block)); + Length -= sizeof(Block); + } + continue; + } + + default: + BadRecord = true; + _error->Warning(_("Unknown TAR header type %u, member %s"),(unsigned)Tar->LinkFlag,Tar->Name); + break; + } + + int Fd = -1; + if (BadRecord == false) + if (Stream.DoItem(Itm,Fd) == false) + return false; + + // Copy the file over the FD + unsigned long long Size = Itm.Size; + while (Size != 0) + { + unsigned char Junk[32*1024]; + unsigned long Read = min(Size, (unsigned long long)sizeof(Junk)); + if (InFd.Read(Junk,((Read+511)/512)*512) == false) + return false; + + if (BadRecord == false) + { + if (Fd > 0) + { + if (write(Fd,Junk,Read) != (signed)Read) + return Stream.Fail(Itm,Fd); + } + else + { + /* An Fd of -2 means to send to a special processing + function */ + if (Fd == -2) + if (Stream.Process(Itm,Junk,Read,Itm.Size - Size) == false) + return Stream.Fail(Itm,Fd); + } + } + + Size -= Read; + } + + // And finish up + if (BadRecord == false) + if (Stream.FinishedFile(Itm,Fd) == false) + return false; + + LastLongName.erase(); + LastLongLink.erase(); + } + + return Done(); +} + /*}}}*/ diff --git a/apt-pkg/contrib/extracttar.h b/apt-pkg/contrib/extracttar.h new file mode 100644 index 000000000..adde21352 --- /dev/null +++ b/apt-pkg/contrib/extracttar.h @@ -0,0 +1,60 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + Extract a Tar - Tar Extractor + + The tar extractor takes an ordinary gzip compressed tar stream from + the given file and explodes it, passing the individual items to the + given Directory Stream for processing. + + ##################################################################### */ + /*}}}*/ +#ifndef PKGLIB_EXTRACTTAR_H +#define PKGLIB_EXTRACTTAR_H + +#include <apt-pkg/fileutl.h> +#include <apt-pkg/macros.h> + +#include <string> + +#ifndef APT_8_CLEANER_HEADERS +#include <apt-pkg/dirstream.h> +#include <algorithm> +using std::min; +#endif + +class pkgDirStream; + +class ExtractTar +{ + protected: + + struct TarHeader; + + // The varios types items can be + enum ItemType {NormalFile0 = '\0',NormalFile = '0',HardLink = '1', + SymbolicLink = '2',CharacterDevice = '3', + BlockDevice = '4',Directory = '5',FIFO = '6', + GNU_LongLink = 'K',GNU_LongName = 'L'}; + + FileFd &File; + unsigned long long MaxInSize; + int GZPid; + FileFd InFd; + bool Eof; + std::string DecompressProg; + + // Fork and reap gzip + bool StartGzip(); + bool Done(); + + public: + + bool Go(pkgDirStream &Stream); + + ExtractTar(FileFd &Fd,unsigned long long Max,std::string DecompressionProgram); + virtual ~ExtractTar(); +}; + +#endif diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 4f123491b..798636647 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -25,7 +25,6 @@ #include <apt-pkg/fileutl.h> #include <apt-pkg/macros.h> #include <apt-pkg/pkgsystem.h> -#include <apt-pkg/sptr.h> #include <apt-pkg/strutl.h> #include <cstdio> @@ -1948,7 +1947,7 @@ class APT_HIDDEN LzmaFileFdPrivate: public FileFdPrivate { /*{{{*/ bool eof; bool compressing; - LZMAFILE(FileFd * const fd) : file(nullptr), filefd(fd), eof(false), compressing(false) { buffer[0] = '\0'; } + explicit LZMAFILE(FileFd * const fd) : file(nullptr), filefd(fd), eof(false), compressing(false) { buffer[0] = '\0'; } ~LZMAFILE() { if (compressing == true && filefd->Failed() == false) @@ -3018,19 +3017,6 @@ bool FileFd::FileFdError(const char *Description,...) { return false; } /*}}}*/ -gzFile FileFd::gzFd() { /*{{{*/ -#ifdef HAVE_ZLIB - GzipFileFdPrivate * const gzipd = dynamic_cast<GzipFileFdPrivate*>(d); - if (gzipd == nullptr) - return nullptr; - else - return gzipd->gz; -#else - return nullptr; -#endif -} - /*}}}*/ - // Glob - wrapper around "glob()" /*{{{*/ std::vector<std::string> Glob(std::string const &pattern, int flags) { @@ -3153,16 +3139,6 @@ bool Rename(std::string From, std::string To) /*{{{*/ return true; } /*}}}*/ -bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode)/*{{{*/ -{ - return Popen(Args, Fd, Child, Mode, true); -} - /*}}}*/ -bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode, bool CaptureStderr)/*{{{*/ -{ - return Popen(Args, Fd, Child, Mode, CaptureStderr, false); -} - /*}}}*/ bool Popen(const char *Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode, bool CaptureStderr, bool Sandbox) /*{{{*/ { int fd; diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 9005b81b5..cc0191192 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -133,20 +133,6 @@ class FileFd unsigned long long FileSize(); time_t ModificationTime(); - /* You want to use 'unsigned long long' if you are talking about a file - to be able to support large files (>2 or >4 GB) properly. - This shouldn't happen all to often for the indexes, but deb's might be… - And as the auto-conversation converts a 'unsigned long *' to a 'bool' - instead of 'unsigned long long *' we need to provide this explicitly - - otherwise applications magically start to fail… */ - bool Read(void *To,unsigned long long Size,unsigned long *Actual) APT_DEPRECATED_MSG("The Actual variable you pass in should be an unsigned long long") - { - unsigned long long R; - bool const T = Read(To, Size, &R); - *Actual = R; - return T; - } - bool Open(std::string FileName,unsigned int const Mode,CompressMode Compress,unsigned long const AccessMode = 0666); bool Open(std::string FileName,unsigned int const Mode,APT::Configuration::Compressor const &compressor,unsigned long const AccessMode = 0666); inline bool Open(std::string const &FileName,unsigned int const Mode, unsigned long const AccessMode = 0666) { @@ -163,7 +149,6 @@ class FileFd // Simple manipulators inline int Fd() {return iFd;}; inline void Fd(int fd) { OpenDescriptor(fd, ReadWrite);}; - gzFile gzFd() APT_DEPRECATED_MSG("Implementation detail, do not use to be able to support bzip2, xz and co") APT_PURE; inline bool IsOpen() {return iFd >= 0;}; inline bool Failed() {return (Flags & Fail) == Fail;}; @@ -294,9 +279,7 @@ std::vector<std::string> Glob(std::string const &pattern, int flags=0); * \param Sandbox True if this should run sandboxed * \return true on success, false on failure with _error set */ -bool Popen(const char *Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode, bool CaptureStderr, bool Sandbox) APT_HIDDEN; -bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode, bool CaptureStderr); -bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode); +bool Popen(const char *Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode, bool CaptureStderr = true, bool Sandbox = false); APT_HIDDEN bool OpenConfigurationFileFd(std::string const &File, FileFd &Fd); diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 98b92cc81..d03fb6083 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -312,7 +312,6 @@ bool Hashes::Add(const unsigned char * const Data, unsigned long long const Size if (Size == 0) return true; bool Res = true; -APT_IGNORE_DEPRECATED_PUSH if ((d->CalcHashes & MD5SUM) == MD5SUM) Res &= MD5.Add(Data, Size); if ((d->CalcHashes & SHA1SUM) == SHA1SUM) @@ -321,15 +320,9 @@ APT_IGNORE_DEPRECATED_PUSH Res &= SHA256.Add(Data, Size); if ((d->CalcHashes & SHA512SUM) == SHA512SUM) Res &= SHA512.Add(Data, Size); -APT_IGNORE_DEPRECATED_POP d->FileSize += Size; return Res; } -bool Hashes::Add(const unsigned char * const Data, unsigned long long const Size, unsigned int const Hashes) -{ - d->CalcHashes = Hashes; - return Add(Data, Size); -} bool Hashes::AddFD(int const Fd,unsigned long long Size) { unsigned char Buf[64*64]; @@ -349,11 +342,6 @@ bool Hashes::AddFD(int const Fd,unsigned long long Size) } return true; } -bool Hashes::AddFD(int const Fd,unsigned long long Size, unsigned int const Hashes) -{ - d->CalcHashes = Hashes; - return AddFD(Fd, Size); -} bool Hashes::AddFD(FileFd &Fd,unsigned long long Size) { unsigned char Buf[64*64]; @@ -378,16 +366,10 @@ bool Hashes::AddFD(FileFd &Fd,unsigned long long Size) } return true; } -bool Hashes::AddFD(FileFd &Fd,unsigned long long Size, unsigned int const Hashes) -{ - d->CalcHashes = Hashes; - return AddFD(Fd, Size); -} /*}}}*/ HashStringList Hashes::GetHashStringList() { HashStringList hashes; -APT_IGNORE_DEPRECATED_PUSH if ((d->CalcHashes & MD5SUM) == MD5SUM) hashes.push_back(HashString("MD5Sum", MD5.Result().Value())); if ((d->CalcHashes & SHA1SUM) == SHA1SUM) @@ -396,13 +378,10 @@ APT_IGNORE_DEPRECATED_PUSH hashes.push_back(HashString("SHA256", SHA256.Result().Value())); if ((d->CalcHashes & SHA512SUM) == SHA512SUM) hashes.push_back(HashString("SHA512", SHA512.Result().Value())); -APT_IGNORE_DEPRECATED_POP hashes.FileSize(d->FileSize); return hashes; } -APT_IGNORE_DEPRECATED_PUSH Hashes::Hashes() : d(new PrivateHashes(~0)) { } Hashes::Hashes(unsigned int const Hashes) : d(new PrivateHashes(Hashes)) {} Hashes::Hashes(HashStringList const &Hashes) : d(new PrivateHashes(Hashes)) {} Hashes::~Hashes() { delete d; } -APT_IGNORE_DEPRECATED_POP diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h index 28bfd3459..c636852ec 100644 --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@ -47,14 +47,12 @@ class HashString public: HashString(std::string Type, std::string Hash); - HashString(std::string StringedHashString); // init from str as "type:hash" + explicit HashString(std::string StringedHashString); // init from str as "type:hash" HashString(); // get hash type used std::string HashType() const { return Type; }; std::string HashValue() const { return Hash; }; - APT_DEPRECATED_MSG("method was const-ified") std::string HashType() { return Type; }; - APT_DEPRECATED_MSG("method was const-ified") std::string HashValue() { return Hash; }; // verify the given filename against the currently loaded hash bool VerifyFile(std::string filename) const; @@ -165,11 +163,11 @@ class HashStringList HashStringList() {} // simplifying API-compatibility constructors - HashStringList(std::string const &hash) { + explicit HashStringList(std::string const &hash) { if (hash.empty() == false) list.push_back(HashString(hash)); } - HashStringList(char const * const hash) { + explicit HashStringList(char const * const hash) { if (hash != NULL && hash[0] != '\0') list.push_back(HashString(hash)); } @@ -182,19 +180,17 @@ class PrivateHashes; class Hashes { PrivateHashes * const d; - - public: - /* those will disappear in the future as it is hard to add new ones this way. + /* TODO: those will disappear in the future as it is hard to add new ones this way. * Use Add* to build the results and get them via GetHashStringList() instead */ - APT_DEPRECATED_MSG("Use general .Add* and .GetHashStringList methods instead of hardcoding specific hashes") MD5Summation MD5; - APT_DEPRECATED_MSG("Use general .Add* and .GetHashStringList methods instead of hardcoding specific hashes") SHA1Summation SHA1; - APT_DEPRECATED_MSG("Use general .Add* and .GetHashStringList methods instead of hardcoding specific hashes") SHA256Summation SHA256; - APT_DEPRECATED_MSG("Use general .Add* and .GetHashStringList methods instead of hardcoding specific hashes") SHA512Summation SHA512; + MD5Summation MD5; + SHA1Summation SHA1; + SHA256Summation SHA256; + SHA512Summation SHA512; + public: static const int UntilEOF = 0; bool Add(const unsigned char * const Data, unsigned long long const Size) APT_NONNULL(2); - APT_DEPRECATED_MSG("Construct accordingly instead of choosing hashes while adding") bool Add(const unsigned char * const Data, unsigned long long const Size, unsigned int const Hashes) APT_NONNULL(2); inline bool Add(const char * const Data) APT_NONNULL(2) {return Add(reinterpret_cast<unsigned char const *>(Data),strlen(Data));}; inline bool Add(const unsigned char * const Beg,const unsigned char * const End) APT_NONNULL(2,3) @@ -203,13 +199,10 @@ class Hashes enum SupportedHashes { MD5SUM = (1 << 0), SHA1SUM = (1 << 1), SHA256SUM = (1 << 2), SHA512SUM = (1 << 3) }; bool AddFD(int const Fd,unsigned long long Size = 0); - APT_DEPRECATED_MSG("Construct accordingly instead of choosing hashes while adding") bool AddFD(int const Fd,unsigned long long Size, unsigned int const Hashes); bool AddFD(FileFd &Fd,unsigned long long Size = 0); - APT_DEPRECATED_MSG("Construct accordingly instead of choosing hashes while adding") bool AddFD(FileFd &Fd,unsigned long long Size, unsigned int const Hashes); HashStringList GetHashStringList(); -APT_IGNORE_DEPRECATED_PUSH /** create a Hashes object to calculate all supported hashes * * If ALL is too much, you can limit which Hashes are calculated @@ -217,34 +210,10 @@ APT_IGNORE_DEPRECATED_PUSH * which hashes to generate. */ Hashes(); /** @param Hashes bitflag composed of #SupportedHashes */ - Hashes(unsigned int const Hashes); + explicit Hashes(unsigned int const Hashes); /** @param Hashes is a list of hashes */ - Hashes(HashStringList const &Hashes); + explicit Hashes(HashStringList const &Hashes); virtual ~Hashes(); -APT_IGNORE_DEPRECATED_POP - - private: - APT_HIDDEN APT_PURE inline unsigned int boolsToFlag(bool const addMD5, bool const addSHA1, bool const addSHA256, bool const addSHA512) - { - unsigned int hashes = ~0; - if (addMD5 == false) hashes &= ~MD5SUM; - if (addSHA1 == false) hashes &= ~SHA1SUM; - if (addSHA256 == false) hashes &= ~SHA256SUM; - if (addSHA512 == false) hashes &= ~SHA512SUM; - return hashes; - } - - public: -APT_IGNORE_DEPRECATED_PUSH - APT_DEPRECATED_MSG("Construct accordingly instead of choosing hashes while adding") bool AddFD(int const Fd, unsigned long long Size, bool const addMD5, - bool const addSHA1, bool const addSHA256, bool const addSHA512) { - return AddFD(Fd, Size, boolsToFlag(addMD5, addSHA1, addSHA256, addSHA512)); - }; - APT_DEPRECATED_MSG("Construct accordingly instead of choosing hashes while adding") bool AddFD(FileFd &Fd, unsigned long long Size, bool const addMD5, - bool const addSHA1, bool const addSHA256, bool const addSHA512) { - return AddFD(Fd, Size, boolsToFlag(addMD5, addSHA1, addSHA256, addSHA512)); - }; -APT_IGNORE_DEPRECATED_POP }; #endif diff --git a/apt-pkg/contrib/macros.h b/apt-pkg/contrib/macros.h index 57d3f6c22..3648390ce 100644 --- a/apt-pkg/contrib/macros.h +++ b/apt-pkg/contrib/macros.h @@ -166,8 +166,8 @@ // Non-ABI-Breaks should only increase RELEASE number. // See also buildlib/libversion.mak #define APT_PKG_MAJOR 5 -#define APT_PKG_MINOR 0 -#define APT_PKG_RELEASE 2 +#define APT_PKG_MINOR 90 +#define APT_PKG_RELEASE 0 #define APT_PKG_ABI ((APT_PKG_MAJOR * 100) + APT_PKG_MINOR) #endif diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h index 63d54d27c..3af1f47fb 100644 --- a/apt-pkg/contrib/mmap.h +++ b/apt-pkg/contrib/mmap.h @@ -74,7 +74,7 @@ class MMap bool Sync(unsigned long Start,unsigned long Stop); MMap(FileFd &F,unsigned long Flags); - MMap(unsigned long Flags); + explicit MMap(unsigned long Flags); virtual ~MMap(); }; diff --git a/apt-pkg/contrib/netrc.cc b/apt-pkg/contrib/netrc.cc index 48114ba3c..ee1996f8d 100644 --- a/apt-pkg/contrib/netrc.cc +++ b/apt-pkg/contrib/netrc.cc @@ -142,15 +142,6 @@ bool MaybeAddAuth(FileFd &NetRCFile, URI &Uri) return false; } -void maybe_add_auth(URI &Uri, std::string NetRCFile) -{ - if (FileExists(NetRCFile) == false) - return; - FileFd fd; - if (fd.Open(NetRCFile, FileFd::ReadOnly)) - MaybeAddAuth(fd, Uri); -} - /* Check if we are authorized. */ bool IsAuthorized(pkgCache::PkgFileIterator const I, std::vector<std::unique_ptr<FileFd>> &authconfs) { diff --git a/apt-pkg/contrib/netrc.h b/apt-pkg/contrib/netrc.h index 80d95acc1..96a5a0973 100644 --- a/apt-pkg/contrib/netrc.h +++ b/apt-pkg/contrib/netrc.h @@ -32,8 +32,6 @@ class URI; class FileFd; -APT_DEPRECATED_MSG("Use FileFd-based MaybeAddAuth instead") -void maybe_add_auth(URI &Uri, std::string NetRCFile); bool MaybeAddAuth(FileFd &NetRCFile, URI &Uri); bool IsAuthorized(pkgCache::PkgFileIterator const I, std::vector<std::unique_ptr<FileFd>> &authconfs) APT_HIDDEN; #endif diff --git a/apt-pkg/contrib/progress.h b/apt-pkg/contrib/progress.h index 4406a388b..903e6613e 100644 --- a/apt-pkg/contrib/progress.h +++ b/apt-pkg/contrib/progress.h @@ -80,9 +80,9 @@ class OpTextProgress : public OpProgress virtual void Done() APT_OVERRIDE; - OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate), + explicit OpTextProgress(bool NoUpdate = false) : NoUpdate(NoUpdate), NoDisplay(false), LastLen(0) {}; - OpTextProgress(Configuration &Config); + explicit OpTextProgress(Configuration &Config); virtual ~OpTextProgress() {Done();}; }; diff --git a/apt-pkg/contrib/sptr.h b/apt-pkg/contrib/sptr.h deleted file mode 100644 index 77806d94d..000000000 --- a/apt-pkg/contrib/sptr.h +++ /dev/null @@ -1,74 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/* ###################################################################### - - Trivial non-ref counted 'smart pointer' - - This is really only good to eliminate - { - delete Foo; - return; - } - - Blocks from functions. - - I think G++ has become good enough that doing this won't have much - code size implications. - - ##################################################################### */ - /*}}}*/ -#ifndef SMART_POINTER_H -#define SMART_POINTER_H -#include <apt-pkg/macros.h> - -template <class T> -class APT_DEPRECATED_MSG("use std::unique_ptr instead") SPtr -{ - public: - T *Ptr; - - inline T *operator ->() {return Ptr;}; - inline T &operator *() {return *Ptr;}; - inline operator T *() {return Ptr;}; - inline operator void *() {return Ptr;}; - inline T *UnGuard() {T *Tmp = Ptr; Ptr = 0; return Tmp;}; - inline void operator =(T *N) {Ptr = N;}; - inline bool operator ==(T *lhs) const {return Ptr == lhs;}; - inline bool operator !=(T *lhs) const {return Ptr != lhs;}; - inline T*Get() {return Ptr;}; - - inline SPtr(T *Ptr) : Ptr(Ptr) {}; - inline SPtr() : Ptr(0) {}; - inline ~SPtr() {delete Ptr;}; -}; - -template <class T> -class APT_DEPRECATED_MSG("use std::unique_ptr instead") SPtrArray -{ - public: - T *Ptr; - - //inline T &operator *() {return *Ptr;}; - inline operator T *() {return Ptr;}; - inline operator void *() {return Ptr;}; - inline T *UnGuard() {T *Tmp = Ptr; Ptr = 0; return Tmp;}; - //inline T &operator [](signed long I) {return Ptr[I];}; - inline void operator =(T *N) {Ptr = N;}; - inline bool operator ==(T *lhs) const {return Ptr == lhs;}; - inline bool operator !=(T *lhs) const {return Ptr != lhs;}; - inline T *Get() {return Ptr;}; - - inline SPtrArray(T *Ptr) : Ptr(Ptr) {}; - inline SPtrArray() : Ptr(0) {}; -#if __GNUC__ >= 4 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" - // gcc warns about this, but we can do nothing here… -#endif - inline ~SPtrArray() {delete [] Ptr;}; -#if __GNUC__ >= 4 - #pragma GCC diagnostic pop -#endif -}; - -#endif diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 50344d1fe..e854c5bf1 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -806,10 +806,6 @@ int StringToBool(const string &Text,int Default) // --------------------------------------------------------------------- /* This converts a time_t into a string time representation that is year 2000 compliant and timezone neutral */ -string TimeRFC1123(time_t Date) -{ - return TimeRFC1123(Date, false); -} string TimeRFC1123(time_t Date, bool const NumericTimezone) { struct tm Conv; @@ -1099,57 +1095,6 @@ bool FTPMDTMStrToTime(const char* const str,time_t &time) return true; } /*}}}*/ -// StrToTime - Converts a string into a time_t /*{{{*/ -// --------------------------------------------------------------------- -/* This handles all 3 popular time formats including RFC 1123, RFC 1036 - and the C library asctime format. It requires the GNU library function - 'timegm' to convert a struct tm in UTC to a time_t. For some bizzar - reason the C library does not provide any such function :< This also - handles the weird, but unambiguous FTP time format*/ -bool StrToTime(const string &Val,time_t &Result) -{ - struct tm Tm; - char Month[10]; - - // Skip the day of the week - const char *I = strchr(Val.c_str(), ' '); - - // Handle RFC 1123 time - Month[0] = 0; - if (sscanf(I," %2d %3s %4d %2d:%2d:%2d GMT",&Tm.tm_mday,Month,&Tm.tm_year, - &Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec) != 6) - { - // Handle RFC 1036 time - if (sscanf(I," %2d-%3s-%3d %2d:%2d:%2d GMT",&Tm.tm_mday,Month, - &Tm.tm_year,&Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec) == 6) - Tm.tm_year += 1900; - else - { - // asctime format - if (sscanf(I," %3s %2d %2d:%2d:%2d %4d",Month,&Tm.tm_mday, - &Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec,&Tm.tm_year) != 6) - { - // 'ftp' time - if (sscanf(Val.c_str(),"%4d%2d%2d%2d%2d%2d",&Tm.tm_year,&Tm.tm_mon, - &Tm.tm_mday,&Tm.tm_hour,&Tm.tm_min,&Tm.tm_sec) != 6) - return false; - Tm.tm_mon--; - } - } - } - - Tm.tm_isdst = 0; - if (Month[0] != 0) - Tm.tm_mon = MonthConv(Month); - else - Tm.tm_mon = 0; // we don't have a month, so pick something - Tm.tm_year -= 1900; - - // Convert to local time and then to GMT - Result = timegm(&Tm); - return true; -} - /*}}}*/ // StrToNum - Convert a fixed length string to a number /*{{{*/ // --------------------------------------------------------------------- /* This is used in decoding the crazy fixed length string headers in diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 9f74f8c2a..ae0aaedf9 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -66,7 +66,6 @@ std::string TimeToStr(unsigned long Sec); std::string Base64Encode(const std::string &Str); std::string OutputInDepth(const unsigned long Depth, const char* Separator=" "); std::string URItoFileName(const std::string &URI); -APT_DEPRECATED_MSG("Specify if GMT is required or a numeric timezone can be used") std::string TimeRFC1123(time_t Date); /** returns a datetime string as needed by HTTP/1.1 and Debian files. * * Note: The date will always be represented in a UTC timezone @@ -94,7 +93,6 @@ std::string TimeRFC1123(time_t Date, bool const NumericTimezone); */ bool RFC1123StrToTime(const char* const str,time_t &time) APT_MUSTCHECK; bool FTPMDTMStrToTime(const char* const str,time_t &time) APT_MUSTCHECK; -APT_DEPRECATED_MSG("Use RFC1123StrToTime or FTPMDTMStrToTime as needed instead") bool StrToTime(const std::string &Val,time_t &Result); std::string LookupTag(const std::string &Message,const char *Tag,const char *Default = 0); int StringToBool(const std::string &Text,int Default = -1); bool ReadMessages(int Fd, std::vector<std::string> &List); @@ -220,8 +218,8 @@ class URI static std::string SiteOnly(const std::string &URI); static std::string ArchiveOnly(const std::string &URI); static std::string NoUserPassword(const std::string &URI); - - URI(std::string Path) {CopyFrom(Path);} + + explicit URI(std::string Path) { CopyFrom(Path); } URI() : Port(0) {} }; |