Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
pathlocks.hh
Go to the documentation of this file.
1#pragma once
3
4#include "file-descriptor.hh"
5
6namespace nix {
7
13AutoCloseFD openLockFile(const Path & path, bool create);
14
18void deleteLockFile(const Path & path, Descriptor desc);
19
20enum LockType { ltRead, ltWrite, ltNone };
21
22bool lockFile(Descriptor desc, LockType lockType, bool wait);
23
24class PathLocks
25{
26private:
27 typedef std::pair<Descriptor, Path> FDPair;
28 std::list<FDPair> fds;
29 bool deletePaths;
30
31public:
32 PathLocks();
33 PathLocks(const PathSet & paths,
34 const std::string & waitMsg = "");
35 bool lockPaths(const PathSet & _paths,
36 const std::string & waitMsg = "",
37 bool wait = true);
38 ~PathLocks();
39 void unlock();
40 void setDeletion(bool deletePaths);
41};
42
43struct FdLock
44{
45 Descriptor desc;
46 bool acquired = false;
47
48 FdLock(Descriptor desc, LockType lockType, bool wait, std::string_view waitMsg);
49
50 ~FdLock()
51 {
52 if (acquired)
53 lockFile(desc, ltNone, false);
54 }
55};
56
57}
Definition file-descriptor.hh:152
int Descriptor
Definition file-descriptor.hh:20
Symbol create(std::string_view s)
Definition lexer.l:1018
void deleteLockFile(const Path &path, Descriptor desc)
AutoCloseFD openLockFile(const Path &path, bool create)
std::string Path
Definition types.hh:22