From 3b5421b4c75f5c85b48cbb61bf22642ff52a6352 Mon Sep 17 00:00:00 2001 From: Arch Librarian Date: Mon, 20 Sep 2004 16:51:06 +0000 Subject: Start on acquire stuff Author: jgg Date: 1998-10-20 02:39:12 GMT Start on acquire stuff --- apt-pkg/acquire-item.cc | 6 +- apt-pkg/acquire-worker.cc | 251 ++++++++++++++++++++++++++++++++++++++- apt-pkg/acquire-worker.h | 36 +++++- apt-pkg/acquire.cc | 58 ++++++++- apt-pkg/acquire.h | 11 +- apt-pkg/algorithms.cc | 24 +++- apt-pkg/algorithms.h | 12 +- apt-pkg/contrib/cmndline.cc | 29 +---- apt-pkg/contrib/configuration.cc | 42 +++---- apt-pkg/contrib/configuration.h | 3 +- apt-pkg/contrib/fileutl.cc | 42 ++++++- apt-pkg/contrib/fileutl.h | 5 +- apt-pkg/contrib/strutl.cc | 75 +++++++++++- apt-pkg/contrib/strutl.h | 5 +- apt-pkg/init.cc | 4 +- apt-pkg/pkgcache.h | 5 +- apt-pkg/pkgcachegen.cc | 32 ++--- apt-pkg/pkgrecords.cc | 4 +- apt-pkg/sourcelist.cc | 4 +- 19 files changed, 541 insertions(+), 107 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index ccd72595b..e92b61181 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire-item.cc,v 1.1 1998/10/15 06:59:59 jgg Exp $ +// $Id: acquire-item.cc,v 1.2 1998/10/20 02:39:12 jgg Exp $ /* ###################################################################### Acquire Item - Item to acquire @@ -56,7 +56,7 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location) /* */ string pkgAcqIndex::ToFile() { - string PartialDir = _config->FindDir("Dir::State::lists") + "/partial/"; + string PartialDir = _config->FindFile("Dir::State::lists") + "/partial/"; return PartialDir + URItoFileName(Location->PackagesURI()); } @@ -78,7 +78,7 @@ pkgAcqIndexRel::pkgAcqIndexRel(pkgAcquire *Owner, /* */ string pkgAcqIndexRel::ToFile() { - string PartialDir = _config->FindDir("Dir::State::lists") + "/partial/"; + string PartialDir = _config->FindFile("Dir::State::lists") + "/partial/"; return PartialDir + URItoFileName(Location->ReleaseURI()); } diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc index 34f20723c..5bd30b7b1 100644 --- a/apt-pkg/acquire-worker.cc +++ b/apt-pkg/acquire-worker.cc @@ -1,15 +1,262 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire-worker.cc,v 1.1 1998/10/15 06:59:59 jgg Exp $ +// $Id: acquire-worker.cc,v 1.2 1998/10/20 02:39:13 jgg Exp $ /* ###################################################################### Acquire Worker + The worker process can startup either as a Configuration prober + or as a queue runner. As a configuration prober it only reads the + configuration message and + ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ #ifdef __GNUG__ #pragma implementation "apt-pkg/acquire-worker.h" -#endif +#endif #include +#include +#include +#include +#include + +#include +#include + /*}}}*/ + +// Worker::Worker - Constructor for Queue startup /*{{{*/ +// --------------------------------------------------------------------- +/* */ +pkgAcquire::Worker::Worker(Queue *Q,string Acc) +{ + OwnerQ = Q; + Config = 0; + Access = Acc; + + Construct(); +} + /*}}}*/ +// Worker::Worker - Constructor for method config startup /*{{{*/ +// --------------------------------------------------------------------- +/* */ +pkgAcquire::Worker::Worker(MethodConfig *Cnf) +{ + OwnerQ = 0; + Config = Cnf; + Access = Cnf->Access; + + Construct(); +} + /*}}}*/ +// Worker::Construct - Constructor helper /*{{{*/ +// --------------------------------------------------------------------- +/* */ +void pkgAcquire::Worker::Construct() +{ + Next = 0; + Process = -1; + InFd = -1; + OutFd = -1; + Debug = _config->FindB("Debug::pkgAcquire::Worker",false); +} + /*}}}*/ +// Worker::~Worker - Destructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +pkgAcquire::Worker::~Worker() +{ + close(InFd); + close(OutFd); + + if (Process > 0) + kill(Process,SIGINT); +} + /*}}}*/ +// Worker::Start - Start the worker process /*{{{*/ +// --------------------------------------------------------------------- +/* This forks the method and inits the communication channel */ +bool pkgAcquire::Worker::Start() +{ + // Get the method path + string Method = _config->FindDir("Dir::Bin::Methods") + Access; + if (FileExists(Method) == false) + return _error->Error("The method driver %s could not be found.",Method.c_str()); + + if (Debug == true) + clog << "Starting method '" << Method << '\'' << endl; + + // Create the pipes + int Pipes[4] = {-1,-1,-1,-1}; + if (pipe(Pipes) != 0 || pipe(Pipes+2) != 0) + { + _error->Errno("pipe","Failed to create IPC pipe to subprocess"); + for (int I = 0; I != 4; I++) + close(Pipes[I]); + return false; + } + + // Fork off the process + Process = fork(); + if (Process < 0) + { + cerr << "FATAL -> Failed to fork." << endl; + exit(100); + } + + // Spawn the subprocess + if (Process == 0) + { + // Setup the FDs + dup2(Pipes[1],STDOUT_FILENO); + dup2(Pipes[2],STDIN_FILENO); + dup2(((filebuf *)clog.rdbuf())->fd(),STDERR_FILENO); + for (int I = 0; I != 4; I++) + close(Pipes[I]); + SetCloseExec(STDOUT_FILENO,false); + SetCloseExec(STDIN_FILENO,false); + SetCloseExec(STDERR_FILENO,false); + + const char *Args[2]; + Args[0] = Method.c_str(); + Args[1] = 0; + execv(Args[0],(char **)Args); + cerr << "Failed to exec method " << Args[0] << endl; + exit(100); + } + + // Fix up our FDs + InFd = Pipes[0]; + OutFd = Pipes[3]; + SetNonBlock(Pipes[0],true); + SetNonBlock(Pipes[3],true); + close(Pipes[1]); + close(Pipes[2]); + + // Read the configuration data + if (WaitFd(InFd) == false || + ReadMessages() == false) + return _error->Error("Method %s did not start correctly",Method.c_str()); + + RunMessages(); + + return true; +} + /*}}}*/ +// Worker::ReadMessages - Read all pending messages into the list /*{{{*/ +// --------------------------------------------------------------------- +/* This pulls full messages from the input FD into the message buffer. + It assumes that messages will not pause during transit so no + fancy buffering is used. */ +bool pkgAcquire::Worker::ReadMessages() +{ + char Buffer[4000]; + char *End = Buffer; + + while (1) + { + int Res = read(InFd,End,sizeof(Buffer) - (End-Buffer)); + + // Process is dead, this is kind of bad.. + if (Res == 0) + { + if (waitpid(Process,0,0) != Process) + _error->Warning("I waited but nothing was there!"); + Process = -1; + close(InFd); + close(OutFd); + InFd = -1; + OutFd = -1; + return false; + } + + // No data + if (Res == -1) + return true; + + End += Res; + + // Look for the end of the message + for (char *I = Buffer; I < End; I++) + { + if (I[0] != '\n' || I[1] != '\n') + continue; + + // Pull the message out + string Message(Buffer,0,I-Buffer); + + // Fix up the buffer + for (; I < End && *I == '\n'; I++); + End -= I-Buffer; + memmove(Buffer,I,End-Buffer); + I = Buffer; + + if (Debug == true) + clog << "Message " << Access << ':' << QuoteString(Message,"\n") << endl; + + MessageQueue.push_back(Message); + } + if (End == Buffer) + return true; + + if (WaitFd(InFd) == false) + return false; + } + + return true; +} + /*}}}*/ + +// Worker::RunMessage - Empty the message queue /*{{{*/ +// --------------------------------------------------------------------- +/* This takes the messages from the message queue and runs them through + the parsers in order. */ +bool pkgAcquire::Worker::RunMessages() +{ + while (MessageQueue.empty() == false) + { + string Message = MessageQueue.front(); + MessageQueue.erase(MessageQueue.begin()); + + // Fetch the message number + char *End; + int Number = strtol(Message.c_str(),&End,10); + if (End == Message.c_str()) + return _error->Error("Invalid message from method %s: %s",Access.c_str(),Message.c_str()); + + // Determine the message number and dispatch + switch (Number) + { + case 100: + if (Capabilities(Message) == false) + return _error->Error("Unable to process Capabilities message from %s",Access.c_str()); + break; + } + } + return true; +} + /*}}}*/ +// Worker::Capabilities - 100 Capabilities handler /*{{{*/ +// --------------------------------------------------------------------- +/* This parses the capabilities message and dumps it into the configuration + structure. */ +bool pkgAcquire::Worker::Capabilities(string Message) +{ + if (Config == 0) + return true; + + Config->Version = LookupTag(Message,"Version"); + Config->SingleInstance = StringToBool(LookupTag(Message,"Single-Instance"),false); + Config->PreScan = StringToBool(LookupTag(Message,"Pre-Scan"),false); + + // Some debug text + if (Debug == true) + { + clog << "Configured access method " << Config->Access << endl; + clog << "Version: " << Config->Version << " SingleInstance: " << + Config->SingleInstance << " PreScan: " << Config->PreScan << endl; + } + + return true; +} /*}}}*/ diff --git a/apt-pkg/acquire-worker.h b/apt-pkg/acquire-worker.h index f01c935ae..28072373f 100644 --- a/apt-pkg/acquire-worker.h +++ b/apt-pkg/acquire-worker.h @@ -1,10 +1,12 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire-worker.h,v 1.1 1998/10/15 06:59:59 jgg Exp $ +// $Id: acquire-worker.h,v 1.2 1998/10/20 02:39:14 jgg Exp $ /* ###################################################################### Acquire Worker - Worker process manager + Each worker class is associated with exaclty one subprocess. + ##################################################################### */ /*}}}*/ #ifndef PKGLIB_ACQUIRE_WORKER_H @@ -20,18 +22,40 @@ class pkgAcquire::Worker { protected: + friend Queue; + + Worker *Next; + // The access association Queue *OwnerQ; - MethodConfig *Config; - Worker *Next; + MethodConfig *Config; + string Access; + + // This is the subprocess IPC setup + pid_t Process; + int InFd; + int OutFd; - friend Queue; + // Various internal things + bool Debug; + vector MessageQueue; + + // Private constructor helper + void Construct(); + + // Message handling things + bool ReadMessages(); + bool RunMessages(); + + // The message handlers + bool Capabilities(string Message); public: - bool Create(); + // Load the method and do the startup + bool Start(); - Worker(Queue *OwnerQ); + Worker(Queue *OwnerQ,string Access); Worker(MethodConfig *Config); ~Worker(); }; diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 9d8ae9934..ad5016b28 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire.cc,v 1.1 1998/10/15 06:59:59 jgg Exp $ +// $Id: acquire.cc,v 1.2 1998/10/20 02:39:15 jgg Exp $ /* ###################################################################### Acquire - File Acquiration @@ -14,6 +14,7 @@ #include #include #include +#include /*}}}*/ // Acquire::pkgAcquire - Constructor /*{{{*/ @@ -27,11 +28,18 @@ pkgAcquire::pkgAcquire() /*}}}*/ // Acquire::~pkgAcquire - Destructor /*{{{*/ // --------------------------------------------------------------------- -/* */ +/* Free our memory */ pkgAcquire::~pkgAcquire() { while (Items.size() != 0) delete Items[0]; + + while (Configs != 0) + { + MethodConfig *Jnk = Configs; + Configs = Configs->Next; + delete Jnk; + } } /*}}}*/ // Acquire::Add - Add a new item /*{{{*/ @@ -61,6 +69,52 @@ void pkgAcquire::Enqueue(Item *Item,string URI) { cout << "Fetching " << URI << endl; cout << " to " << Item->ToFile() << endl; + cout << " Queue is: " << QueueName(URI) << endl; +} + /*}}}*/ +// Acquire::QueueName - Return the name of the queue for this URI /*{{{*/ +// --------------------------------------------------------------------- +/* */ +string pkgAcquire::QueueName(string URI) +{ + const MethodConfig *Config = GetConfig(URIAccess(URI)); + return string(); } /*}}}*/ +// Acquire::GetConfig - Fetch the configuration information /*{{{*/ +// --------------------------------------------------------------------- +/* This locates the configuration structure for an access method. If + a config structure cannot be found a Worker will be created to + retrieve it */ +const pkgAcquire::MethodConfig *pkgAcquire::GetConfig(string Access) +{ + // Search for an existing config + MethodConfig *Conf; + for (Conf = Configs; Conf != 0; Conf = Conf->Next) + if (Conf->Access == Access) + return Conf; + + // Create the new config class + Conf = new MethodConfig; + Conf->Access = Access; + Conf->Next = Configs; + Configs = Conf; + // Create the worker to fetch the configuration + Worker Work(Conf); + if (Work.Start() == false) + return 0; + + return Conf; +} + /*}}}*/ + +// Acquire::MethodConfig::MethodConfig - Constructor /*{{{*/ +// --------------------------------------------------------------------- +/* */ +pkgAcquire::MethodConfig::MethodConfig() +{ + SingleInstance = false; + PreScan = false; +} + /*}}}*/ diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index b728d2133..355eb3c3a 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: acquire.h,v 1.1 1998/10/15 06:59:59 jgg Exp $ +// $Id: acquire.h,v 1.2 1998/10/20 02:39:16 jgg Exp $ /* ###################################################################### Acquire - File Acquiration @@ -60,6 +60,9 @@ class pkgAcquire void Enqueue(Item *Item,string URI); public: + + const MethodConfig *GetConfig(string Access); + string QueueName(string URI); pkgAcquire(); ~pkgAcquire(); @@ -73,9 +76,8 @@ class pkgAcquire::Queue protected: - string Access; string URIMatch; - + vector Items; public: @@ -84,6 +86,8 @@ class pkgAcquire::Queue // Configuration information from each method struct pkgAcquire::MethodConfig { + MethodConfig *Next; + string Access; string Version; @@ -91,7 +95,6 @@ struct pkgAcquire::MethodConfig bool PreScan; MethodConfig(); - ~MethodConfig(); }; #endif diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 126318b59..755474e15 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: algorithms.cc,v 1.5 1998/10/08 04:54:58 jgg Exp $ +// $Id: algorithms.cc,v 1.6 1998/10/20 02:39:17 jgg Exp $ /* ###################################################################### Algorithms - A set of misc algorithms @@ -713,7 +713,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) ((Cache[End] & pkgDepCache::DepGNow) == 0 && End->Type != pkgCache::Dep::Conflicts)) { - if ((Flags[I->ID] & Protected) != 0) + if ((Flags[I->ID] & Protected) == Protected) continue; // See if a keep will do @@ -755,7 +755,8 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) } // Hm, nothing can possibly satisify this dep. Nuke it. - if (VList[0] == 0 && End->Type != pkgCache::Dep::Conflicts) + if (VList[0] == 0 && End->Type != pkgCache::Dep::Conflicts && + (Flags[I->ID] & Protected) != Protected) { Cache.MarkKeep(I); if (Cache[I].InstBroken() == false) @@ -942,3 +943,20 @@ bool pkgProblemResolver::ResolveByKeep() return true; } /*}}}*/ +// ProblemResolver::InstallProtect - Install all protected packages /*{{{*/ +// --------------------------------------------------------------------- +/* This is used to make sure protected packages are installed */ +void pkgProblemResolver::InstallProtect() +{ + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + { + if ((Flags[I->ID] & Protected) == Protected) + { + if ((Flags[I->ID] & ToRemove) == ToRemove) + Cache.MarkDelete(I); + else + Cache.MarkInstall(I,false); + } + } +} + /*}}}*/ diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index bd0a1f7bd..0553b3eec 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: algorithms.h,v 1.5 1998/10/08 04:54:59 jgg Exp $ +// $Id: algorithms.h,v 1.6 1998/10/20 02:39:18 jgg Exp $ /* ###################################################################### Algorithms - A set of misc algorithms @@ -68,7 +68,8 @@ class pkgProblemResolver typedef pkgCache::Package Package; enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1), - Upgradable = (1 << 2), ReInstateTried = (1 << 3)}; + Upgradable = (1 << 2), ReInstateTried = (1 << 3), + ToRemove = (1 << 4)}; signed short *Scores; unsigned char *Flags; bool Debug; @@ -89,13 +90,16 @@ class pkgProblemResolver public: inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected;}; + inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;}; // Try to intelligently resolve problems by installing and removing packages bool Resolve(bool BrokenFix = false); - + // Try to resolve problems only by using keep bool ResolveByKeep(); - + + void InstallProtect(); + pkgProblemResolver(pkgDepCache &Cache); }; diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index 7f5ab59a5..94ca4dc70 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: cmndline.cc,v 1.3 1998/10/08 04:55:01 jgg Exp $ +// $Id: cmndline.cc,v 1.4 1998/10/20 02:39:25 jgg Exp $ /* ###################################################################### Command Line Class - Sophisticated command line parser @@ -259,14 +259,10 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[], break; } - // Check for positives - if (strcasecmp(Argument,"yes") == 0 || - strcasecmp(Argument,"true") == 0 || - strcasecmp(Argument,"with") == 0 || - strcasecmp(Argument,"enable") == 0) + // Check for boolean + Sense = StringToBool(Argument); + if (Sense >= 0) { - Sense = 1; - // Eat the argument if (Argument != Buffer) { @@ -276,23 +272,6 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[], break; } - // Check for negatives - if (strcasecmp(Argument,"no") == 0 || - strcasecmp(Argument,"false") == 0 || - strcasecmp(Argument,"without") == 0 || - strcasecmp(Argument,"disable") == 0) - { - Sense = 0; - - // Eat the argument - if (Argument != Buffer) - { - Opt += strlen(Opt); - I += IncI; - } - break; - } - if (CertainArg == true) return _error->Error("Sense %s is not understood, try true or false.",Argument); diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 433b92244..82418f9c2 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: configuration.cc,v 1.6 1998/10/02 04:39:49 jgg Exp $ +// $Id: configuration.cc,v 1.7 1998/10/20 02:39:26 jgg Exp $ /* ###################################################################### Configuration Class @@ -102,12 +102,12 @@ string Configuration::Find(const char *Name,const char *Default) return Itm->Value; } /*}}}*/ -// Configuration::FindDir - Find a directory /*{{{*/ +// Configuration::FindFile - Find a Filename /*{{{*/ // --------------------------------------------------------------------- /* Directories are stored as the base dir in the Parent node and the - sub directory in sub nodes + sub directory in sub nodes with the final node being the end filename */ -string Configuration::FindDir(const char *Name,const char *Default = 0) +string Configuration::FindFile(const char *Name,const char *Default) { Item *Itm = Lookup(Name,false); if (Itm == 0 || Itm->Value.empty() == true) @@ -134,6 +134,17 @@ string Configuration::FindDir(const char *Name,const char *Default = 0) return Itm->Parent->Value + '/' + Itm->Value; } /*}}}*/ +// Configuration::FindDir - Find a directory name /*{{{*/ +// --------------------------------------------------------------------- +/* This is like findfile execept the result is terminated in a / */ +string Configuration::FindDir(const char *Name,const char *Default) +{ + string Res = FindFile(Name,Default); + if (Res.end()[-1] != '/') + return Res + '/'; + return Res; +} + /*}}}*/ // Configuration::FindI - Find an integer value /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -160,28 +171,7 @@ bool Configuration::FindB(const char *Name,bool Default) if (Itm == 0 || Itm->Value.empty() == true) return Default; - char *End; - int Res = strtol(Itm->Value.c_str(),&End,0); - if (End == Itm->Value.c_str() || Res < 0 || Res > 1) - { - // Check for positives - if (strcasecmp(Itm->Value.c_str(),"no") == 0 || - strcasecmp(Itm->Value.c_str(),"false") == 0 || - strcasecmp(Itm->Value.c_str(),"without") == 0 || - strcasecmp(Itm->Value.c_str(),"disable") == 0) - return false; - - // Check for negatives - if (strcasecmp(Itm->Value.c_str(),"yes") == 0 || - strcasecmp(Itm->Value.c_str(),"true") == 0 || - strcasecmp(Itm->Value.c_str(),"with") == 0 || - strcasecmp(Itm->Value.c_str(),"enable") == 0) - return true; - - return Default; - } - - return Res; + return StringToBool(Itm->Value,Default); } /*}}}*/ // Configuration::Set - Set a value /*{{{*/ diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 1cdf67860..c98b0bb14 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: configuration.h,v 1.4 1998/09/22 05:30:27 jgg Exp $ +// $Id: configuration.h,v 1.5 1998/10/20 02:39:27 jgg Exp $ /* ###################################################################### Configuration Class @@ -49,6 +49,7 @@ class Configuration public: string Find(const char *Name,const char *Default = 0); + string FindFile(const char *Name,const char *Default = 0); string FindDir(const char *Name,const char *Default = 0); int FindI(const char *Name,int Default = 0); bool FindB(const char *Name,bool Default = false); diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 60b9f8b75..cc0363da5 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: fileutl.cc,v 1.8 1998/10/02 04:39:50 jgg Exp $ +// $Id: fileutl.cc,v 1.9 1998/10/20 02:39:28 jgg Exp $ /* ###################################################################### File Utilities @@ -119,6 +119,45 @@ string flNotDir(string File) return string(File,Res,Res - File.length()); } /*}}}*/ +// SetCloseExec - Set the close on exec flag /*{{{*/ +// --------------------------------------------------------------------- +/* */ +void SetCloseExec(int Fd,bool Close) +{ + if (fcntl(Fd,F_SETFD,(Close == false)?0:FD_CLOEXEC) != 0) + { + cerr << "FATAL -> Could not set close on exec " << strerror(errno) << endl; + exit(100); + } +} + /*}}}*/ +// SetNonBlock - Set the nonblocking flag /*{{{*/ +// --------------------------------------------------------------------- +/* */ +void SetNonBlock(int Fd,bool Block) +{ + int Flags = fcntl(Fd,F_GETFL); + if (fcntl(Fd,F_SETFL,(Block == false)?0:O_NONBLOCK) != 0) + { + cerr << "FATAL -> Could not set non-blocking flag " << strerror(errno) << endl; + exit(100); + } +} + /*}}}*/ +// WaitFd - Wait for a FD to become readable /*{{{*/ +// --------------------------------------------------------------------- +/* This waits for a FD to become readable using select. It is usefull for + applications making use of non-blocking sockets. */ +bool WaitFd(int Fd) +{ + fd_set Set; + FD_ZERO(&Set); + FD_SET(Fd,&Set); + if (select(Fd+1,&Set,0,0,0) <= 0) + return false; + return true; +} + /*}}}*/ // FileFd::FileFd - Open a file /*{{{*/ // --------------------------------------------------------------------- @@ -155,6 +194,7 @@ FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms) _error->Errno("open","Could not open file %s",FileName.c_str()); else this->FileName = FileName; + SetCloseExec(iFd,true); } /*}}}*/ // FileFd::~File - Closes the file /*{{{*/ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index c468c95d3..7a72df09f 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: fileutl.h,v 1.6 1998/10/02 04:39:52 jgg Exp $ +// $Id: fileutl.h,v 1.7 1998/10/20 02:39:29 jgg Exp $ /* ###################################################################### File Utilities @@ -63,6 +63,9 @@ bool CopyFile(FileFd From,FileFd To); int GetLock(string File,bool Errors = true); bool FileExists(string File); string SafeGetCWD(); +void SetCloseExec(int Fd,bool Close); +void SetNonBlock(int Fd,bool Block); +bool WaitFd(int Fd); // File string manipulators string flNotDir(string File); diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 5a61f269c..c615f6229 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: strutl.cc,v 1.4 1998/09/22 05:30:28 jgg Exp $ +// $Id: strutl.cc,v 1.5 1998/10/20 02:39:30 jgg Exp $ /* ###################################################################### String Util - Some usefull string functions. @@ -303,6 +303,17 @@ string URItoFileName(string URI) return URI; } /*}}}*/ +// URIAccess - Return the access method for the URI /*{{{*/ +// --------------------------------------------------------------------- +/* */ +string URIAccess(string URI) +{ + string::size_type Pos = URI.find(':'); + if (Pos == string::npos) + return string(); + return string(URI,0,Pos); +} + /*}}}*/ // Base64Encode - Base64 Encoding routine for short strings /*{{{*/ // --------------------------------------------------------------------- /* This routine performs a base64 transformation on a string. It was ripped @@ -389,7 +400,7 @@ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd) for (; A != AEnd && B != BEnd; A++, B++) if (toupper(*A) != toupper(*B)) break; - + if (A == AEnd && B == BEnd) return 0; if (A == AEnd) @@ -401,3 +412,63 @@ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd) return 1; } /*}}}*/ +// LookupTag - Lookup the value of a tag in a taged string /*{{{*/ +// --------------------------------------------------------------------- +/* The format is like those used in package files and the method + communication system */ +string LookupTag(string Message,const char *Tag,const char *Default) +{ + // Look for a matching tag. + int Length = strlen(Tag); + for (string::iterator I = Message.begin(); I + Length < Message.end(); I++) + { + // Found the tag + if (I[Length] == ':' && stringcasecmp(I,I+Length,Tag) == 0) + { + // Find the end of line and strip the leading/trailing spaces + string::iterator J; + I += Length + 1; + for (; isspace(*I) != 0 && I < Message.end(); I++); + for (J = I; *J != '\n' && J < Message.end(); J++); + for (; J > I && isspace(J[-1]) != 0; J--); + + return string(I,J-I); + } + + for (; *I != '\n' && I < Message.end(); I++); + } + + // Failed to find a match + if (Default == 0) + return string(); + return Default; +} + /*}}}*/ +// StringToBool - Converts a string into a boolean /*{{{*/ +// --------------------------------------------------------------------- +/* This inspects the string to see if it is true or if it is false and + then returns the result. Several varients on true/false are checked. */ +int StringToBool(string Text,int Default = -1) +{ + char *End; + int Res = strtol(Text.c_str(),&End,0); + if (End != Text.c_str() && Res >= 0 && Res <= 1) + return Res; + + // Check for positives + if (strcasecmp(Text.c_str(),"no") == 0 || + strcasecmp(Text.c_str(),"false") == 0 || + strcasecmp(Text.c_str(),"without") == 0 || + strcasecmp(Text.c_str(),"disable") == 0) + return 0; + + // Check for negatives + if (strcasecmp(Text.c_str(),"yes") == 0 || + strcasecmp(Text.c_str(),"true") == 0 || + strcasecmp(Text.c_str(),"with") == 0 || + strcasecmp(Text.c_str(),"enable") == 0) + return 1; + + return Default; +} + /*}}}*/ diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 7af215587..38aca5762 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: strutl.h,v 1.4 1998/09/22 05:30:29 jgg Exp $ +// $Id: strutl.h,v 1.5 1998/10/20 02:39:31 jgg Exp $ /* ###################################################################### String Util - These are some usefull string functions @@ -31,10 +31,13 @@ string TimeToStr(unsigned long Sec); string SubstVar(string Str,string Subst,string Contents); string Base64Encode(string Str); string URItoFileName(string URI); +string URIAccess(string URI); int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd); inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));}; int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd); inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));}; +string LookupTag(string Message,const char *Tag,const char *Default = 0); +int StringToBool(string Text,int Default = -1); #endif diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index c8b35de17..645d64d30 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: init.cc,v 1.7 1998/10/09 19:57:21 jgg Exp $ +// $Id: init.cc,v 1.8 1998/10/20 02:39:19 jgg Exp $ /* ###################################################################### Init - Initialize the package library @@ -47,7 +47,7 @@ bool pkgInitialize(Configuration &Cnf) Cnf.Set("Dir::Etc::main","apt.conf"); // Read the main config file - string FName = Cnf.FindDir("Dir::Etc::main"); + string FName = Cnf.FindFile("Dir::Etc::main"); struct stat Buf; if (stat(FName.c_str(),&Buf) != 0) return true; diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 2e695ab7b..9dd9869db 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: pkgcache.h,v 1.7 1998/07/19 04:22:01 jgg Exp $ +// $Id: pkgcache.h,v 1.8 1998/10/20 02:39:20 jgg Exp $ /* ###################################################################### Cache - Structure definitions for the cache file @@ -86,9 +86,6 @@ class pkgCache string CacheFile; MMap ⤅ - bool Public; - bool ReadOnly; - static unsigned long sHash(string S); static unsigned long sHash(const char *S); diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 7227f15eb..f41ee4925 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: pkgcachegen.cc,v 1.19 1998/10/15 07:00:00 jgg Exp $ +// $Id: pkgcachegen.cc,v 1.20 1998/10/20 02:39:21 jgg Exp $ /* ###################################################################### Package Cache Generator - Generator for the cache structure. @@ -384,8 +384,8 @@ bool pkgSrcCacheCheck(pkgSourceList &List) if (_error->PendingError() == true) return false; - string CacheFile = _config->FindDir("Dir::Cache::srcpkgcache"); - string ListDir = _config->FindDir("Dir::State::lists"); + string CacheFile = _config->FindFile("Dir::Cache::srcpkgcache"); + string ListDir = _config->FindFile("Dir::State::lists"); // Count the number of missing files int Missing = 0; @@ -489,9 +489,9 @@ bool pkgPkgCacheCheck(string CacheFile) // Status files that must be in the cache string Status[3]; - Status[0] = _config->FindDir("Dir::State::xstatus"); - Status[1]= _config->FindDir("Dir::State::userstatus"); - Status[2] = _config->FindDir("Dir::State::status"); + Status[0] = _config->FindFile("Dir::State::xstatus"); + Status[1]= _config->FindFile("Dir::State::userstatus"); + Status[2] = _config->FindFile("Dir::State::status"); // Cheack each file for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++) @@ -521,9 +521,9 @@ bool pkgPkgCacheCheck(string CacheFile) static bool pkgAddSourcesSize(unsigned long &TotalSize) { // Grab the file names - string xstatus = _config->FindDir("Dir::State::xstatus"); - string userstatus = _config->FindDir("Dir::State::userstatus"); - string status = _config->FindDir("Dir::State::status"); + string xstatus = _config->FindFile("Dir::State::xstatus"); + string userstatus = _config->FindFile("Dir::State::userstatus"); + string status = _config->FindFile("Dir::State::status"); // Grab the sizes struct stat Buf; @@ -546,9 +546,9 @@ static bool pkgMergeStatus(OpProgress &Progress,pkgCacheGenerator &Gen, { // Grab the file names string Status[3]; - Status[0] = _config->FindDir("Dir::State::xstatus"); - Status[1]= _config->FindDir("Dir::State::userstatus"); - Status[2] = _config->FindDir("Dir::State::status"); + Status[0] = _config->FindFile("Dir::State::xstatus"); + Status[1]= _config->FindFile("Dir::State::userstatus"); + Status[2] = _config->FindFile("Dir::State::status"); for (int I = 0; I != 3; I++) { @@ -584,15 +584,15 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress) { Progress.OverallProgress(0,1,1,"Reading Package Lists"); - string CacheFile = _config->FindDir("Dir::Cache::pkgcache"); + string CacheFile = _config->FindFile("Dir::Cache::pkgcache"); bool SrcOk = pkgSrcCacheCheck(List); bool PkgOk = SrcOk && pkgPkgCacheCheck(CacheFile); // Rebuild the source and package caches if (SrcOk == false) { - string SCacheFile = _config->FindDir("Dir::Cache::srcpkgcache"); - string ListDir = _config->FindDir("Dir::State::lists"); + string SCacheFile = _config->FindFile("Dir::Cache::srcpkgcache"); + string ListDir = _config->FindFile("Dir::State::lists"); FileFd SCacheF(SCacheFile,FileFd::WriteEmpty); FileFd CacheF(CacheFile,FileFd::WriteEmpty); @@ -657,7 +657,7 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress) } // We use the source cache to generate the package cache - string SCacheFile = _config->FindDir("Dir::Cache::srcpkgcache"); + string SCacheFile = _config->FindFile("Dir::Cache::srcpkgcache"); FileFd SCacheF(SCacheFile,FileFd::ReadOnly); FileFd CacheF(CacheFile,FileFd::WriteEmpty); diff --git a/apt-pkg/pkgrecords.cc b/apt-pkg/pkgrecords.cc index bb8b05759..59bc2a1bc 100644 --- a/apt-pkg/pkgrecords.cc +++ b/apt-pkg/pkgrecords.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: pkgrecords.cc,v 1.2 1998/08/19 06:16:10 jgg Exp $ +// $Id: pkgrecords.cc,v 1.3 1998/10/20 02:39:23 jgg Exp $ /* ###################################################################### Package Records - Allows access to complete package description records @@ -23,7 +23,7 @@ /* This will create the necessary structures to access the status files */ pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0) { - string ListDir = _config->FindDir("Dir::State::lists"); + string ListDir = _config->FindFile("Dir::State::lists"); Files = new PkgFile[Cache.HeaderP->PackageFileCount]; for (pkgCache::PkgFileIterator I = Cache.FileBegin(); diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc index c9d0285a9..e6200d3be 100644 --- a/apt-pkg/sourcelist.cc +++ b/apt-pkg/sourcelist.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: sourcelist.cc,v 1.6 1998/10/15 07:00:01 jgg Exp $ +// $Id: sourcelist.cc,v 1.7 1998/10/20 02:39:24 jgg Exp $ /* ###################################################################### List of Sources @@ -41,7 +41,7 @@ pkgSourceList::pkgSourceList(string File) /* */ bool pkgSourceList::ReadMainList() { - return Read(_config->FindDir("Dir::Etc::sourcelist")); + return Read(_config->FindFile("Dir::Etc::sourcelist")); } /*}}}*/ // SourceList::Read - Parse the sourcelist file /*{{{*/ -- cgit v1.2.3