2012-07-18 14:59:03 -04:00
|
|
|
#pragma once
|
2003-08-01 10:11:19 -04:00
|
|
|
|
2017-01-25 06:51:35 -05:00
|
|
|
#include "util.hh"
|
2006-09-04 17:06:23 -04:00
|
|
|
|
|
|
|
namespace nix {
|
2003-08-01 10:11:19 -04:00
|
|
|
|
2006-06-20 13:48:10 -04:00
|
|
|
/* Open (possibly create) a lock file and return the file descriptor.
|
|
|
|
-1 is returned if create is false and the lock could not be opened
|
|
|
|
because it doesn't exist. Any other error throws an exception. */
|
2017-01-25 06:51:35 -05:00
|
|
|
AutoCloseFD openLockFile(const Path & path, bool create);
|
2006-06-20 13:48:10 -04:00
|
|
|
|
2010-02-02 10:28:36 -05:00
|
|
|
/* Delete an open lock file. */
|
|
|
|
void deleteLockFile(const Path & path, int fd);
|
2006-06-20 13:48:10 -04:00
|
|
|
|
2008-05-21 07:17:31 -04:00
|
|
|
enum LockType { ltRead, ltWrite, ltNone };
|
2003-10-14 11:33:00 -04:00
|
|
|
|
2010-02-03 16:38:41 -05:00
|
|
|
bool lockFile(int fd, LockType lockType, bool wait);
|
2003-10-14 11:33:00 -04:00
|
|
|
|
2017-01-25 06:51:35 -05:00
|
|
|
class PathLocks
|
2003-08-01 10:11:19 -04:00
|
|
|
{
|
|
|
|
private:
|
2006-09-04 17:06:23 -04:00
|
|
|
typedef std::pair<int, Path> FDPair;
|
2005-01-27 07:19:25 -05:00
|
|
|
list<FDPair> fds;
|
2003-11-21 11:05:19 -05:00
|
|
|
bool deletePaths;
|
2003-08-01 10:11:19 -04:00
|
|
|
|
|
|
|
public:
|
2004-05-11 14:05:44 -04:00
|
|
|
PathLocks();
|
2006-06-15 07:56:49 -04:00
|
|
|
PathLocks(const PathSet & paths,
|
|
|
|
const string & waitMsg = "");
|
2009-03-22 21:05:54 -04:00
|
|
|
bool lockPaths(const PathSet & _paths,
|
|
|
|
const string & waitMsg = "",
|
|
|
|
bool wait = true);
|
2003-08-01 10:11:19 -04:00
|
|
|
~PathLocks();
|
2009-02-16 04:24:20 -05:00
|
|
|
void unlock();
|
2003-11-21 11:05:19 -05:00
|
|
|
void setDeletion(bool deletePaths);
|
2003-08-01 10:11:19 -04:00
|
|
|
};
|
|
|
|
|
2006-09-04 17:06:23 -04:00
|
|
|
}
|