gnu: Add gnome-shell-extension-dash-to-dock.
[jackhill/guix/guix.git] / nix / libstore / pathlocks.hh
1 #pragma once
2
3 #include "types.hh"
4
5
6 namespace 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. */
12 int openLockFile(const Path & path, bool create);
13
14 /* Delete an open lock file. */
15 void deleteLockFile(const Path & path, int fd);
16
17 enum LockType { ltRead, ltWrite, ltNone };
18
19 bool lockFile(int fd, LockType lockType, bool wait);
20
21
22 class PathLocks
23 {
24 private:
25 typedef std::pair<int, Path> FDPair;
26 list<FDPair> fds;
27 bool deletePaths;
28
29 public:
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
42 bool pathIsLockedByMe(const Path & path);
43
44
45 }