#ifndef ZYPP_CHECKSUM_H
#define ZYPP_CHECKSUM_H
+#include <string>
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
: _type(type)
, _checksum(checksum)
{}
- std::string type() { return _type; }
- std::string checksum() { return _checksum; }
+
+ CheckSum()
+ {}
+
+ std::string type() const
+ { return _type; }
+ std::string checksum() const
+ { return _checksum; }
private:
std::string _type;
std::string _checksum;
Pathname lock_file = Pathname(ZYPP_LOCK_FILE);
_zypp_lockfile = fopen(lock_file.asString().c_str(), mode);
if (_zypp_lockfile == 0)
- ZYPP_THROW (Exception( "Cant open " + lock_file.asString() ) );
+ ZYPP_THROW (Exception( "Cant open " + lock_file.asString() + " in mode " + std::string(mode) ) );
}
void closeLockFile()
if ( locker_pid == curr_pid )
{
// alles ok, we are requesting the instance again
- MIL << "Lockfile found, but it is myself. Assuming same process getting zypp instance again." << std::endl;
+ //MIL << "Lockfile found, but it is myself. Assuming same process getting zypp instance again." << std::endl;
return false;
}
else
{
if ( isProcessRunning(locker_pid) )
{
- MIL << locker_pid << " is running and has a ZYpp lock. Sorry" << std::endl;
- return true;
- }
- else
- {
- MIL << locker_pid << " has a ZYpp lock, but process is not running. Cleaning lock file." << std::endl;
- if ( filesystem::unlink(lock_file) == 0 )
+ if ( geteuid() == 0 )
{
- createLockFile();
- // now open it for reading
- openLockFile("r");
- shLockFile();
- return false;
+ // i am root
+ MIL << locker_pid << " is running and has a ZYpp lock. Sorry" << std::endl;
+ return true;
}
else
{
- ERR << "Can't clean lockfile. Sorry, can't create a new lock. Zypp still locked." << std::endl;
- return true;
+ MIL << locker_pid << " is running and has a ZYpp lock. Access as normal user allowed." << std::endl;
+ return false;
+ }
+ }
+ else
+ {
+ if ( geteuid() == 0 )
+ {
+ MIL << locker_pid << " has a ZYpp lock, but process is not running. Cleaning lock file." << std::endl;
+ if ( filesystem::unlink(lock_file) == 0 )
+ {
+ createLockFile();
+ // now open it for reading
+ openLockFile("r");
+ shLockFile();
+ return false;
+ }
+ else
+ {
+ ERR << "Can't clean lockfile. Sorry, can't create a new lock. Zypp still locked." << std::endl;
+ return true;
+ }
}
}
}
}
else
{
- createLockFile();
- // now open it for reading
- openLockFile("r");
- shLockFile();
+ if ( geteuid() == 0 )
+ {
+ createLockFile();
+ // now open it for reading
+ openLockFile("r");
+ shLockFile();
+ }
return false;
}
+ return true;
}
};
//
ZYpp::Ptr ZYppFactory::getZYpp() const
{
- static ZYpp::Ptr _instance( new ZYpp( ZYpp::Impl_Ptr(new ZYpp::Impl) ) );
- if ( globalLock.zyppLocked() )
- return 0;
- else
+ static ZYpp::Ptr _instance;
+
+ if ( _instance )
+ {
return _instance;
+ }
+ else
+ {
+ if ( globalLock.zyppLocked() )
+ {
+ return 0;
+ }
+ else
+ {
+ _instance = new ZYpp( ZYpp::Impl_Ptr(new ZYpp::Impl) );
+ return _instance;
+ }
+ }
}
/******************************************************************
prodImpl->_language = value;
else if(key == "TIMEZONE")
prodImpl->_timezone = value;
+ else if(key == "META")
+ parseFileCheckSum( key, value, prodImpl->_descr_files_checksums);
else
DBG << "parse error" << std::endl;
}
}
}
+ void ProductMetadataParser::parseFileCheckSum( const std::string &key, const std::string &value, std::map<std::string, CheckSum> &container)
+ {
+ std::list<std::string> splitted;
+ str::split( value, std::back_inserter(splitted), " ");
+ if (splitted.size() != 3)
+ {
+ ERR << "Parse error in checksum. Expected [type checksum file], got [" << value << "]" << std::endl;
+ }
+ else
+ {
+ std::string checksum_type = splitted.front();
+ splitted.pop_front();
+ std::string checksum_str = splitted.front();
+ splitted.pop_front();
+ std::string filename = splitted.front();
+ splitted.pop_front();
+ MIL << "Checksum for " << filename << " is " << checksum_str << " (" << checksum_type << ")" << std::endl;
+ container[filename] = CheckSum(checksum_type, checksum_str);
+ }
+ }
/////////////////////////////////////////////////////////////////
} // namespace susetags
///////////////////////////////////////////////////////////////////
#include "zypp/parser/tagfile/ParseException.h"
+#include "zypp/CheckSum.h"
#include "zypp/Pathname.h"
#include "zypp/Product.h"
#include "zypp/source/susetags/SuseTagsProductImpl.h"
* REQUIRES line
*/
void parseRequires( const std::string &key, const std::string &value, zypp::CapSet &container);
+
+ void parseFileCheckSum( const std::string &key, const std::string &value, std::map<std::string, CheckSum> &container);
+
};
///////////////////////////////////////////////////////////////////
#ifndef ZYPP_DETAIL_SUSETAGS_PRODUCTIMPL_H
#define ZYPP_DETAIL_SUSETAGS_PRODUCTIMPL_H
+#include <map>
+
+#include "zypp/CheckSum.h"
#include "zypp/CapSet.h"
#include "zypp/detail/ProductImplIf.h"
#include "zypp/Source.h"
std::string _language;
std::string _timezone;
+ std::map<std::string, CheckSum> _descr_files_checksums;
+
Source_Ref _source;
+
};
///////////////////////////////////////////////////////////////////