mirror of
https://github.com/NixOS/nix.git
synced 2025-11-18 00:12:43 +01:00
Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter, * It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files * Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose, Let's rip the bandaid off? Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
This commit is contained in:
parent
41bf87ec70
commit
e4f62e4608
587 changed files with 23258 additions and 23135 deletions
|
|
@ -11,7 +11,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
||||
AutoCloseFD openLockFile(const Path & path, bool create)
|
||||
|
|
@ -25,7 +24,6 @@ AutoCloseFD openLockFile(const Path & path, bool create)
|
|||
return fd;
|
||||
}
|
||||
|
||||
|
||||
void deleteLockFile(const Path & path, Descriptor desc)
|
||||
{
|
||||
/* Get rid of the lock file. Have to be careful not to introduce
|
||||
|
|
@ -38,14 +36,17 @@ void deleteLockFile(const Path & path, Descriptor desc)
|
|||
file is an optimisation, not a necessity. */
|
||||
}
|
||||
|
||||
|
||||
bool lockFile(Descriptor desc, LockType lockType, bool wait)
|
||||
{
|
||||
int type;
|
||||
if (lockType == ltRead) type = LOCK_SH;
|
||||
else if (lockType == ltWrite) type = LOCK_EX;
|
||||
else if (lockType == ltNone) type = LOCK_UN;
|
||||
else unreachable();
|
||||
if (lockType == ltRead)
|
||||
type = LOCK_SH;
|
||||
else if (lockType == ltWrite)
|
||||
type = LOCK_EX;
|
||||
else if (lockType == ltNone)
|
||||
type = LOCK_UN;
|
||||
else
|
||||
unreachable();
|
||||
|
||||
if (wait) {
|
||||
while (flock(desc, type) != 0) {
|
||||
|
|
@ -58,7 +59,8 @@ bool lockFile(Descriptor desc, LockType lockType, bool wait)
|
|||
} else {
|
||||
while (flock(desc, type | LOCK_NB) != 0) {
|
||||
checkInterrupt();
|
||||
if (errno == EWOULDBLOCK) return false;
|
||||
if (errno == EWOULDBLOCK)
|
||||
return false;
|
||||
if (errno != EINTR)
|
||||
throw SysError("acquiring/releasing lock");
|
||||
}
|
||||
|
|
@ -67,9 +69,7 @@ bool lockFile(Descriptor desc, LockType lockType, bool wait)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PathLocks::lockPaths(const PathSet & paths,
|
||||
const std::string & waitMsg, bool wait)
|
||||
bool PathLocks::lockPaths(const PathSet & paths, const std::string & waitMsg, bool wait)
|
||||
{
|
||||
assert(fds.empty());
|
||||
|
||||
|
|
@ -95,7 +95,8 @@ bool PathLocks::lockPaths(const PathSet & paths,
|
|||
/* Acquire an exclusive lock. */
|
||||
if (!lockFile(fd.get(), ltWrite, false)) {
|
||||
if (wait) {
|
||||
if (waitMsg != "") printError(waitMsg);
|
||||
if (waitMsg != "")
|
||||
printError(waitMsg);
|
||||
lockFile(fd.get(), ltWrite, true);
|
||||
} else {
|
||||
/* Failed to lock this path; release all other
|
||||
|
|
@ -129,16 +130,14 @@ bool PathLocks::lockPaths(const PathSet & paths,
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
void PathLocks::unlock()
|
||||
{
|
||||
for (auto & i : fds) {
|
||||
if (deletePaths) deleteLockFile(i.second, i.first);
|
||||
if (deletePaths)
|
||||
deleteLockFile(i.second, i.first);
|
||||
|
||||
if (close(i.first) == -1)
|
||||
printError(
|
||||
"error (ignored): cannot close lock file on '%1%'",
|
||||
i.second);
|
||||
printError("error (ignored): cannot close lock file on '%1%'", i.second);
|
||||
|
||||
debug("lock released on '%1%'", i.second);
|
||||
}
|
||||
|
|
@ -146,7 +145,6 @@ void PathLocks::unlock()
|
|||
fds.clear();
|
||||
}
|
||||
|
||||
|
||||
FdLock::FdLock(Descriptor desc, LockType lockType, bool wait, std::string_view waitMsg)
|
||||
: desc(desc)
|
||||
{
|
||||
|
|
@ -159,5 +157,4 @@ FdLock::FdLock(Descriptor desc, LockType lockType, bool wait, std::string_view w
|
|||
acquired = lockFile(desc, lockType, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue