- moved lock handle functions to rsdir.h/cc

- created a scope guard to manage file lock handles
- added lock gards to PGP keyring read/writes.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5216 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-06-12 20:31:13 +00:00
parent 1885fb66c4
commit f30a3f1b16
7 changed files with 185 additions and 98 deletions

View file

@ -36,6 +36,21 @@ class RsThread;
#include <retroshare/rstypes.h>
// This is a scope guard on a given file. Works like a mutex. Is blocking.
// We could do that in another way: derive RsMutex into RsLockFileMutex, and
// use RsStackMutex on it transparently. Only issue: this will cost little more
// because of the multiple inheritance.
//
class RsStackFileLock
{
public:
RsStackFileLock(const std::string& file_path) ;
~RsStackFileLock() ;
private:
int _file_handle ;
};
namespace RsDirUtil {
std::string getTopDir(const std::string&);
@ -70,6 +85,15 @@ bool getFileHash(const std::string& filepath,std::string &hash, uint64_t &size
Sha1CheckSum sha1sum(uint8_t *data,uint32_t size) ;
// Creates a lock file with given path, and returns the lock handle
// returns:
// 0: Success
// 1: Another instance already has the lock
// 2 : Unexpected error
int createLockFile(const std::string& lock_file_path,int& lock_handle) ;
// Removes the lock file with specified handle.
void releaseLockFile(int lockHandle) ;
std::wstring getWideTopDir(std::wstring);
std::wstring getWideRootDir(std::wstring);