mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-12 00:00:44 -04:00
- 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:
parent
1885fb66c4
commit
f30a3f1b16
7 changed files with 185 additions and 98 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue