Merge remote-tracking branch 'origin/master' into flakes

This commit is contained in:
Eelco Dolstra 2020-05-06 12:01:40 +02:00
commit 2f8ee4578f
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
8 changed files with 26 additions and 62 deletions

View file

@ -419,7 +419,7 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
try {
auto mapFile = fmt("/proc/%s/maps", ent->d_name);
auto mapLines = tokenizeString<std::vector<string>>(readFile(mapFile, true), "\n");
auto mapLines = tokenizeString<std::vector<string>>(readFile(mapFile), "\n");
for (const auto & line : mapLines) {
auto match = std::smatch{};
if (std::regex_match(line, match, mapRegex))
@ -427,7 +427,7 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
}
auto envFile = fmt("/proc/%s/environ", ent->d_name);
auto envString = readFile(envFile, true);
auto envString = readFile(envFile);
auto env_end = std::sregex_iterator{};
for (auto i = std::sregex_iterator{envString.begin(), envString.end(), storePathRegex}; i != env_end; ++i)
unchecked[i->str()].emplace(envFile);
@ -889,7 +889,7 @@ void LocalStore::autoGC(bool sync)
if (statvfs(realStoreDir.c_str(), &st))
throw SysError("getting filesystem info about '%s'", realStoreDir);
return (uint64_t) st.f_bavail * st.f_bsize;
return (uint64_t) st.f_bavail * st.f_frsize;
};
std::shared_future<void> future;

View file

@ -779,10 +779,8 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source *
return std::make_exception_ptr(Error(status, error));
}
else if (msg == STDERR_NEXT) {
string s = chomp(readString(from));
printMsg(lvlVomit, "stderr %s", s);
}
else if (msg == STDERR_NEXT)
printError(chomp(readString(from)));
else if (msg == STDERR_START_ACTIVITY) {
auto act = readNum<ActivityId>(from);

View file

@ -63,16 +63,6 @@ public:
writeToStderr(prefix + filterANSIEscapes(fs.s, !tty) + "\n");
}
void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override
{
if (type == resBuildLogLine || type == resPostBuildLogLine) {
assert(0 < fields.size());
assert(fields[0].type == Logger::Field::tString);
auto lastLine = fields[0].s;
log(lvlInfo, lastLine);
}
}
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
const std::string & s, const Fields & fields, ActivityId parent)
override

View file

@ -148,6 +148,9 @@ struct StringSink : Sink
{
ref<std::string> s;
StringSink() : s(make_ref<std::string>()) { };
explicit StringSink(const size_t reservedSize) : s(make_ref<std::string>()) {
s->reserve(reservedSize);
};
StringSink(ref<std::string> s) : s(s) { };
void operator () (const unsigned char * data, size_t len) override;
};

View file

@ -317,19 +317,16 @@ string readFile(int fd)
if (fstat(fd, &st) == -1)
throw SysError("statting file");
std::vector<unsigned char> buf(st.st_size);
readFull(fd, buf.data(), st.st_size);
return string((char *) buf.data(), st.st_size);
return drainFD(fd, true, st.st_size);
}
string readFile(const Path & path, bool drain)
string readFile(const Path & path)
{
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (!fd)
throw SysError(format("opening file '%1%'") % path);
return drain ? drainFD(fd.get()) : readFile(fd.get());
return readFile(fd.get());
}
@ -676,9 +673,9 @@ void writeFull(int fd, const string & s, bool allowInterrupts)
}
string drainFD(int fd, bool block)
string drainFD(int fd, bool block, const size_t reserveSize)
{
StringSink sink;
StringSink sink(reserveSize);
drainFD(fd, sink, block);
return std::move(*sink.s);
}

View file

@ -105,7 +105,7 @@ unsigned char getFileType(const Path & path);
/* Read the contents of a file into a string. */
string readFile(int fd);
string readFile(const Path & path, bool drain = false);
string readFile(const Path & path);
void readFile(const Path & path, Sink & sink);
/* Write a string to a file. */
@ -166,7 +166,7 @@ MakeError(EndOfFile, Error);
/* Read a file descriptor until EOF occurs. */
string drainFD(int fd, bool block = true);
string drainFD(int fd, bool block = true, const size_t reserveSize=0);
void drainFD(int fd, Sink & sink, bool block = true);

View file

@ -140,7 +140,7 @@ struct CmdLsNar : Command, MixLs
void run() override
{
list(makeNarAccessor(make_ref<std::string>(readFile(narPath, true))));
list(makeNarAccessor(make_ref<std::string>(readFile(narPath))));
}
};

View file

@ -82,40 +82,6 @@ struct NixRepl : gc
};
void printHelp()
{
std::cout
<< "Usage: nix-repl [--help] [--version] [-I path] paths...\n"
<< "\n"
<< "nix-repl is a simple read-eval-print loop (REPL) for the Nix package manager.\n"
<< "\n"
<< "Options:\n"
<< " --help\n"
<< " Prints out a summary of the command syntax and exits.\n"
<< "\n"
<< " --version\n"
<< " Prints out the Nix version number on standard output and exits.\n"
<< "\n"
<< " -I path\n"
<< " Add a path to the Nix expression search path. This option may be given\n"
<< " multiple times. See the NIX_PATH environment variable for information on\n"
<< " the semantics of the Nix search path. Paths added through -I take\n"
<< " precedence over NIX_PATH.\n"
<< "\n"
<< " paths...\n"
<< " A list of paths to files containing Nix expressions which nix-repl will\n"
<< " load and add to its scope.\n"
<< "\n"
<< " A path surrounded in < and > will be looked up in the Nix expression search\n"
<< " path, as in the Nix language itself.\n"
<< "\n"
<< " If an element of paths starts with http:// or https://, it is interpreted\n"
<< " as the URL of a tarball that will be downloaded and unpacked to a temporary\n"
<< " location. The tarball must include a single top-level directory containing\n"
<< " at least a file named default.nix.\n";
}
string removeWhitespace(string s)
{
s = chomp(s);
@ -809,6 +775,16 @@ struct CmdRepl : StoreCommand, MixEvalArgs
return "start an interactive environment for evaluating Nix expressions";
}
Examples examples() override
{
return {
Example{
"Display all special commands within the REPL:",
"nix repl\n nix-repl> :?"
}
};
}
void run(ref<Store> store) override
{
evalSettings.pureEval = false;