mirror of
https://github.com/NixOS/nix.git
synced 2025-11-16 23:42: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
|
|
@ -8,14 +8,13 @@
|
|||
#include "store-config-private.hh"
|
||||
|
||||
#if NIX_SUPPORT_ACL
|
||||
# include <sys/xattr.h>
|
||||
# include <sys/xattr.h>
|
||||
#endif
|
||||
|
||||
namespace nix {
|
||||
|
||||
const time_t mtimeStore = 1; /* 1 second into the epoch */
|
||||
|
||||
|
||||
static void canonicaliseTimestampAndPermissions(const Path & path, const struct stat & st)
|
||||
{
|
||||
if (!S_ISLNK(st.st_mode)) {
|
||||
|
|
@ -24,31 +23,25 @@ static void canonicaliseTimestampAndPermissions(const Path & path, const struct
|
|||
mode_t mode = st.st_mode & ~S_IFMT;
|
||||
|
||||
if (mode != 0444 && mode != 0555) {
|
||||
mode = (st.st_mode & S_IFMT)
|
||||
| 0444
|
||||
| (st.st_mode & S_IXUSR ? 0111 : 0);
|
||||
mode = (st.st_mode & S_IFMT) | 0444 | (st.st_mode & S_IXUSR ? 0111 : 0);
|
||||
if (chmod(path.c_str(), mode) == -1)
|
||||
throw SysError("changing mode of '%1%' to %2$o", path, mode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifndef _WIN32 // TODO implement
|
||||
if (st.st_mtime != mtimeStore) {
|
||||
struct stat st2 = st;
|
||||
st2.st_mtime = mtimeStore,
|
||||
setWriteTime(path, st2);
|
||||
st2.st_mtime = mtimeStore, setWriteTime(path, st2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void canonicaliseTimestampAndPermissions(const Path & path)
|
||||
{
|
||||
canonicaliseTimestampAndPermissions(path, lstat(path));
|
||||
}
|
||||
|
||||
|
||||
static void canonicalisePathMetaData_(
|
||||
const Path & path,
|
||||
#ifndef _WIN32
|
||||
|
|
@ -87,12 +80,13 @@ static void canonicalisePathMetaData_(
|
|||
if ((eaSize = llistxattr(path.c_str(), eaBuf.data(), eaBuf.size())) < 0)
|
||||
throw SysError("querying extended attributes of '%s'", path);
|
||||
|
||||
for (auto & eaName: tokenizeString<Strings>(std::string(eaBuf.data(), eaSize), std::string("\000", 1))) {
|
||||
if (settings.ignoredAcls.get().count(eaName)) continue;
|
||||
for (auto & eaName : tokenizeString<Strings>(std::string(eaBuf.data(), eaSize), std::string("\000", 1))) {
|
||||
if (settings.ignoredAcls.get().count(eaName))
|
||||
continue;
|
||||
if (lremovexattr(path.c_str(), eaName.c_str()) == -1)
|
||||
throw SysError("removing extended attribute '%s' from '%s'", eaName, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
|
|
@ -106,7 +100,9 @@ static void canonicalisePathMetaData_(
|
|||
if (S_ISDIR(st.st_mode) || !inodesSeen.count(Inode(st.st_dev, st.st_ino)))
|
||||
throw BuildError("invalid ownership on file '%1%'", path);
|
||||
mode_t mode = st.st_mode & ~S_IFMT;
|
||||
assert(S_ISLNK(st.st_mode) || (st.st_uid == geteuid() && (mode == 0444 || mode == 0555) && st.st_mtime == mtimeStore));
|
||||
assert(
|
||||
S_ISLNK(st.st_mode)
|
||||
|| (st.st_uid == geteuid() && (mode == 0444 || mode == 0555) && st.st_mtime == mtimeStore));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -124,14 +120,12 @@ static void canonicalisePathMetaData_(
|
|||
store (since that directory is group-writable for the Nix build
|
||||
users group); we check for this case below. */
|
||||
if (st.st_uid != geteuid()) {
|
||||
#if HAVE_LCHOWN
|
||||
# if HAVE_LCHOWN
|
||||
if (lchown(path.c_str(), geteuid(), getegid()) == -1)
|
||||
#else
|
||||
if (!S_ISLNK(st.st_mode) &&
|
||||
chown(path.c_str(), geteuid(), getegid()) == -1)
|
||||
#endif
|
||||
throw SysError("changing owner of '%1%' to %2%",
|
||||
path, geteuid());
|
||||
# else
|
||||
if (!S_ISLNK(st.st_mode) && chown(path.c_str(), geteuid(), getegid()) == -1)
|
||||
# endif
|
||||
throw SysError("changing owner of '%1%' to %2%", path, geteuid());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -148,7 +142,6 @@ static void canonicalisePathMetaData_(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void canonicalisePathMetaData(
|
||||
const Path & path,
|
||||
#ifndef _WIN32
|
||||
|
|
@ -175,12 +168,13 @@ void canonicalisePathMetaData(
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
void canonicalisePathMetaData(const Path & path
|
||||
void canonicalisePathMetaData(
|
||||
const Path & path
|
||||
#ifndef _WIN32
|
||||
, std::optional<std::pair<uid_t, uid_t>> uidRange
|
||||
,
|
||||
std::optional<std::pair<uid_t, uid_t>> uidRange
|
||||
#endif
|
||||
)
|
||||
)
|
||||
{
|
||||
InodesSeen inodesSeen;
|
||||
canonicalisePathMetaData_(
|
||||
|
|
@ -191,4 +185,4 @@ void canonicalisePathMetaData(const Path & path
|
|||
inodesSeen);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue