diff options
Diffstat (limited to 'ftparchive')
-rw-r--r-- | ftparchive/apt-ftparchive.cc | 2 | ||||
-rw-r--r-- | ftparchive/contents.cc | 27 | ||||
-rw-r--r-- | ftparchive/multicompress.cc | 58 | ||||
-rw-r--r-- | ftparchive/multicompress.h | 21 | ||||
-rw-r--r-- | ftparchive/writer.cc | 175 | ||||
-rw-r--r-- | ftparchive/writer.h | 8 |
6 files changed, 152 insertions, 139 deletions
diff --git a/ftparchive/apt-ftparchive.cc b/ftparchive/apt-ftparchive.cc index 0c29002e6..0762a2b28 100644 --- a/ftparchive/apt-ftparchive.cc +++ b/ftparchive/apt-ftparchive.cc @@ -949,6 +949,8 @@ int main(int argc, const char *argv[]) CommandLine::Args Args[] = { {'h',"help","help",0}, {0,"md5","APT::FTPArchive::MD5",0}, + {0,"sha1","APT::FTPArchive::SHA1",0}, + {0,"sha256","APT::FTPArchive::SHA256",0}, {'v',"version","version",0}, {'d',"db","APT::FTPArchive::DB",CommandLine::HasArg}, {'s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg}, diff --git a/ftparchive/contents.cc b/ftparchive/contents.cc index b761d9204..eadced626 100644 --- a/ftparchive/contents.cc +++ b/ftparchive/contents.cc @@ -36,12 +36,13 @@ #include "contents.h" #include <apti18n.h> +#include <apt-pkg/debfile.h> #include <apt-pkg/extracttar.h> #include <apt-pkg/error.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <malloc.h> +#include <malloc.h> /*}}}*/ // GenContents::~GenContents - Free allocated memory /*{{{*/ @@ -305,29 +306,7 @@ void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf) bool ContentsExtract::Read(debDebFile &Deb) { Reset(); - - // Get the archive member and positition the file - const ARArchive::Member *Member = Deb.GotoMember("data.tar.gz"); - const char *Compressor = "gzip"; - if (Member == 0) { - Member = Deb.GotoMember("data.tar.bz2"); - Compressor = "bzip2"; - } - if (Member == 0) { - Member = Deb.GotoMember("data.tar.lzma"); - Compressor = "lzma"; - } - if (Member == 0) { - _error->Error(_("Internal error, could not locate member %s"), - "data.tar.{gz,bz2,lzma}"); - return false; - } - - // Extract it. - ExtractTar Tar(Deb.GetFile(),Member->Size,Compressor); - if (Tar.Go(*this) == false) - return false; - return true; + return Deb.ExtractArchive(*this); } /*}}}*/ // ContentsExtract::DoItem - Extract an item /*{{{*/ diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc index bb4beedf9..f82879015 100644 --- a/ftparchive/multicompress.cc +++ b/ftparchive/multicompress.cc @@ -30,12 +30,6 @@ using namespace std; -const MultiCompress::CompType MultiCompress::Compressors[] = - {{".","",0,0,0,1}, - {"gzip",".gz","gzip","-9n","-d",2}, - {"bzip2",".bz2","bzip2","-9","-d",3}, - {"lzma",".lzma","lzma","-9","-d",4}, - {}}; // MultiCompress::MultiCompress - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -48,7 +42,7 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress, Outputter = -1; Input = 0; UpdateMTime = 0; - + /* Parse the compression string, a space separated lists of compresison types */ string::const_iterator I = Compress.begin(); @@ -61,13 +55,14 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress, for (; I != Compress.end() && !isspace(*I); I++); // Find the matching compressor - const CompType *Comp = Compressors; - for (; Comp->Name != 0; Comp++) - if (stringcmp(Start,I,Comp->Name) == 0) + std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors(); + std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin(); + for (; Comp != Compressors.end(); ++Comp) + if (stringcmp(Start,I,Comp->Name.c_str()) == 0) break; // Hmm.. unknown. - if (Comp->Name == 0) + if (Comp == Compressors.end()) { _error->Warning(_("Unknown compression algorithm '%s'"),string(Start,I).c_str()); continue; @@ -77,7 +72,7 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress, Files *NewOut = new Files; NewOut->Next = Outputs; Outputs = NewOut; - NewOut->CompressProg = Comp; + NewOut->CompressProg = *Comp; NewOut->Output = Output+Comp->Extension; struct stat St; @@ -141,13 +136,14 @@ bool MultiCompress::GetStat(string const &Output,string const &Compress,struct s for (; I != Compress.end() && !isspace(*I); I++); // Find the matching compressor - const CompType *Comp = Compressors; - for (; Comp->Name != 0; Comp++) - if (stringcmp(Start,I,Comp->Name) == 0) + std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors(); + std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin(); + for (; Comp != Compressors.end(); ++Comp) + if (stringcmp(Start,I,Comp->Name.c_str()) == 0) break; // Hmm.. unknown. - if (Comp->Name == 0) + if (Comp == Compressors.end()) continue; string Name = Output+Comp->Extension; @@ -268,13 +264,13 @@ bool MultiCompress::Finalize(unsigned long &OutSize) /* This opens the compressor, either in compress mode or decompress mode. FileFd is always the compressor input/output file, OutFd is the created pipe, Input for Compress, Output for Decompress. */ -bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd, - int &OutFd,bool const &Comp) +bool MultiCompress::OpenCompress(APT::Configuration::Compressor const &Prog, + pid_t &Pid,int const &FileFd,int &OutFd,bool const &Comp) { Pid = -1; // No compression - if (Prog->Binary == 0) + if (Prog.Binary.empty() == true) { OutFd = dup(FileFd); return true; @@ -309,15 +305,17 @@ bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int const &File SetCloseExec(STDOUT_FILENO,false); SetCloseExec(STDIN_FILENO,false); - - const char *Args[3]; - Args[0] = Prog->Binary; - if (Comp == true) - Args[1] = Prog->CompArgs; - else - Args[1] = Prog->UnCompArgs; - Args[2] = 0; - execvp(Args[0],(char **)Args); + + std::vector<char const*> Args; + Args.push_back(Prog.Binary.c_str()); + std::vector<std::string> const * const addArgs = + (Comp == true) ? &(Prog.CompressArgs) : &(Prog.UncompressArgs); + for (std::vector<std::string>::const_iterator a = addArgs->begin(); + a != addArgs->end(); ++a) + Args.push_back(a->c_str()); + Args.push_back(NULL); + + execvp(Args[0],(char **)&Args[0]); cerr << _("Failed to exec compressor ") << Args[0] << endl; _exit(100); }; @@ -335,7 +333,7 @@ bool MultiCompress::OpenOld(int &Fd,pid_t &Proc) { Files *Best = Outputs; for (Files *I = Outputs; I != 0; I = I->Next) - if (Best->CompressProg->Cost > I->CompressProg->Cost) + if (Best->CompressProg.Cost > I->CompressProg.Cost) Best = I; // Open the file @@ -414,7 +412,7 @@ bool MultiCompress::Child(int const &FD) for (Files *I = Outputs; I != 0; I = I->Next) { if (I->CompressProc != -1) - ExecWait(I->CompressProc,I->CompressProg->Binary,false); + ExecWait(I->CompressProc, I->CompressProg.Binary.c_str(), false); } if (_error->PendingError() == true) diff --git a/ftparchive/multicompress.h b/ftparchive/multicompress.h index 3ac3b8fb2..19dede174 100644 --- a/ftparchive/multicompress.h +++ b/ftparchive/multicompress.h @@ -20,28 +20,18 @@ #include <string> #include <apt-pkg/fileutl.h> +#include <apt-pkg/aptconfiguration.h> #include <stdio.h> #include <sys/types.h> class MultiCompress { - // Enumeration of all supported compressors - struct CompType - { - const char *Name; - const char *Extension; - const char *Binary; - const char *CompArgs; - const char *UnCompArgs; - unsigned char Cost; - }; - // An output file struct Files { string Output; - const CompType *CompressProg; - Files *Next; + APT::Configuration::Compressor CompressProg; + Files *Next; FileFd TmpFile; pid_t CompressProc; time_t OldMTime; @@ -51,10 +41,9 @@ class MultiCompress Files *Outputs; pid_t Outputter; mode_t Permissions; - static const CompType Compressors[]; - bool OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd, - int &OutFd,bool const &Comp); + bool OpenCompress(APT::Configuration::Compressor const &Prog, + pid_t &Pid,int const &FileFd, int &OutFd,bool const &Comp); bool Child(int const &Fd); bool Start(); bool Die(); diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 98ab852ea..c43e8f4b4 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -17,6 +17,7 @@ #include <apt-pkg/strutl.h> #include <apt-pkg/error.h> #include <apt-pkg/configuration.h> +#include <apt-pkg/aptconfiguration.h> #include <apt-pkg/md5.h> #include <apt-pkg/sha1.h> #include <apt-pkg/sha2.h> @@ -59,6 +60,11 @@ FTWScanner::FTWScanner(string const &Arch): Arch(Arch) { ErrorPrinted = false; NoLinkAct = !_config->FindB("APT::FTPArchive::DeLinkAct",true); + + DoMD5 = _config->FindB("APT::FTPArchive::MD5",true); + DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true); + DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true); + DoSHA512 = _config->FindB("APT::FTPArchive::SHA512",true); } /*}}}*/ // FTWScanner::Scanner - FTW Scanner /*{{{*/ @@ -308,10 +314,10 @@ PackagesWriter::PackagesWriter(string const &DB,string const &Overrides,string c DeLinkLimit = 0; // Process the command line options - DoMD5 = _config->FindB("APT::FTPArchive::MD5",true); - DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true); - DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true); - DoSHA256 = _config->FindB("APT::FTPArchive::SHA512",true); + DoMD5 = _config->FindB("APT::FTPArchive::Packages::MD5",DoMD5); + DoSHA1 = _config->FindB("APT::FTPArchive::Packages::SHA1",DoSHA1); + DoSHA256 = _config->FindB("APT::FTPArchive::Packages::SHA256",DoSHA256); + DoSHA256 = _config->FindB("APT::FTPArchive::Packages::SHA512",true); DoAlwaysStat = _config->FindB("APT::FTPArchive::AlwaysStat", false); DoContents = _config->FindB("APT::FTPArchive::Contents",true); NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false); @@ -436,10 +442,14 @@ bool PackagesWriter::DoPackage(string FileName) unsigned int End = 0; SetTFRewriteData(Changes[End++], "Size", Size); - SetTFRewriteData(Changes[End++], "MD5sum", Db.MD5Res.c_str()); - SetTFRewriteData(Changes[End++], "SHA1", Db.SHA1Res.c_str()); - SetTFRewriteData(Changes[End++], "SHA256", Db.SHA256Res.c_str()); - SetTFRewriteData(Changes[End++], "SHA512", Db.SHA512Res.c_str()); + if (DoMD5 == true) + SetTFRewriteData(Changes[End++], "MD5sum", Db.MD5Res.c_str()); + if (DoSHA1 == true) + SetTFRewriteData(Changes[End++], "SHA1", Db.SHA1Res.c_str()); + if (DoSHA256 == true) + SetTFRewriteData(Changes[End++], "SHA256", Db.SHA256Res.c_str()); + if (DoSHA512 == true) + SetTFRewriteData(Changes[End++], "SHA512", Db.SHA512Res.c_str()); SetTFRewriteData(Changes[End++], "Filename", NewFileName.c_str()); SetTFRewriteData(Changes[End++], "Priority", OverItem->Priority.c_str()); SetTFRewriteData(Changes[End++], "Status", 0); @@ -561,6 +571,9 @@ SourcesWriter::SourcesWriter(string const &BOverrides,string const &SOverrides, BufSize = 0; // Process the command line options + DoMD5 = _config->FindB("APT::FTPArchive::Sources::MD5",DoMD5); + DoSHA1 = _config->FindB("APT::FTPArchive::Sources::SHA1",DoSHA1); + DoSHA256 = _config->FindB("APT::FTPArchive::Sources::SHA256",DoSHA256); NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false); // Read the override file @@ -610,15 +623,20 @@ bool SourcesWriter::DoPackage(string FileName) // Hash the file char *Start = Buffer; char *BlkEnd = Buffer + St.st_size; - MD5Summation MD5; - MD5.Add((unsigned char *)Start,BlkEnd - Start); + MD5Summation MD5; SHA1Summation SHA1; SHA256Summation SHA256; - SHA512Summation SHA512; - SHA1.Add((unsigned char *)Start,BlkEnd - Start); - SHA256.Add((unsigned char *)Start,BlkEnd - Start); - SHA512.Add((unsigned char *)Start,BlkEnd - Start); + SHA256Summation SHA512; + + if (DoMD5 == true) + MD5.Add((unsigned char *)Start,BlkEnd - Start); + if (DoSHA1 == true) + SHA1.Add((unsigned char *)Start,BlkEnd - Start); + if (DoSHA256 == true) + SHA256.Add((unsigned char *)Start,BlkEnd - Start); + if (DoSHA512 == true) + SHA512.Add((unsigned char *)Start,BlkEnd - Start); // Add an extra \n to the end, just in case *BlkEnd++ = '\n'; @@ -712,19 +730,19 @@ bool SourcesWriter::DoPackage(string FileName) // Add the dsc to the files hash list string const strippedName = flNotDir(FileName); std::ostringstream ostreamFiles; - if (Tags.Exists("Files")) + if (DoMD5 == true && Tags.Exists("Files")) ostreamFiles << "\n " << string(MD5.Result()) << " " << St.st_size << " " << strippedName << "\n " << Tags.FindS("Files"); string const Files = ostreamFiles.str(); std::ostringstream ostreamSha1; - if (Tags.Exists("Checksums-Sha1")) + if (DoSHA1 == true && Tags.Exists("Checksums-Sha1")) ostreamSha1 << "\n " << string(SHA1.Result()) << " " << St.st_size << " " << strippedName << "\n " << Tags.FindS("Checksums-Sha1"); string const ChecksumsSha1 = ostreamSha1.str(); std::ostringstream ostreamSha256; - if (Tags.Exists("Checksums-Sha256")) + if (DoSHA256 == true && Tags.Exists("Checksums-Sha256")) ostreamSha256 << "\n " << string(SHA256.Result()) << " " << St.st_size << " " << strippedName << "\n " << Tags.FindS("Checksums-Sha256"); string const ChecksumsSha256 = ostreamSha256.str(); @@ -784,10 +802,14 @@ bool SourcesWriter::DoPackage(string FileName) unsigned int End = 0; SetTFRewriteData(Changes[End++],"Source",Package.c_str(),"Package"); - SetTFRewriteData(Changes[End++],"Files",Files.c_str()); - SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str()); - SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str()); - SetTFRewriteData(Changes[End++],"Checksums-Sha512",ChecksumsSha512.c_str()); + if (Files.empty() == false) + SetTFRewriteData(Changes[End++],"Files",Files.c_str()); + if (ChecksumsSha1.empty() == false) + SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str()); + if (ChecksumsSha256.empty() == false) + SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str()); + if (ChecksumsSha512.empty() == false) + SetTFRewriteData(Changes[End++],"Checksums-Sha512",ChecksumsSha512.c_str()); if (Directory != "./") SetTFRewriteData(Changes[End++],"Directory",Directory.c_str()); SetTFRewriteData(Changes[End++],"Priority",BestPrio.c_str()); @@ -924,10 +946,12 @@ ReleaseWriter::ReleaseWriter(string const &DB) AddPattern("Packages.gz"); AddPattern("Packages.bz2"); AddPattern("Packages.lzma"); + AddPattern("Packages.xz"); AddPattern("Sources"); AddPattern("Sources.gz"); AddPattern("Sources.bz2"); AddPattern("Sources.lzma"); + AddPattern("Sources.xz"); AddPattern("Release"); AddPattern("Index"); AddPattern("md5sum.txt"); @@ -936,6 +960,9 @@ ReleaseWriter::ReleaseWriter(string const &DB) Output = stdout; time_t const now = time(NULL); + + setlocale(LC_TIME, "C"); + char datestr[128]; if (strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S UTC", gmtime(&now)) == 0) @@ -952,6 +979,8 @@ ReleaseWriter::ReleaseWriter(string const &DB) validstr[0] = '\0'; } + setlocale(LC_TIME, ""); + map<string,string> Fields; Fields["Origin"] = ""; Fields["Label"] = ""; @@ -975,6 +1004,10 @@ ReleaseWriter::ReleaseWriter(string const &DB) fprintf(Output, "%s: %s\n", (*I).first.c_str(), Value.c_str()); } + + DoMD5 = _config->FindB("APT::FTPArchive::Release::MD5",DoMD5); + DoSHA1 = _config->FindB("APT::FTPArchive::Release::SHA1",DoSHA1); + DoSHA256 = _config->FindB("APT::FTPArchive::Release::SHA256",DoSHA256); } /*}}}*/ // ReleaseWriter::DoPackage - Process a single package /*{{{*/ @@ -1007,24 +1040,33 @@ bool ReleaseWriter::DoPackage(string FileName) CheckSums[NewFileName].size = fd.Size(); - MD5Summation MD5; - MD5.AddFD(fd.Fd(), fd.Size()); - CheckSums[NewFileName].MD5 = MD5.Result(); - - fd.Seek(0); - SHA1Summation SHA1; - SHA1.AddFD(fd.Fd(), fd.Size()); - CheckSums[NewFileName].SHA1 = SHA1.Result(); - - fd.Seek(0); - SHA256Summation SHA256; - SHA256.AddFD(fd.Fd(), fd.Size()); - CheckSums[NewFileName].SHA256 = SHA256.Result(); - - SHA256Summation SHA512; - SHA256.AddFD(fd.Fd(), fd.Size()); - CheckSums[NewFileName].SHA512 = SHA512.Result(); + if (DoMD5 == true) + { + MD5Summation MD5; + MD5.AddFD(fd.Fd(), fd.Size()); + CheckSums[NewFileName].MD5 = MD5.Result(); + fd.Seek(0); + } + if (DoSHA1 == true) + { + SHA1Summation SHA1; + SHA1.AddFD(fd.Fd(), fd.Size()); + CheckSums[NewFileName].SHA1 = SHA1.Result(); + fd.Seek(0); + } + if (DoSHA256 == true) + { + SHA256Summation SHA256; + SHA256.AddFD(fd.Fd(), fd.Size()); + CheckSums[NewFileName].SHA256 = SHA256.Result(); + } + if (DoSHA512 == true) + { + SHA512Summation SHA512; + SHA512.AddFD(fd.Fd(), fd.Size()); + CheckSums[NewFileName].SHA512 = SHA512.Result(); + } fd.Close(); return true; @@ -1035,37 +1077,41 @@ bool ReleaseWriter::DoPackage(string FileName) // --------------------------------------------------------------------- void ReleaseWriter::Finish() { - fprintf(Output, "MD5Sum:\n"); - for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin(); - I != CheckSums.end(); - ++I) + if (DoMD5 == true) { - fprintf(Output, " %s %16ld %s\n", - (*I).second.MD5.c_str(), - (*I).second.size, - (*I).first.c_str()); + fprintf(Output, "MD5Sum:\n"); + for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin(); + I != CheckSums.end(); ++I) + { + fprintf(Output, " %s %16ld %s\n", + (*I).second.MD5.c_str(), + (*I).second.size, + (*I).first.c_str()); + } } - - fprintf(Output, "SHA1:\n"); - for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin(); - I != CheckSums.end(); - ++I) + if (DoSHA1 == true) { - fprintf(Output, " %s %16ld %s\n", - (*I).second.SHA1.c_str(), - (*I).second.size, - (*I).first.c_str()); + fprintf(Output, "SHA1:\n"); + for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin(); + I != CheckSums.end(); ++I) + { + fprintf(Output, " %s %16ld %s\n", + (*I).second.SHA1.c_str(), + (*I).second.size, + (*I).first.c_str()); + } } - - fprintf(Output, "SHA256:\n"); - for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin(); - I != CheckSums.end(); - ++I) + if (DoSHA256 == true) { - fprintf(Output, " %s %16ld %s\n", - (*I).second.SHA256.c_str(), - (*I).second.size, - (*I).first.c_str()); + fprintf(Output, "SHA256:\n"); + for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin(); + I != CheckSums.end(); ++I) + { + fprintf(Output, " %s %16ld %s\n", + (*I).second.SHA256.c_str(), + (*I).second.size, + (*I).first.c_str()); + } } fprintf(Output, "SHA512:\n"); @@ -1080,4 +1126,3 @@ void ReleaseWriter::Finish() } } - diff --git a/ftparchive/writer.h b/ftparchive/writer.h index e1810821a..c6026e954 100644 --- a/ftparchive/writer.h +++ b/ftparchive/writer.h @@ -60,6 +60,10 @@ class FTWScanner } public: + bool DoMD5; + bool DoSHA1; + bool DoSHA256; + bool DoSHA512; unsigned long DeLinkLimit; string InternalPrefix; @@ -103,10 +107,6 @@ class PackagesWriter : public FTWScanner public: // Some flags - bool DoMD5; - bool DoSHA1; - bool DoSHA256; - bool DoSHA512; bool DoAlwaysStat; bool NoOverride; bool DoContents; |