summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:50:43 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:50:43 +0000
commit9c14e3d619e713aefa623986b5bbae81a1d6cc94 (patch)
tree282c77581b35bbdc46faa400be5d64ec37605507
parent6c139d6e362f04a1582e8a8f511f8aeab031fecf (diff)
Config class and source list
Author: jgg Date: 1998-07-09 05:12:27 GMT Config class and source list
-rw-r--r--apt-pkg/contrib/configuration.cc45
-rw-r--r--apt-pkg/contrib/configuration.h10
-rw-r--r--apt-pkg/contrib/strutl.h4
-rw-r--r--apt-pkg/deb/deblistparser.cc22
-rw-r--r--apt-pkg/init.cc43
-rw-r--r--apt-pkg/init.h21
-rw-r--r--apt-pkg/pkgcachegen.cc7
-rw-r--r--apt-pkg/sourcelist.cc195
-rw-r--r--apt-pkg/sourcelist.h6
-rw-r--r--apt-pkg/tagfile.cc7
-rw-r--r--apt-pkg/templates.cc5
11 files changed, 147 insertions, 218 deletions
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 6d937d657..7694330f9 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.1 1998/07/07 04:17:10 jgg Exp $
+// $Id: configuration.cc,v 1.2 1998/07/09 05:12:33 jgg Exp $
/* ######################################################################
Configuration Class
@@ -20,7 +20,8 @@
#include <stdio.h>
/*}}}*/
-Configuration *_config;
+
+Configuration *_config = new Configuration;
// Configuration::Configuration - Constructor /*{{{*/
// ---------------------------------------------------------------------
@@ -41,17 +42,18 @@ Configuration::Item *Configuration::Lookup(Item *Head,const char *S,
Item *I = Head->Child;
Item **Last = &Head->Child;
for (; I != 0; Last = &I->Next, I = I->Next)
- if ((Res = stringcasecmp(I->Value.begin(),I->Value.end(),S,S + Len)) == 0)
+ if ((Res = stringcasecmp(I->Tag.begin(),I->Tag.end(),S,S + Len)) == 0)
break;
-
+
if (Res == 0)
return I;
if (Create == false)
return 0;
I = new Item;
- I->Value = string(S,Len);
+ I->Tag = string(S,Len);
I->Next = *Last;
+ I->Parent = Head;
*Last = I;
return I;
}
@@ -78,8 +80,6 @@ Configuration::Item *Configuration::Lookup(const char *Name,bool Create)
}
Itm = Lookup(Itm,Start,End - Start,Create);
- if (Itm == 0)
- return 0;
return Itm;
}
/*}}}*/
@@ -90,10 +90,39 @@ string Configuration::Find(const char *Name,const char *Default)
{
Item *Itm = Lookup(Name,false);
if (Itm == 0 || Itm->Value.empty() == true)
- return Default;
+ {
+ if (Default == 0)
+ return string();
+ else
+ return Default;
+ }
+
return Itm->Value;
}
/*}}}*/
+// Configuration::FindDir - Find a directory /*{{{*/
+// ---------------------------------------------------------------------
+/* Directories are stored as the base dir in the Parent node and the
+ */
+string Configuration::FindDir(const char *Name,const char *Default = 0)
+{
+ Item *Itm = Lookup(Name,false);
+ if (Itm == 0 || Itm->Value.empty() == true)
+ {
+ if (Default == 0)
+ return string();
+ else
+ return Default;
+ }
+
+ if (Itm->Value[0] == '/' || Itm->Parent == 0)
+ return Itm->Value;
+ if (Itm->Parent->Value.end()[-1] == '/')
+ return Itm->Parent->Value + Itm->Value;
+ else
+ return Itm->Parent->Value + '/' + Itm->Value;
+}
+ /*}}}*/
// Configuration::FindI - Find an integer value /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 7476346ef..bd06f5e37 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.1 1998/07/07 04:17:10 jgg Exp $
+// $Id: configuration.h,v 1.2 1998/07/09 05:12:34 jgg Exp $
/* ######################################################################
Configuration Class
@@ -21,8 +21,8 @@
##################################################################### */
/*}}}*/
// Header section: pkglib
-#ifndef PKGLIB_TAGFILE_H
-#define PKGLIB_TAGFILE_H
+#ifndef PKGLIB_CONFIGURATION_H
+#define PKGLIB_CONFIGURATION_H
#ifdef __GNUG__
#pragma interface "pkglib/configuration.h"
@@ -36,6 +36,7 @@ class Configuration
{
string Value;
string Tag;
+ Item *Parent;
Item *Child;
Item *Next;
Item() : Child(0), Next(0) {};
@@ -48,11 +49,12 @@ class Configuration
public:
string Find(const char *Name,const char *Default = 0);
+ string FindDir(const char *Name,const char *Default = 0);
int FindI(const char *Name,int Default = 0);
void Set(const char *Name,string Value);
void Set(const char *Name,int Value);
-
+
Configuration();
};
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 44a10c2f3..0aabf0186 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.1 1998/07/07 04:17:16 jgg Exp $
+// $Id: strutl.h,v 1.2 1998/07/09 05:12:35 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
@@ -31,6 +31,8 @@ string SubstVar(string Str,string Subst,string Contents);
string Base64Encode(string Str);
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));};
#endif
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 5fbb43a9f..3c82ee51d 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: deblistparser.cc,v 1.4 1998/07/07 04:17:16 jgg Exp $
+// $Id: deblistparser.cc,v 1.5 1998/07/09 05:12:37 jgg Exp $
/* ######################################################################
Package Cache Generator - Generator for the cache structure.
@@ -12,6 +12,9 @@
// Include Files /*{{{*/
#include <pkglib/deblistparser.h>
#include <pkglib/error.h>
+#include <pkglib/configuration.h>
+#include <strutl.h>
+
#include <system.h>
/*}}}*/
@@ -82,13 +85,13 @@ bool debListParser::HandleFlag(const char *Tag,unsigned long &Flags,
return true;
int Set = 2;
- if (strncasecmp(Start,"yes",Stop - Start) == 0)
+ if (stringcasecmp(Start,Stop,"yes") == 0)
Set = 1;
- if (strncasecmp(Start,"true",Stop - Start) == 0)
+ if (stringcasecmp(Start,Stop,"true") == 0)
Set = 1;
- if (strncasecmp(Start,"no",Stop - Start) == 0)
+ if (stringcasecmp(Start,Stop,"no") == 0)
Set = 0;
- if (strncasecmp(Start,"false",Stop - Start) == 0)
+ if (stringcasecmp(Start,Stop,"false") == 0)
Set = 0;
if (Set == 2)
{
@@ -489,6 +492,7 @@ bool debListParser::GrabWord(string Word,WordList *List,int Count,
bool debListParser::Step()
{
iOffset = Tags.Offset();
+ string Arch = _config->Find("APT::architecture");
while (Tags.Step(Section) == true)
{
/* See if this is the correct Architecture, if it isnt then we
@@ -497,13 +501,11 @@ bool debListParser::Step()
const char *Stop;
if (Section.Find("Architecture",Start,Stop) == false)
return true;
-
- if (strncmp(Start,"i386",Stop - Start) == 0 &&
- strlen("i386") == (unsigned)(Stop - Start))
+
+ if (stringcmp(Start,Stop,Arch.begin(),Arch.end()) == 0)
return true;
- if (strncmp(Start,"all",Stop - Start) == 0 &&
- 3 == (unsigned)(Stop - Start))
+ if (stringcmp(Start,Stop,"all") == 0)
return true;
iOffset = Tags.Offset();
diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc
new file mode 100644
index 000000000..5dd7b58aa
--- /dev/null
+++ b/apt-pkg/init.cc
@@ -0,0 +1,43 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: init.cc,v 1.1 1998/07/09 05:12:27 jgg Exp $
+/* ######################################################################
+
+ Init - Initialize the package library
+
+ ##################################################################### */
+ /*}}}*/
+// Include files /*{{{*/
+#include <pkglib/init.h>
+ /*}}}*/
+
+// pkglibInitialize - Initialize the configuration class /*{{{*/
+// ---------------------------------------------------------------------
+/* Directories are specified in such a way that the FindDir function will
+ understand them. That is, if they don't start with a / then their parent
+ is prepended, this allows a fair degree of flexability. */
+bool pkglibInitialize(Configuration &Cnf)
+{
+ // General APT things
+ Cnf.Set("APT::Architecture","i386");
+
+ // State
+ Cnf.Set("Dir::State","/var/state/apt/");
+ Cnf.Set("Dir::State::lists","lists/");
+ Cnf.Set("Dir::State::xstatus","xstatus");
+ Cnf.Set("Dir::State::userstatus","status.user");
+
+ // Cache
+ Cnf.Set("Dir::Cache","/etc/apt/");
+ Cnf.Set("Dir::Cache::archives","archives/");
+ Cnf.Set("Dir::Cache::srcpkgcache","srcpkgcache");
+ Cnf.Set("Dir::Cache::pkhcache","pkgcache");
+
+ // Configuration
+ Cnf.Set("Dir::Etc","/etc/apt/");
+ Cnf.Set("Dir::Etc::sourcelist","sources.list");
+ Cnf.Set("Dir::Etc::main","apt.conf");
+
+ return true;
+}
+ /*}}}*/
diff --git a/apt-pkg/init.h b/apt-pkg/init.h
new file mode 100644
index 000000000..bd03dd10d
--- /dev/null
+++ b/apt-pkg/init.h
@@ -0,0 +1,21 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: init.h,v 1.1 1998/07/09 05:12:27 jgg Exp $
+/* ######################################################################
+
+ Init - Initialize the package library
+
+ This function must be called to configure the config class before
+ calling many APT library functions.
+
+ ##################################################################### */
+ /*}}}*/
+// Header section: pkglib
+#ifndef PKGLIB_INIT_H
+#define PKGLIB_INIT_H
+
+#include <pkglib/configuration.h>
+
+bool pkglibInitialize(Configuration &Cnf);
+
+#endif
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index aac3f77d9..3e37c74f3 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.7 1998/07/07 04:17:04 jgg Exp $
+// $Id: pkgcachegen.cc,v 1.8 1998/07/09 05:12:27 jgg Exp $
/* ######################################################################
Package Cache Generator - Generator for the cache structure.
@@ -17,6 +17,7 @@
#include <pkglib/pkgcachegen.h>
#include <pkglib/error.h>
#include <pkglib/version.h>
+#include <strutl.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -329,9 +330,7 @@ unsigned long pkgCacheGenerator::WriteUniqString(const char *S,
for (; I != Cache.StringItemP; Last = &I->NextItem,
I = Cache.StringItemP + I->NextItem)
{
- Res = strncmp(Cache.StrP + I->String,S,Size);
- if (Res == 0 && *(Cache.StrP + I->String + Size) != 0)
- Res = 1;
+ Res = stringcmp(S,S+Size,Cache.StrP + I->String);
if (Res >= 0)
break;
}
diff --git a/apt-pkg/sourcelist.cc b/apt-pkg/sourcelist.cc
index 62d5e6fcd..bce3e5990 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.1 1998/07/07 04:17:06 jgg Exp $
+// $Id: sourcelist.cc,v 1.2 1998/07/09 05:12:28 jgg Exp $
/* ######################################################################
List of Sources
@@ -15,8 +15,8 @@
#include <pkglib/sourcelist.h>
#include <pkglib/error.h>
#include <pkglib/fileutl.h>
+#include <pkglib/configuration.h>
#include <strutl.h>
-#include <options.h>
#include <fstream.h>
#include <stdio.h>
@@ -41,7 +41,7 @@ pkgSourceList::pkgSourceList(string File)
/* */
bool pkgSourceList::ReadMainList()
{
- return Read(PKG_DEB_CF_SOURCELIST);
+ return Read(_config->Find("APT::Etc:sourcelist"));
}
/*}}}*/
// SourceList::Read - Parse the sourcelist file /*{{{*/
@@ -90,7 +90,7 @@ bool pkgSourceList::Read(string File)
{
if (ParseQuoteWord(C,Itm.Section) == true)
return _error->Error("Malformed line %u in source list %s (Absolute dist)",CurLine,File.c_str());
- Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",PKG_DEB_ARCH);
+ Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",_config->Find("APT::Architecture"));
List.push_back(Itm);
continue;
}
@@ -132,15 +132,15 @@ string pkgSourceList::SanitizeURI(string URI)
file */
pkgSourceList::const_iterator pkgSourceList::MatchPkgFile(pkgCache::VerIterator Ver)
{
- string Base = PKG_DEB_ST_LIST;
+ string Base = _config->Find("APT::Architecture");
for (const_iterator I = List.begin(); I != List.end(); I++)
{
string URI = I->PackagesURI();
switch (I->Type)
{
case Item::Deb:
- if (Base + SanitizeURI(URI) == Ver.File().FileName())
- return I;
+/* if (Base + SanitizeURI(URI) == Ver.File().FileName())
+ return I;*/
break;
};
}
@@ -182,7 +182,7 @@ bool pkgSourceList::Item::SetURI(string S)
if (S.find(':') == string::npos)
return false;
- S = SubstVar(S,"$(ARCH)",PKG_DEB_ARCH);
+ S = SubstVar(S,"$(ARCH)",_config->Find("APT::Architecture"));
// Make sure that the URN is / postfixed
URI = S;
@@ -204,8 +204,8 @@ string pkgSourceList::Item::PackagesURI() const
if (Dist[Dist.size() - 1] == '/')
Res = URI + Dist;
else
- Res = URI + "dists/" + Dist + '/' + Section +
- "/binary-" + PKG_DEB_ARCH + '/';
+ Res = URI + "dists/" + Dist + '/' + Section +
+ "/binary-" + _config->Find("APT::Architecture") + '/';
Res += "Packages";
break;
@@ -288,178 +288,3 @@ string pkgSourceList::Item::SiteOnly(string URI) const
return string(URI,0,Pos);
}
/*}}}*/
-
-// UpdateMeta - Update the meta information /*{{{*/
-// ---------------------------------------------------------------------
-/* The meta information is package files, revision information and mirror
- lists. */
-bool pkgUpdateMeta(pkgSourceList &List,pkgAquire &Engine)
-{
- if (Engine.OutputDir(PKG_DEB_ST_LIST) == false)
- return false;
-
- for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
- {
- string URI = I->PackagesURI();
- string GetInfo = I->PackagesInfo();
- switch (I->Type)
- {
- case pkgSourceList::Item::Deb:
- if (Engine.Get(URI + ".gz",List.SanitizeURI(URI),GetInfo) == false)
- return false;
- break;
- };
- }
-
- return true;
-}
- /*}}}*/
-// MakeSrcCache - Generate a cache file of all the package files /*{{{*/
-// ---------------------------------------------------------------------
-/* This goes over the source list and builds a cache of all the package
- files. */
-bool pkgMakeSrcCache(pkgSourceList &List)
-{
- // First we date check the cache
- bool Bad = false;
- while (Bad == false)
- {
- if (FileExists(PKG_DEB_CA_SRCCACHE) == false)
- break;
-
- pkgCache Cache(PKG_DEB_CA_SRCCACHE,true,true);
- if (_error->PendingError() == true)
- {
- _error->Discard();
- break;
- }
-
- // They are certianly out of sync
- if (Cache.Head().PackageFileCount != List.size())
- break;
-
- for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
- {
- // Search for a match in the source list
- Bad = true;
- for (pkgSourceList::const_iterator I = List.begin();
- I != List.end(); I++)
- {
- string File = string(PKG_DEB_ST_LIST) +
- List.SanitizeURI(I->PackagesURI());
- if (F.FileName() == File)
- {
- Bad = false;
- break;
- }
- }
-
- // Check if the file matches what was cached
- Bad |= !F.IsOk();
- if (Bad == true)
- break;
- }
-
- if (Bad == false)
- return true;
- }
-
- unlink(PKG_DEB_CA_SRCCACHE);
- pkgCache::MergeState Merge(PKG_DEB_CA_SRCCACHE);
- if (_error->PendingError() == true)
- return false;
-
- for (pkgSourceList::const_iterator I = List.begin(); I != List.end(); I++)
- {
- string File = string(PKG_DEB_ST_LIST) + List.SanitizeURI(I->PackagesURI());
- if (Merge.MergePackageFile(File,"??","??") == false)
- return false;
- }
-
- return true;
-}
- /*}}}*/
-// MakeStatusCache - Generates a cache that includes the status files /*{{{*/
-// ---------------------------------------------------------------------
-/* This copies the package source cache and then merges the status and
- xstatus files into it. */
-bool pkgMakeStatusCache()
-{
- // Quickly check if the existing package cache is ok
- bool Bad = false;
- while (Bad == false)
- {
- if (FileExists(PKG_DEB_CA_PKGCACHE) == false)
- break;
-
- /* We check the dates of the two caches. This takes care of most things
- quickly and easially */
- struct stat Src;
- struct stat Pkg;
- if (stat(PKG_DEB_CA_PKGCACHE,&Pkg) != 0 ||
- stat(PKG_DEB_CA_SRCCACHE,&Src) != 0)
- break;
- if (difftime(Src.st_mtime,Pkg.st_mtime) > 0)
- break;
-
- pkgCache Cache(PKG_DEB_CA_PKGCACHE,true,true);
- if (_error->PendingError() == true)
- {
- _error->Discard();
- break;
- }
-
- for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
- {
- if (F.IsOk() == false)
- {
- Bad = true;
- break;
- }
- }
-
- if (Bad == false)
- return true;
- }
-
- // Check the integrity of the source cache.
- {
- pkgCache Cache(PKG_DEB_CA_SRCCACHE,true,true);
- if (_error->PendingError() == true)
- return false;
- }
-
- // Sub scope so that merge destructs before we rename the file...
- string Cache = PKG_DEB_CA_PKGCACHE ".new";
- {
- if (CopyFile(PKG_DEB_CA_SRCCACHE,Cache) == false)
- return false;
-
- pkgCache::MergeState Merge(Cache);
- if (_error->PendingError() == true)
- return false;
-
- // Merge in the user status file
- if (FileExists(PKG_DEB_ST_USERSTATUS) == true)
- if (Merge.MergePackageFile(PKG_DEB_ST_USERSTATUS,"status","0",
- pkgFLAG_NotSource) == false)
- return false;
-
- // Merge in the extra status file
- if (FileExists(PKG_DEB_ST_XSTATUS) == true)
- if (Merge.MergePackageFile(PKG_DEB_ST_XSTATUS,"status","0",
- pkgFLAG_NotSource) == false)
- return false;
-
- // Merge in the status file
- if (Merge.MergePackageFile("/var/lib/dpkg/status","status","0",
- pkgFLAG_NotSource) == false)
- return false;
- }
-
- if (rename(Cache.c_str(),PKG_DEB_CA_PKGCACHE) != 0)
- return false;
-
- return true;
-}
- /*}}}*/
diff --git a/apt-pkg/sourcelist.h b/apt-pkg/sourcelist.h
index 986d5e9e8..43739fbcd 100644
--- a/apt-pkg/sourcelist.h
+++ b/apt-pkg/sourcelist.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: sourcelist.h,v 1.1 1998/07/07 04:17:06 jgg Exp $
+// $Id: sourcelist.h,v 1.2 1998/07/09 05:12:31 jgg Exp $
/* ######################################################################
SourceList - Manage a list of sources
@@ -69,10 +69,6 @@ class pkgSourceList
pkgSourceList(string File);
};
-bool pkgUpdateMeta(pkgSourceList &List,pkgAquire &Engine);
-bool pkgMakeSrcCache(pkgSourceList &List);
-bool pkgMakeStatusCache();
-
ostream &operator <<(ostream &O,pkgSourceList::Item &Itm);
#endif
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index b8845a3b1..aaef3da8b 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: tagfile.cc,v 1.5 1998/07/07 04:17:06 jgg Exp $
+// $Id: tagfile.cc,v 1.6 1998/07/09 05:12:32 jgg Exp $
/* ######################################################################
Fast scanner for RFC-822 type header information
@@ -17,6 +17,7 @@
#include <pkglib/tagfile.h>
#include <pkglib/error.h>
+#include <pkglib/init.h>
#include <string>
#include <stdio.h>
@@ -158,6 +159,10 @@ bool pkgTagSection::Find(const char *Tag,const char *&Start,
int main(int argc,char *argv[])
{
+ pkglibInitialize(*_config);
+ cout << _config->Find("APT::arch") << endl;
+ cout << _config->FindDir("DIR::Etc::sourcelist") << endl;
+
{
File CacheF("./cache",File::WriteEmpty);
DynamicMMap Map(CacheF,MMap::Public);
diff --git a/apt-pkg/templates.cc b/apt-pkg/templates.cc
new file mode 100644
index 000000000..0f86bde9a
--- /dev/null
+++ b/apt-pkg/templates.cc
@@ -0,0 +1,5 @@
+/* All template instances are explicly declared here */
+
+#include <pkglib/sourcelist.h>
+
+template vector<pkgSourceList::Item>;