Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / nix / libstore / pathlocks.hh
CommitLineData
36457566
LC
1#pragma once
2
3#include "types.hh"
4
5
6namespace nix {
7
8
9/* Open (possibly create) a lock file and return the file descriptor.
10 -1 is returned if create is false and the lock could not be opened
11 because it doesn't exist. Any other error throws an exception. */
12int openLockFile(const Path & path, bool create);
13
14/* Delete an open lock file. */
15void deleteLockFile(const Path & path, int fd);
16
17enum LockType { ltRead, ltWrite, ltNone };
18
19bool lockFile(int fd, LockType lockType, bool wait);
20
21
22class PathLocks
23{
24private:
25 typedef std::pair<int, Path> FDPair;
26 list<FDPair> fds;
27 bool deletePaths;
28
29public:
30 PathLocks();
31 PathLocks(const PathSet & paths,
32 const string & waitMsg = "");
33 bool lockPaths(const PathSet & _paths,
34 const string & waitMsg = "",
35 bool wait = true);
36 ~PathLocks();
37 void unlock();
38 void setDeletion(bool deletePaths);
39};
40
41
42bool pathIsLockedByMe(const Path & path);
43
44
45}