Mailinglist Archive: zypp-devel (148 mails)

< Previous Next >
[zypp-devel] api proposal for locks
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Thu, 27 Mar 2008 16:11:04 +0100
  • Message-id: <47EBB908.3000407@xxxxxxx>
Hi,
I'm sending my proposal for locks API in the attachment. See FATE #120118 and [1] (locks).

The attachment contains io api for locks file and locks-to-pool bridge. Also some functions telling which Resolvables a lock or several locks cover.

question about C++ (function addLocks). I need distinguish between container that contains resolvables and locks. Is this possible in C++? (like Collection<Lock> and Collection<Resolvable> in java?)

some ideas how to solve the issue with support of regexes or wildcards in the locks file:

- keep support of regexes in the locks file - have function which does something like locks coverage. How would it work? It would get old locks and resolvables which the user wanted to lock (including the changed ones). Then, for each lock it gets all matching available resolvables and checks if the set is a subset of currently locked resolvables. If it is, those resolvables are marked as already locked (written/covered/whatever) and the lock is written back to the locks file unchanged (meaning if it was a regex, it will stay so). Thus the remaining resolvables will be written to the locks file individually (without using any regex).

This may not be trivial.

- drop regex support and write one lock per resolvable

- use two files for user (regex) locks and UI locks (as suggested in [1])


Other issues:
- how to clean up or maintain the locks file, it will probably be a mess
after some time
- the locks file format will be extended to include resolvable kind. The
question is whether we want to support also something else
(architecture, vendor, ...)
- the API supports locks file <-> pool manipulation as well as direct
to/from locks manipulation, is it OK?

thanks for comments, Pepa

[1] http://lists.opensuse.org/yast-devel/2008-03/msg00158.html
namespace zypp{
namespace locks{

/**
* class representing one lock record
* \TODO maybe some iostream operator help writing to file or let it
* to logging purpose?
*
* format in lock file: PATTERN [ OP EDITION ][;TYPE[;ARCH]]
*/
class Lock {
public:

/**
* default ctor
* \TODO what default kind, is nokind OK?
*/
Lock (const std::string& pattern = std::string(),
const EditionRestrict& edRestrict = EditionRestrict(),
const ResKind& kind = ResKind::nokind, const Arch& arch);

/**
* Ctor without specify restriction on editation
* f.e. kde*;package;x86_64
*/
Lock (const std::string& pattern,
const ResKind& kind = ResKind::nokind, const Arch& arch);


/**
* Gets name regex for lock like kde* or xfvw4.
*/
std::string getPattern() const;

/**
* Structs representition restriction on version like <= 4.3.0
* empty can be recognized by edition==noedition and op=NONE
*/
Rel getOp() const;

Edition getEdition() const;

/**
* Gets kind restriction of lock record.
* nokind mean no restriction.
* \TODO can one lock have more then one kind restriction?
*/
ResKind getKind() const;

/**
* Gets architecture restriction.
* noarch mean no restriction.
* \TODO allow more then one arch restrict in one lock?
*/
Arch getArch() const;

/**
* setters for upper methods\
*/
void setPattern( const std::string &name );
void setEdition( const Edition &edition, const Rel &op = Rel::EQ );
void setArch( const Arch &arch);

/**
* gets true if lock is identical
* \TODO maybe add operator== and != instead - DAT
*/
bool equal(const Lock &lock) const;

/**
* Help determine if Pattern contains any * or ?
*
*/
bool isPatternRegex() const;

class Impl;

private:

RWCOW_pointer<Impl> _pimpl;
};

/**
* write lock to stream
*/
std::ostream & operator<<( std::ostream & str, const Lock & obj );

/**
* read lock from istream
*/
std::istream & operator>>( std::istream & str, Lock & obj );

/**
* Represents settings for lockFiles. Now contains only path to lockfile.
*/
struct LocksOptions{
Pathname Lockfile;

LocksOptions();
}

class Locks {

public:
class Impl;

/**
* ctor
*/
Locks( const LocksOptions &options = LocksOptions() );

/**
* adds lock to file
* \throw IO exception, ?some bad lock related?
*/
void addLock( const Lock &lock ) const;

/**
* adds lock that lock resolvable to file
*/
void addLock( const Resolvable &res ) const;

/**
* adds more locks to file, passed by iterators
* \TODO this templating not work, how to change it to work??? idea is clear,
implementation not
* something like java Collection<Lock> and second Collection<Resolvable>
* \TODO maybe this need another universal function which send lock to outpur
stream
*/
template<typename Container>
void addLocks( Container<Lock> &container ) const;
template<typename Container>
void addLocks( Container<Resolvable> &container ) const;

/**
* reads locks from file and send it to output
*/
template <class OutputIterator>
unsigned readLocks( OutputIterator output ) const;

/**
* removes all locks in container from file
*/
template <class Container>
void removeLocks( Container &container ) const;

/**
* removes single lock from file
*/
void removeLock( const Lock& lock ) const;

/**
* Truncates file and write locks to it
*/
template<typename Container>
void writeLocks( Container &container ) const;

/**
* Sends to output every Resolvable which is locked by locks in container
*/
template<class OutputIterator, typename Container>
unsigned lockedResolvables( Container &container, OutputIterator output )
const;

/**
* Sends to output each Resolvable locked by lock
*/
template<class OutputIterator>
unsigned lockedResolvables( const Lock& lock, OutputIterator output ) const;

/**
* adds locks to pool
*/
template<typename Container>
void addLocksToPool( const Container& container ) const;

/**
* directly sends locks from file to pool. No storing in memory needed.
*/
void readLocksToPool() const;

/**
* saves locked resolvables from pool to lock file
*/
void writeLocksFromPool() const;

/**
* adds single lock to pool
*/
void addLockToPool( const Lock &lock ) const;

/**
* sends to output each lock from container that lock resolvable
* use case - if user want in ui unlock some resolvable, ui call this
* function with all locks from locksfile and it return all lock which
* must be changed
* e.g.
* locks: xf* xfce4* kde*
* resolvable: xfce4-plugin-sensors
* response: xf* xfce4*
*/
template<typename Container, class OutputIterator>
void matchingLocks( const Resolvable& resolvable, Container locks,
OutputIterator output ) const;

private:
RWCOW_pointer<Impl> _pimpl;
}

/**
* for logging purpose
*/
std::ostream & operator<<( std::ostream & str, const Locks & obj );

} //namespace locks
} //namespace zypp
< Previous Next >