std::string type() const
{ return _type; }
+
std::string checksum() const
{ return _checksum; }
bool empty() const
{ return (checksum().empty() || type().empty()); }
+
private:
std::string _type;
std::string _checksum;
cacheincludedir = $(pkgincludedir)/cache
-cacheinclude_HEADERS = KnownSourcesCache.h
+cacheinclude_HEADERS = SourceCache.h SourceCacher.h
## ##################################################
## ##################################################
-lib@PACKAGE@_cache_la_SOURCES = KnownSourcesCache.cpp
+lib@PACKAGE@_cache_la_SOURCES = SourceCache.cpp SourceCacher.cpp
lib@PACKAGE@_cache_la_LDFLAGS = @LIBZYPP_VERSION_INFO@
| |
\---------------------------------------------------------------------*/
+#include <vector>
+
#include "zypp/base/Logger.h"
-#include "zypp/cache/KnownSourcesCache.h"
+#include "zypp/base/String.h"
+#include "zypp/cache/SourceCache.h"
#include "zypp/target/store/PersistentStorage.h"
#include "zypp/cache/sqlite3x/sqlite3x.hpp"
namespace cache
{ /////////////////////////////////////////////////////////////////
-KnownSourcesCache::KnownSourcesCache( const Pathname &root_r )
+static int int_to_tribool( boost::tribool b )
+{
+ if (b)
+ return 1;
+ else if (!b)
+ return 0;
+ else
+ return 2;
+}
+
+static boost::tribool b tribool_to_int( int i )
+{
+ if (i==1)
+ return true;
+ else if (i==0)
+ return false;
+ else
+ return boost;indeterminate;
+}
+
+static std::string checksum_to_string( const CheckSum &checksum )
+{
+ return checksum.type() + ":" checksum.checksum();
+}
+
+static CheckSum string_to_checksum( const std::string &checksum )
+{
+ std::vector<std::string> words;
+ if ( str::split( checksum, std::back_inserter(words), ":" ) != 2 )
+ return CheckSum();
+
+ return CheckSum( words[0], words[19);
+}
+
+#define SOURCES_TABLE_SCHEMA "create table sources ( alias varchar primary key, type varchar, description varchar, url varchar, path varchar, enabled integer, autorefresh integer, timestamp varchar, checksum varchar);"
+
+// alias 0 , type 1, desc 2, url 3, path 4, enabled 5, autorefresh 6, timestamp 7, checksum 8
+
+SourceCache::SourceCache( const Pathname &root_r )
{
try
{
int count = con.executeint("select count(*) from sqlite_master where type='table' and name='sources';");
if( count==0 )
{
- con.executenonquery("create table sources ( id integer primary key autoincrement, alias varchar, url varchar, description varchar, enabled integer, autorefresh integer, type varchar, cachedir varchar, path varchar);");
+ con.executenonquery(SOURCES_TABLE_SCHEMA);
try
{
}
}
-KnownSourcesCache::~KnownSourcesCache()
+SourceCache::~SourceCache()
{
}
-source::SourceInfoList KnownSourcesCache::knownSources() const
+source::SourceInfoList SourceCache::knownSources() const
{
source::SourceInfoList sources;
while(reader.read())
{
+ // alias 0 , type 1, desc 2, url 3, path 4, enabled 5, autorefresh 6, timestamp 7, checksum 8
source::SourceInfo info;
- info.setAlias(reader.getstring(1));
- info.setUrl(reader.getstring(2));
- info.setEnabled( (reader.getint(4) == 1 ) ? true : false );
- info.setAutorefresh( (reader.getint(5) == 1 ) ? true : false );
- info.setType(reader.getstring(6));
- info.setCacheDir(reader.getstring(7));
- info.setPath(reader.getstring(8));
+ info.setAlias(reader.getstring(0));
+ info.setType(reader.getstring(1));
+ info.setDescription(reader.getstring(2));
+ info.setUrl(reader.getstring(3));
+ info.setPath(reader.getstring(4));
+ info.setEnabled( int_to_tribool(reader.getint(5)) );
+ info.setAutorefresh( int_to_tribool( reader.getint(6) ));
+ info.setTimestamp(reader.getstring(7));
+ info.setChecksum(string_to_checksum(reader.getstring(8)));
sources.push_back(info);
}
}
return sources;
}
-void KnownSourcesCache::storeSource( const source::SourceInfo &info )
+void SourceCache::storeSource( const source::SourceInfo &info )
{
try
{
sqlite3_transaction trans(con);
{
- sqlite3_command cmd(con, "insert into sources ( alias, url, description, enabled, autorefresh, type, cachedir, path) values ( ?, ?, ?, ? , ?, ?, ?, ?);");
- cmd.bind(1, info.alias());
- cmd.bind(2, info.url().asCompleteString());
- // FIXME no description
- cmd.bind(4, info.enabled() ? 1 : 0 );
- cmd.bind(5, info.autorefresh() ? 1 : 0 );
- cmd.bind(6, info.type());
- cmd.bind(7, info.cacheDir().asString());
- cmd.bind(8, info.path().asString());
+ // alias 0 , type 1, desc 2, url 3, path 4, enabled 5, autorefresh 6, timestamp 7, checksum 8
+
+ sqlite3_command cmd(con, "insert into sources ( alias, type, description, url, path, enabled, autorefresh, timestamp, checksum ) values ( ?, ?, ?, ? , ?, ?, ?, ?, ?);");
+ cmd.bind(0, info.alias());
+ cmd.bind(1, info.type());
+ cmd.bind(2, info.description());
+ cmd.bind(3, info.url().asCompleteString());
+ cmd.bind(4, info.path().asString());
+ cmd.bind(5, tribool_to_int(info.enabled()) );
+ cmd.bind(6, tribool_to_int(info.autorefresh()) );
+ cmd.bind(7, info.timestamp().asString());
+ cmd.bind(8, checksum_to_string(info.checksum()) );
cmd.executenonquery();
}
}
}
-std::ostream & KnownSourcesCache::dumpOn( std::ostream & str ) const
+std::ostream & SourceCache::dumpOn( std::ostream & str ) const
{
return str;
}
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
-/** \file zypp/KnownSourcesCache.h
+/** \file zypp/SourceCache.h
*
*/
-#ifndef ZYPP_KnownSourcesCache_H
-#define ZYPP_KnownSourcesCache_H
+#ifndef ZYPP_SourceCache_H
+#define ZYPP_SourceCache_H
#include <iosfwd>
#include <string>
namespace cache
{ /////////////////////////////////////////////////////////////////
- DEFINE_PTR_TYPE(KnownSourcesCache);
+ DEFINE_PTR_TYPE(SourceCache);
///////////////////////////////////////////////////////////////////
//
- // CLASS NAME : KnownSourcesCache
+ // CLASS NAME : SourceCache
//
- class KnownSourcesCache : public base::ReferenceCounted, private base::NonCopyable
+ class SourceCache : public base::ReferenceCounted, private base::NonCopyable
{
- friend std::ostream & operator<<( std::ostream & str, const KnownSourcesCache & obj );
+ friend std::ostream & operator<<( std::ostream & str, const SourceCache & obj );
public:
/** root path */
- KnownSourcesCache( const Pathname &root_r );
- ~KnownSourcesCache();
+ SourceCache( const Pathname &root_r );
+ ~SourceCache();
source::SourceInfoList knownSources() const;
void storeSource( const source::SourceInfo &info );
protected:
};
///////////////////////////////////////////////////////////////////
- /** \relates KnownSourcesCache Stream output */
- inline std::ostream & operator<<( std::ostream & str, const KnownSourcesCache & obj )
+ /** \relates SourceCache Stream output */
+ inline std::ostream & operator<<( std::ostream & str, const SourceCache & obj )
{ return obj.dumpOn( str ); }
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
-#endif // ZYPP_SOURCE_KnownSourcesCache_H
+#endif // ZYPP_SOURCE_SourceCache_H
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#include "zypp/base/Logger.h"
+#include "zypp/cache/SourceCacher.h"
+
+using namespace std;
+
+//////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace cache
+{ /////////////////////////////////////////////////////////////////
+
+SourceCacher::SourceCacher( const Pathname &root_r )
+{
+}
+
+SourceCacher::~SourceCacher()
+{
+}
+
+
+}
+}
+
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/SourceCacher.h
+ *
+*/
+#ifndef ZYPP_SourceCacher_H
+#define ZYPP_SourceCacher_H
+
+#include <iosfwd>
+#include <string>
+
+#include "zypp/base/ReferenceCounted.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/base/PtrTypes.h"
+#include "zypp/source/SourceInfo.h"
+#include "zypp/Pathname.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace cache
+ { /////////////////////////////////////////////////////////////////
+
+ DEFINE_PTR_TYPE(SourceCacher);
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : SourceCacher
+ //
+ class SourceCacher : public base::ReferenceCounted, private base::NonCopyable
+ {
+ friend std::ostream & operator<<( std::ostream & str, const SourceCacher & obj );
+
+ public:
+ /** root path */
+ SourceCacher( const Pathname &root_r );
+ ~SourceCacher();
+ protected:
+
+ /** Overload to realize stream output. */
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ //typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates SourceCacher Stream output */
+ inline std::ostream & operator<<( std::ostream & str, const SourceCacher & obj )
+ { return obj.dumpOn( str ); }
+
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace cache
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SOURCE_SourceCacher_H
return *this;
}
+ SourceInfo & SourceInfo::setDescription( const std::string &description )
+ {
+ _description = description;
+ return *this;
+ }
+
+ SourceInfo & SourceInfo::setChecksum( const CheckSum &checksum )
+ {
+ _checksum = checksum;
+ return *this;
+ }
+
+ SourceInfo & SourceInfo::setTimesamp( const Date ×tamp )
+ {
+ _timestamp = timestamp;
+ return *this;
+ }
+
tribool SourceInfo::enabled() const
{ return _enabled; }
std::string SourceInfo::alias() const
{ return _alias; }
+
+ std::string SourceInfo::description() const
+ { return _description; }
+ CheckSum SourceInfo::checksum() const
+ { return _checksum; }
+
+ Date SourceInfo::timestamp() const
+ { return _timestamp; }
+
std::string SourceInfo::type() const
{ return _type; }
#include <boost/logic/tribool.hpp>
#include "zypp/Pathname.h"
#include "zypp/Url.h"
+#include "zypp/CheckSum.h"
+#include "zypp/Date.h"
///////////////////////////////////////////////////////////////////
namespace zypp
SourceInfo & setAlias( const std::string &alias );
SourceInfo & setType( const std::string &t );
SourceInfo & setCacheDir( const Pathname &p );
+ SourceInfo & setDescription( const std::string &description );
+ SourceInfo & setChecksum( const CheckSum &checksum );
+ SourceInfo & setTimesamp( const Date ×tamp );
boost::tribool enabled() const;
boost::tribool autorefresh() const;
Pathname cacheDir() const;
Pathname path() const;
std::string alias() const;
std::string type() const;
+ std::string description() const;
+ CheckSum checksum() const;
+ Date timestamp() const;
Url url() const;
+
/** Overload to realize stream output. */
std::ostream & dumpOn( std::ostream & str ) const;
Pathname _cache_dir;
Pathname _path;
std::string _alias;
+ std::string _description;
+ CheckSum _checksum;
+ Date _timestamp;
};
/** \relates SourceInfo Stream output */