From ce8bb20b3694d21efab0aa4a15f7be6fe88d75c9 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Wed, 8 Feb 2006 14:08:19 +0000 Subject: [PATCH] move md5 out to a helper method. and implement removing a source from cache --- zypp/target/store/XMLFilesBackend.cc | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/zypp/target/store/XMLFilesBackend.cc b/zypp/target/store/XMLFilesBackend.cc index 24debef..ac2d7ee 100644 --- a/zypp/target/store/XMLFilesBackend.cc +++ b/zypp/target/store/XMLFilesBackend.cc @@ -700,8 +700,16 @@ XMLFilesBackend::storedSources() const } -static std::string hexDigest(const md5_byte_t *digest) +static std::string hexDigest(const std::string &message) { + md5_state_t state; + md5_byte_t digest[16]; + + md5_init(&state); + /* Append a string to the message. */ + md5_append(&state, (md5_byte_t*) message.c_str(), message.size()); /* Finish the message and return the digest. */ + md5_finish(&state, digest); + char s[33]; int i; for (i=0; i<16; i++) @@ -714,6 +722,7 @@ static std::string hexDigest(const md5_byte_t *digest) void XMLFilesBackend::storeSource(const PersistentStorage::SourceData &data) { + // serialize and save a file std::string xml = toXML(data); path source_p = path(d->root.asString()) / path(ZYPP_DB_DIR) / path ("source-cache"); @@ -722,22 +731,13 @@ XMLFilesBackend::storeSource(const PersistentStorage::SourceData &data) { ZYPP_THROW(Exception("Cant save source with empty alias")); } - //MD5 md5(ss); - md5_state_t state; - md5_byte_t digest[16]; - md5_init(&state); - /* Append a string to the message. */ - std::string alias = data.alias; - md5_append(&state, (md5_byte_t*) alias.c_str(), alias.size()); /* Finish the message and return the digest. */ - md5_finish(&state, digest); - //DBG << std::endl << xml << std::endl; std::ofstream file; //DBG << filename << std::endl; try { - std::string full_path = (source_p / hexDigest(digest)).string(); + std::string full_path = (source_p / hexDigest(data.alias)).string(); file.open(full_path.c_str()); file << xml; @@ -753,7 +753,18 @@ XMLFilesBackend::storeSource(const PersistentStorage::SourceData &data) void XMLFilesBackend::deleteSource(const std::string &alias) { - + // just delete the files + path source_p = path(d->root.asString()) / path(ZYPP_DB_DIR) / path ("source-cache"); + try + { + std::string full_path = (source_p / hexDigest(alias)).string(); + remove(full_path); + } + catch ( std::exception &e ) + { + ERR << "Error deleting source " << alias << " in the cache" << std::endl; + ZYPP_THROW(Exception(e.what())); + } } ///////////////////////////////////////////////////////////////// -- 2.7.4