Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
pathlocks.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include <filesystem>
5
6
#include "
nix/util/file-descriptor.hh
"
7
8
namespace
nix {
9
15
AutoCloseFD
openLockFile
(
const
std::filesystem::path & path,
bool
create);
16
20
void
deleteLockFile
(
const
std::filesystem::path & path,
Descriptor
desc);
21
22
enum
LockType { ltRead, ltWrite, ltNone };
23
24
bool
lockFile(
Descriptor
desc, LockType lockType,
bool
wait);
25
26
class
PathLocks
27
{
28
private
:
29
typedef
std::pair<Descriptor, std::filesystem::path> FDPair;
30
std::list<FDPair> fds;
31
bool
deletePaths;
32
33
public
:
34
PathLocks();
35
PathLocks(
const
std::set<std::filesystem::path> & paths,
const
std::string & waitMsg =
""
);
36
37
PathLocks(PathLocks && other) noexcept
38
: fds(std::exchange(other.fds, {}))
39
, deletePaths(other.deletePaths)
40
{
41
}
42
43
PathLocks & operator=(PathLocks && other)
noexcept
44
{
45
fds = std::exchange(other.fds, {});
46
deletePaths = other.deletePaths;
47
return
*
this
;
48
}
49
50
PathLocks(
const
PathLocks &) =
delete
;
51
PathLocks & operator=(
const
PathLocks &) =
delete
;
52
bool
lockPaths(
const
std::set<std::filesystem::path> & _paths,
const
std::string & waitMsg =
""
,
bool
wait =
true
);
53
~PathLocks();
54
void
unlock();
55
void
setDeletion(
bool
deletePaths);
56
};
57
58
struct
FdLock
59
{
60
Descriptor
desc;
61
bool
acquired =
false
;
62
63
FdLock(
Descriptor
desc, LockType lockType,
bool
wait, std::string_view waitMsg);
64
FdLock(
const
FdLock &) =
delete
;
65
FdLock & operator=(
const
FdLock &) =
delete
;
66
FdLock(FdLock &&) =
delete
;
67
FdLock & operator=(FdLock &&) =
delete
;
68
69
~FdLock()
70
{
71
if
(acquired)
72
lockFile(desc, ltNone,
false
);
73
}
74
};
75
76
}
// namespace nix
nix::AutoCloseFD
Definition
file-descriptor.hh:265
file-descriptor.hh
File descriptor operations for almost arbitrary file descriptors.
nix::Descriptor
int Descriptor
Definition
file-descriptor.hh:36
nix::openLockFile
AutoCloseFD openLockFile(const std::filesystem::path &path, bool create)
Definition
pathlocks.cc:16
nix::deleteLockFile
void deleteLockFile(const std::filesystem::path &path, Descriptor desc)
Definition
pathlocks.cc:27
libstore
include
nix
store
pathlocks.hh
Generated by
1.18.0