From a91565ac12c48b39d3f2b328bb5906bb9f45a271 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 22 Jun 2006 14:14:22 +0000 Subject: [PATCH] fork of Klaus dbsource, will be used as cache soon or later as we redesign the sources. --- configure.ac | 3 +- zypp/source/Makefile.am | 8 +- zypp/source/sqlite-source/Makefile.am | 42 + zypp/source/sqlite-source/SqliteAccess.cc | 1158 +++++++++++++++++++++++ zypp/source/sqlite-source/SqliteAccess.h | 221 +++++ zypp/source/sqlite-source/SqliteAtomImpl.cc | 49 + zypp/source/sqlite-source/SqliteAtomImpl.h | 49 + zypp/source/sqlite-source/SqliteLanguageImpl.cc | 49 + zypp/source/sqlite-source/SqliteLanguageImpl.h | 49 + zypp/source/sqlite-source/SqliteMessageImpl.cc | 57 ++ zypp/source/sqlite-source/SqliteMessageImpl.h | 52 + zypp/source/sqlite-source/SqlitePackageImpl.cc | 127 +++ zypp/source/sqlite-source/SqlitePackageImpl.h | 78 ++ zypp/source/sqlite-source/SqlitePatchImpl.cc | 116 +++ zypp/source/sqlite-source/SqlitePatchImpl.h | 89 ++ zypp/source/sqlite-source/SqlitePatternImpl.cc | 96 ++ zypp/source/sqlite-source/SqlitePatternImpl.h | 74 ++ zypp/source/sqlite-source/SqliteProductImpl.cc | 95 ++ zypp/source/sqlite-source/SqliteProductImpl.h | 68 ++ zypp/source/sqlite-source/SqliteScriptImpl.cc | 85 ++ zypp/source/sqlite-source/SqliteScriptImpl.h | 57 ++ zypp/source/sqlite-source/SqliteSourceImpl.cc | 882 +++++++++++++++++ zypp/source/sqlite-source/SqliteSourceImpl.h | 95 ++ zypp/source/sqlite-source/SqliteSources.cc | 243 +++++ zypp/source/sqlite-source/SqliteSources.h | 63 ++ 25 files changed, 3901 insertions(+), 4 deletions(-) create mode 100644 zypp/source/sqlite-source/Makefile.am create mode 100644 zypp/source/sqlite-source/SqliteAccess.cc create mode 100644 zypp/source/sqlite-source/SqliteAccess.h create mode 100644 zypp/source/sqlite-source/SqliteAtomImpl.cc create mode 100644 zypp/source/sqlite-source/SqliteAtomImpl.h create mode 100644 zypp/source/sqlite-source/SqliteLanguageImpl.cc create mode 100644 zypp/source/sqlite-source/SqliteLanguageImpl.h create mode 100644 zypp/source/sqlite-source/SqliteMessageImpl.cc create mode 100644 zypp/source/sqlite-source/SqliteMessageImpl.h create mode 100644 zypp/source/sqlite-source/SqlitePackageImpl.cc create mode 100644 zypp/source/sqlite-source/SqlitePackageImpl.h create mode 100644 zypp/source/sqlite-source/SqlitePatchImpl.cc create mode 100644 zypp/source/sqlite-source/SqlitePatchImpl.h create mode 100644 zypp/source/sqlite-source/SqlitePatternImpl.cc create mode 100644 zypp/source/sqlite-source/SqlitePatternImpl.h create mode 100644 zypp/source/sqlite-source/SqliteProductImpl.cc create mode 100644 zypp/source/sqlite-source/SqliteProductImpl.h create mode 100644 zypp/source/sqlite-source/SqliteScriptImpl.cc create mode 100644 zypp/source/sqlite-source/SqliteScriptImpl.h create mode 100644 zypp/source/sqlite-source/SqliteSourceImpl.cc create mode 100644 zypp/source/sqlite-source/SqliteSourceImpl.h create mode 100644 zypp/source/sqlite-source/SqliteSources.cc create mode 100644 zypp/source/sqlite-source/SqliteSources.h diff --git a/configure.ac b/configure.ac index ac7e4e3..3d5cf32 100644 --- a/configure.ac +++ b/configure.ac @@ -246,7 +246,8 @@ AC_OUTPUT( po/Makefile.in\ zypp/source/plaindir/Makefile \ zypp/source/susetags/Makefile \ zypp/source/yum/Makefile \ - zypp/media/Makefile \ + zypp/source/sqlite-source/Makefile \ + zypp/media/Makefile \ zypp/media/proxyinfo/Makefile \ zypp/ui/Makefile \ zypp/url/Makefile \ diff --git a/zypp/source/Makefile.am b/zypp/source/Makefile.am index 786c956..952d039 100644 --- a/zypp/source/Makefile.am +++ b/zypp/source/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## ################################################## -SUBDIRS = plaindir susetags yum +SUBDIRS = plaindir susetags yum sqlite-source INCLUDES = \ -DZYPP_BASE_LOGGER_LOGGROUP=\"source\" @@ -14,7 +14,8 @@ sourceinclude_HEADERS = \ SourceImpl.h \ Builtin.h \ PackageDelta.h \ - MediaSet.h + MediaSet.h \ + SourceCreateContext.h noinst_LTLIBRARIES = lib@PACKAGE@_source.la @@ -29,6 +30,7 @@ lib@PACKAGE@_source_la_SOURCES = \ lib@PACKAGE@_source_la_LIBADD = \ plaindir/lib@PACKAGE@_source_plaindir.la \ susetags/lib@PACKAGE@_source_susetags.la \ - yum/lib@PACKAGE@_source_yum.la + yum/lib@PACKAGE@_source_yum.la \ + sqlite-source/lib@PACKAGE@_source_sqlite.la ## ################################################## diff --git a/zypp/source/sqlite-source/Makefile.am b/zypp/source/sqlite-source/Makefile.am new file mode 100644 index 0000000..e1e2b88 --- /dev/null +++ b/zypp/source/sqlite-source/Makefile.am @@ -0,0 +1,42 @@ +# +# Makefile.am for zmd/backend/dbsource +# + +INCLUDES = \ + -I$(top_srcdir) $(ZYPP_CFLAGS) -Wall \ + -DG_LOG_DOMAIN=\"sqlite-source\" \ + -DZYPP_BASE_LOGGER_LOGGROUP=\"sqlite-source\" + +sourceincludedir = $(pkgincludedir)/source + +pkginclude_HEADERS = \ + SqliteSources.h \ + SqliteAccess.h + +sourceinclude_HEADERS = \ + SqliteSourceImpl.h \ + SqlitePackageImpl.h \ + SqliteAtomImpl.h \ + SqliteScriptImpl.h \ + SqliteMessageImpl.h \ + SqliteLanguageImpl.h \ + SqlitePatchImpl.h \ + SqlitePatternImpl.h \ + SqliteProductImpl.h + +noinst_LTLIBRARIES = lib@PACKAGE@_source_sqlite.la + +lib@PACKAGE@_source_sqlite_la_SOURCES = \ + SqliteSourceImpl.cc \ + SqlitePackageImpl.cc \ + SqliteAtomImpl.cc \ + SqliteScriptImpl.cc \ + SqliteMessageImpl.cc \ + SqliteLanguageImpl.cc \ + SqlitePatchImpl.cc \ + SqlitePatternImpl.cc \ + SqliteProductImpl.cc \ + SqliteSources.cc \ + SqliteAccess.cc + +lib@PACKAGE@_source_sqlite_la_LBADD = -lsqlite3 diff --git a/zypp/source/sqlite-source/SqliteAccess.cc b/zypp/source/sqlite-source/SqliteAccess.cc new file mode 100644 index 0000000..b3817c6 --- /dev/null +++ b/zypp/source/sqlite-source/SqliteAccess.cc @@ -0,0 +1,1158 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zmd/backend/dbsource/SqliteAccess.cc + * +*/ + +#include +#include + +#include "zypp/base/Logger.h" +#include "zypp/ZYppFactory.h" +#include "zypp/Source.h" +#include "SqliteAccess.h" + +IMPL_PTR_TYPE(SqliteAccess); + +#undef ZYPP_BASE_LOGGER_LOGGROUP +#define ZYPP_BASE_LOGGER_LOGGROUP "SqliteAccess" + +using namespace std; +using namespace zypp; + + +static struct archrc { + char *arch; + RCArch rc; + } archtable[] = { + { "noarch", RC_ARCH_NOARCH }, + { "i386", RC_ARCH_I386 }, + { "i486", RC_ARCH_I486 }, + { "i586", RC_ARCH_I586 }, + { "i686", RC_ARCH_I686 }, + { "x86_64", RC_ARCH_X86_64 }, + { "ia32e", RC_ARCH_IA32E }, + { "athlon", RC_ARCH_ATHLON }, + { "ppc", RC_ARCH_PPC }, + { "ppc64", RC_ARCH_PPC64 }, + { "s390", RC_ARCH_S390 }, + { "s390x", RC_ARCH_S390X }, + { "ia64", RC_ARCH_IA64 }, + { "sparc", RC_ARCH_SPARC }, + { "sparc64", RC_ARCH_SPARC64 }, + { NULL, RC_ARCH_UNKNOWN } + }; + + +//---------------------------------------------------------------------------- + +// check if source is local for zypp + +static bool +source_is_local( Source_Ref source ) +{ + return false; + + if (!source) return true; + + string scheme = source.url().getScheme(); +// DBG << "Source url '" << src.url() << "', scheme '" << scheme << "'" << endl; + return (scheme == "cd" + || scheme == "dvd" + || scheme == "file" + || scheme == "dir" + || scheme == "hd" + || scheme == "iso" + || scheme == "smb" + || scheme == "nfs"); +} + +//---------------------------------------------------------------------------- + +// Convert ZYPP relation operator to ZMD RCResolvableRelation + +RCResolvableRelation +SqliteAccess::Rel2Rc (Rel op) +{ + + /* This enum is here so that gdb can give us pretty strings */ + + switch (op.inSwitch()) { + case Rel::EQ_e: return RC_RELATION_EQUAL; break; + case Rel::NE_e: return RC_RELATION_NOT_EQUAL; break; + case Rel::LT_e: return RC_RELATION_LESS; break; + case Rel::LE_e: return RC_RELATION_LESS_EQUAL; break; + case Rel::GT_e: return RC_RELATION_GREATER; break; + case Rel::GE_e: return RC_RELATION_GREATER_EQUAL; break; + case Rel::ANY_e: return RC_RELATION_ANY; break; + case Rel::NONE_e: return RC_RELATION_NONE; break; + } + return RC_RELATION_INVALID; +} + + +Rel +SqliteAccess::Rc2Rel (RCResolvableRelation rel) +{ + switch (rel) { + case RC_RELATION_INVALID: return Rel::NONE; break; + case RC_RELATION_ANY: return Rel::ANY; break; + case RC_RELATION_EQUAL: return Rel::EQ; break; + case RC_RELATION_LESS: return Rel::LT; break; + case RC_RELATION_LESS_EQUAL: return Rel::LE; break; + case RC_RELATION_GREATER: return Rel::GT; break; + case RC_RELATION_GREATER_EQUAL: return Rel::GE; break; + case RC_RELATION_NOT_EQUAL: return Rel::NE; break; + case RC_RELATION_NONE: return Rel::ANY; break; + } + return Rel::NONE; +} + +//---------------------------------------------------------------------------- + +// convert ZYPP architecture string to ZMD int + +RCArch +SqliteAccess::Arch2Rc (const Arch & arch) +{ + string arch_str = arch.asString(); + struct archrc *aptr = archtable; + while (aptr->arch != NULL) { + if (arch_str == aptr->arch) + break; + aptr++; + } + + return aptr->rc; +} + +Arch +SqliteAccess::Rc2Arch (RCArch rc) +{ + if (rc == RC_ARCH_UNKNOWN) + return Arch(); + + struct archrc *aptr = archtable; + while (aptr->arch != NULL) { + if (aptr->rc == rc) { + return Arch (aptr->arch); + } + aptr++; + } + WAR << "SqliteAccess::Rc2Arch(" << rc << ") unknown" << endl; + return Arch (); +} + + +// convert description Text (list) to a single string +static string +desc2str (const Text t) +{ + static string s; // static so we can use sqlite STATIC below + s.clear(); + string::size_type authors = t.find ("Authors:"); // strip off 'Authors:' + if (authors != string::npos) { + do { + --authors; + } while (t[authors] == ' ' || t[authors] == '\n'); + } + s = string (t, 0, authors); + return s; +} + +//---------------------------------------------------------------------------- +// convert ZYPP Resolvable kind to ZMD RCDependencyTarget + +static RCDependencyTarget +kind2target( Resolvable::Kind kind ) +{ + if (kind == ResTraits::kind) return RC_DEP_TARGET_PACKAGE; + else if (kind == ResTraits