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
|
|
@ -5,47 +5,38 @@
|
|||
#include "nix/util/fs-sink.hh"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <fileapi.h>
|
||||
# include "nix/util/file-path.hh"
|
||||
# include "nix/util/windows-error.hh"
|
||||
# include <fileapi.h>
|
||||
# include "nix/util/file-path.hh"
|
||||
# include "nix/util/windows-error.hh"
|
||||
#endif
|
||||
|
||||
#include "util-config-private.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
void copyRecursive(
|
||||
SourceAccessor & accessor, const CanonPath & from,
|
||||
FileSystemObjectSink & sink, const CanonPath & to)
|
||||
void copyRecursive(SourceAccessor & accessor, const CanonPath & from, FileSystemObjectSink & sink, const CanonPath & to)
|
||||
{
|
||||
auto stat = accessor.lstat(from);
|
||||
|
||||
switch (stat.type) {
|
||||
case SourceAccessor::tSymlink:
|
||||
{
|
||||
case SourceAccessor::tSymlink: {
|
||||
sink.createSymlink(to, accessor.readLink(from));
|
||||
break;
|
||||
}
|
||||
|
||||
case SourceAccessor::tRegular:
|
||||
{
|
||||
case SourceAccessor::tRegular: {
|
||||
sink.createRegularFile(to, [&](CreateRegularFileSink & crf) {
|
||||
if (stat.isExecutable)
|
||||
crf.isExecutable();
|
||||
accessor.readFile(from, crf, [&](uint64_t size) {
|
||||
crf.preallocateContents(size);
|
||||
});
|
||||
accessor.readFile(from, crf, [&](uint64_t size) { crf.preallocateContents(size); });
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case SourceAccessor::tDirectory:
|
||||
{
|
||||
case SourceAccessor::tDirectory: {
|
||||
sink.createDirectory(to);
|
||||
for (auto & [name, _] : accessor.readDirectory(from)) {
|
||||
copyRecursive(
|
||||
accessor, from / name,
|
||||
sink, to / name);
|
||||
copyRecursive(accessor, from / name, sink, to / name);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
@ -61,11 +52,10 @@ void copyRecursive(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
struct RestoreSinkSettings : Config
|
||||
{
|
||||
Setting<bool> preallocateContents{this, false, "preallocate-contents",
|
||||
"Whether to preallocate files when writing objects with known size."};
|
||||
Setting<bool> preallocateContents{
|
||||
this, false, "preallocate-contents", "Whether to preallocate files when writing objects with known size."};
|
||||
};
|
||||
|
||||
static RestoreSinkSettings restoreSinkSettings;
|
||||
|
|
@ -87,7 +77,8 @@ void RestoreSink::createDirectory(const CanonPath & path)
|
|||
throw Error("path '%s' already exists", p.string());
|
||||
};
|
||||
|
||||
struct RestoreRegularFile : CreateRegularFileSink {
|
||||
struct RestoreRegularFile : CreateRegularFileSink
|
||||
{
|
||||
AutoCloseFD fd;
|
||||
bool startFsync = false;
|
||||
|
||||
|
|
@ -101,7 +92,7 @@ struct RestoreRegularFile : CreateRegularFileSink {
|
|||
fd.startFsync();
|
||||
}
|
||||
|
||||
void operator () (std::string_view data) override;
|
||||
void operator()(std::string_view data) override;
|
||||
void isExecutable() override;
|
||||
void preallocateContents(uint64_t size) override;
|
||||
};
|
||||
|
|
@ -114,12 +105,20 @@ void RestoreSink::createRegularFile(const CanonPath & path, std::function<void(C
|
|||
crf.startFsync = startFsync;
|
||||
crf.fd =
|
||||
#ifdef _WIN32
|
||||
CreateFileW(p.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL)
|
||||
CreateFileW(
|
||||
p.c_str(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL,
|
||||
CREATE_NEW,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
NULL)
|
||||
#else
|
||||
open(p.c_str(), O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0666)
|
||||
#endif
|
||||
;
|
||||
if (!crf.fd) throw NativeSysError("creating file '%1%'", p);
|
||||
if (!crf.fd)
|
||||
throw NativeSysError("creating file '%1%'", p);
|
||||
func(crf);
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +153,7 @@ void RestoreRegularFile::preallocateContents(uint64_t len)
|
|||
#endif
|
||||
}
|
||||
|
||||
void RestoreRegularFile::operator () (std::string_view data)
|
||||
void RestoreRegularFile::operator()(std::string_view data)
|
||||
{
|
||||
writeFull(fd.get(), data);
|
||||
}
|
||||
|
|
@ -165,32 +164,42 @@ void RestoreSink::createSymlink(const CanonPath & path, const std::string & targ
|
|||
nix::createSymlink(target, p.string());
|
||||
}
|
||||
|
||||
|
||||
void RegularFileSink::createRegularFile(const CanonPath & path, std::function<void(CreateRegularFileSink &)> func)
|
||||
{
|
||||
struct CRF : CreateRegularFileSink {
|
||||
struct CRF : CreateRegularFileSink
|
||||
{
|
||||
RegularFileSink & back;
|
||||
CRF(RegularFileSink & back) : back(back) {}
|
||||
void operator () (std::string_view data) override
|
||||
|
||||
CRF(RegularFileSink & back)
|
||||
: back(back)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(std::string_view data) override
|
||||
{
|
||||
back.sink(data);
|
||||
}
|
||||
|
||||
void isExecutable() override {}
|
||||
} crf { *this };
|
||||
} crf{*this};
|
||||
|
||||
func(crf);
|
||||
}
|
||||
|
||||
|
||||
void NullFileSystemObjectSink::createRegularFile(const CanonPath & path, std::function<void(CreateRegularFileSink &)> func)
|
||||
void NullFileSystemObjectSink::createRegularFile(
|
||||
const CanonPath & path, std::function<void(CreateRegularFileSink &)> func)
|
||||
{
|
||||
struct : CreateRegularFileSink {
|
||||
void operator () (std::string_view data) override {}
|
||||
struct : CreateRegularFileSink
|
||||
{
|
||||
void operator()(std::string_view data) override {}
|
||||
|
||||
void isExecutable() override {}
|
||||
} crf;
|
||||
|
||||
// Even though `NullFileSystemObjectSink` doesn't do anything, it's important
|
||||
// that we call the function, to e.g. advance the parser using this
|
||||
// sink.
|
||||
func(crf);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue