aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build.cc7
-rw-r--r--src/libstore/derivations.cc17
-rw-r--r--src/libutil/fmt.hh17
-rw-r--r--src/libutil/hash.cc27
-rw-r--r--src/libutil/hash.hh2
-rw-r--r--src/libutil/tests/logging.cc99
6 files changed, 115 insertions, 54 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 0c25897f8..9ac5fd923 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1950,8 +1950,11 @@ void linkOrCopy(const Path & from, const Path & to)
/* Hard-linking fails if we exceed the maximum link count on a
file (e.g. 32000 of ext3), which is quite possible after a
'nix-store --optimise'. FIXME: actually, why don't we just
- bind-mount in this case? */
- if (errno != EMLINK)
+ bind-mount in this case?
+
+ It can also fail with EPERM in BeegFS v7 and earlier versions
+ which don't allow hard-links to other directories */
+ if (errno != EMLINK && errno != EPERM)
throw SysError("linking '%s' to '%s'", to, from);
copyPath(from, to);
}
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index 6c49075ba..42551ef6b 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -404,7 +404,7 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store)
{
auto path = store.parseStorePath(readString(in));
auto hashAlgo = readString(in);
- const auto hash = readString(in);
+ auto hash = readString(in);
std::optional<FixedOutputHash> fsh;
if (hashAlgo != "") {
@@ -413,7 +413,7 @@ static DerivationOutput readDerivationOutput(Source & in, const Store & store)
method = FileIngestionMethod::Recursive;
hashAlgo = string(hashAlgo, 2);
}
- const HashType hashType = parseHashType(hashAlgo);
+ auto hashType = parseHashType(hashAlgo);
fsh = FixedOutputHash {
.method = std::move(method),
.hash = Hash(hash, hashType),
@@ -463,11 +463,16 @@ Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv)
void writeDerivation(Sink & out, const Store & store, const BasicDerivation & drv)
{
out << drv.outputs.size();
- for (auto & i : drv.outputs)
+ for (auto & i : drv.outputs) {
out << i.first
- << store.printStorePath(i.second.path)
- << i.second.hash->printMethodAlgo()
- << i.second.hash->hash.to_string(Base16, false);
+ << store.printStorePath(i.second.path);
+ if (i.second.hash) {
+ out << i.second.hash->printMethodAlgo()
+ << i.second.hash->hash.to_string(Base16, false);
+ } else {
+ out << "" << "";
+ }
+ }
writeStorePaths(store, out, drv.inputSrcs);
out << drv.platform << drv.builder << drv.args;
out << drv.env.size();
diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh
index 12ab9c407..a39de041f 100644
--- a/src/libutil/fmt.hh
+++ b/src/libutil/fmt.hh
@@ -1,6 +1,7 @@
#pragma once
#include <boost/format.hpp>
+#include <boost/algorithm/string/replace.hpp>
#include <string>
#include "ansicolor.hh"
@@ -103,7 +104,9 @@ class hintformat
public:
hintformat(const string &format) :fmt(format)
{
- fmt.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
+ fmt.exceptions(boost::io::all_error_bits ^
+ boost::io::too_many_args_bit ^
+ boost::io::too_few_args_bit);
}
hintformat(const hintformat &hf)
@@ -117,6 +120,13 @@ public:
return *this;
}
+ template<class T>
+ hintformat& operator%(const normaltxt<T> &value)
+ {
+ fmt % value.value;
+ return *this;
+ }
+
std::string str() const
{
return fmt.str();
@@ -136,4 +146,9 @@ inline hintformat hintfmt(const std::string & fs, const Args & ... args)
return f;
}
+inline hintformat hintfmt(std::string plain_string)
+{
+ // we won't be receiving any args in this case, so just print the original string
+ return hintfmt("%s", normaltxt(plain_string));
+}
}
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index c8fcdfed0..01fae3044 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -19,7 +19,7 @@ namespace nix {
void Hash::init()
{
- if (!type) abort();
+ assert(type);
switch (*type) {
case htMD5: hashSize = md5HashSize; break;
case htSHA1: hashSize = sha1HashSize; break;
@@ -101,15 +101,15 @@ static string printHash32(const Hash & hash)
string printHash16or32(const Hash & hash)
{
+ assert(hash.type);
return hash.to_string(hash.type == htMD5 ? Base16 : Base32, false);
}
-HashType assertInitHashType(const Hash & h) {
- if (h.type)
- return *h.type;
- else
- abort();
+HashType assertInitHashType(const Hash & h)
+{
+ assert(h.type);
+ return *h.type;
}
std::string Hash::to_string(Base base, bool includeType) const
@@ -363,14 +363,15 @@ HashType parseHashType(const string & s)
string printHashType(HashType ht)
{
switch (ht) {
- case htMD5: return "md5"; break;
- case htSHA1: return "sha1"; break;
- case htSHA256: return "sha256"; break;
- case htSHA512: return "sha512"; break;
+ case htMD5: return "md5";
+ case htSHA1: return "sha1";
+ case htSHA256: return "sha256";
+ case htSHA512: return "sha512";
+ default:
+ // illegal hash type enum value internally, as opposed to external input
+ // which should be validated with nice error message.
+ abort();
}
- // illegal hash type enum value internally, as opposed to external input
- // which should be validated with nice error message.
- abort();
}
}
diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh
index 0d9916508..23259dced 100644
--- a/src/libutil/hash.hh
+++ b/src/libutil/hash.hh
@@ -10,7 +10,7 @@ namespace nix {
MakeError(BadHash, Error);
-enum HashType : char { htMD5, htSHA1, htSHA256, htSHA512 };
+enum HashType : char { htMD5 = 42, htSHA1, htSHA256, htSHA512 };
const int md5HashSize = 16;
diff --git a/src/libutil/tests/logging.cc b/src/libutil/tests/logging.cc
index 4cb54995b..6a6fb4ac3 100644
--- a/src/libutil/tests/logging.cc
+++ b/src/libutil/tests/logging.cc
@@ -1,6 +1,7 @@
#include "logging.hh"
#include "nixexpr.hh"
#include "util.hh"
+#include <fstream>
#include <gtest/gtest.h>
@@ -42,7 +43,7 @@ namespace nix {
logger->logEI(ei);
auto str = testing::internal::GetCapturedStderr();
- ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- TestError --- error-unit-test\x1B[0m\n\x1B[33;1m\x1B[0minitial error\x1B[0m; subsequent error message.\n");
+ ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- TestError --- error-unit-test\x1B[0m\ninitial error; subsequent error message.\n");
}
}
@@ -60,8 +61,7 @@ namespace nix {
logError(e.info());
auto str = testing::internal::GetCapturedStderr();
- ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- SysError --- error-unit-test\x1B[0m\n\x1B[33;1m\x1B[0mstatting file\x1B[0m: \x1B[33;1mBad file descriptor\x1B[0m\n");
-
+ ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- SysError --- error-unit-test\x1B[0m\nstatting file: \x1B[33;1mBad file descriptor\x1B[0m\n");
}
}
@@ -69,9 +69,9 @@ namespace nix {
testing::internal::CaptureStderr();
logger->logEI({ .level = lvlInfo,
- .name = "Info name",
- .description = "Info description",
- });
+ .name = "Info name",
+ .description = "Info description",
+ });
auto str = testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(), "\x1B[32;1minfo:\x1B[0m\x1B[34;1m --- Info name --- error-unit-test\x1B[0m\nInfo description\n");
@@ -85,7 +85,7 @@ namespace nix {
logger->logEI({ .level = lvlTalkative,
.name = "Talkative name",
.description = "Talkative description",
- });
+ });
auto str = testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(), "\x1B[32;1mtalk:\x1B[0m\x1B[34;1m --- Talkative name --- error-unit-test\x1B[0m\nTalkative description\n");
@@ -99,7 +99,7 @@ namespace nix {
logger->logEI({ .level = lvlChatty,
.name = "Chatty name",
.description = "Talkative description",
- });
+ });
auto str = testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(), "\x1B[32;1mchat:\x1B[0m\x1B[34;1m --- Chatty name --- error-unit-test\x1B[0m\nTalkative description\n");
@@ -113,7 +113,7 @@ namespace nix {
logger->logEI({ .level = lvlDebug,
.name = "Debug name",
.description = "Debug description",
- });
+ });
auto str = testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(), "\x1B[33;1mdebug:\x1B[0m\x1B[34;1m --- Debug name --- error-unit-test\x1B[0m\nDebug description\n");
@@ -127,7 +127,7 @@ namespace nix {
logger->logEI({ .level = lvlVomit,
.name = "Vomit name",
.description = "Vomit description",
- });
+ });
auto str = testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(), "\x1B[32;1mvomit:\x1B[0m\x1B[34;1m --- Vomit name --- error-unit-test\x1B[0m\nVomit description\n");
@@ -144,7 +144,7 @@ namespace nix {
logError({
.name = "name",
.description = "error description",
- });
+ });
auto str = testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(), "\x1B[31;1merror:\x1B[0m\x1B[34;1m --- name --- error-unit-test\x1B[0m\nerror description\n");
@@ -160,13 +160,13 @@ namespace nix {
.name = "error name",
.description = "error with code lines",
.hint = hintfmt("this hint has %1% templated %2%!!",
- "yellow",
- "values"),
+ "yellow",
+ "values"),
.nixCode = NixCode {
- .errPos = Pos(problem_file, 40, 13),
- .prevLineOfCode = "previous line of code",
- .errLineOfCode = "this is the problem line of code",
- .nextLineOfCode = "next line of code",
+ .errPos = Pos(problem_file, 40, 13),
+ .prevLineOfCode = "previous line of code",
+ .errLineOfCode = "this is the problem line of code",
+ .nextLineOfCode = "next line of code",
}});
@@ -183,10 +183,10 @@ namespace nix {
.name = "error name",
.description = "error without any code lines.",
.hint = hintfmt("this hint has %1% templated %2%!!",
- "yellow",
- "values"),
+ "yellow",
+ "values"),
.nixCode = NixCode {
- .errPos = Pos(problem_file, 40, 13)
+ .errPos = Pos(problem_file, 40, 13)
}});
auto str = testing::internal::GetCapturedStderr();
@@ -202,7 +202,7 @@ namespace nix {
.name = "error name",
.hint = hintfmt("hint %1%", "only"),
.nixCode = NixCode {
- .errPos = Pos(problem_file, 40, 13)
+ .errPos = Pos(problem_file, 40, 13)
}});
auto str = testing::internal::GetCapturedStderr();
@@ -218,10 +218,10 @@ namespace nix {
testing::internal::CaptureStderr();
logWarning({
- .name = "name",
- .description = "error description",
- .hint = hintfmt("there was a %1%", "warning"),
- });
+ .name = "name",
+ .description = "error description",
+ .hint = hintfmt("there was a %1%", "warning"),
+ });
auto str = testing::internal::GetCapturedStderr();
ASSERT_STREQ(str.c_str(), "\x1B[33;1mwarning:\x1B[0m\x1B[34;1m --- name --- error-unit-test\x1B[0m\nerror description\n\nthere was a \x1B[33;1mwarning\x1B[0m\n");
@@ -238,13 +238,13 @@ namespace nix {
.name = "warning name",
.description = "warning description",
.hint = hintfmt("this hint has %1% templated %2%!!",
- "yellow",
- "values"),
+ "yellow",
+ "values"),
.nixCode = NixCode {
- .errPos = Pos(problem_file, 40, 13),
- .prevLineOfCode = std::nullopt,
- .errLineOfCode = "this is the problem line of code",
- .nextLineOfCode = std::nullopt
+ .errPos = Pos(problem_file, 40, 13),
+ .prevLineOfCode = std::nullopt,
+ .errLineOfCode = "this is the problem line of code",
+ .nextLineOfCode = std::nullopt
}});
@@ -252,4 +252,41 @@ namespace nix {
ASSERT_STREQ(str.c_str(), "\x1B[33;1mwarning:\x1B[0m\x1B[34;1m --- warning name --- error-unit-test\x1B[0m\nin file: \x1B[34;1mmyfile.nix (40:13)\x1B[0m\n\nwarning description\n\n 40| this is the problem line of code\n | \x1B[31;1m^\x1B[0m\n\nthis hint has \x1B[33;1myellow\x1B[0m templated \x1B[33;1mvalues\x1B[0m!!\n");
}
+ /* ----------------------------------------------------------------------------
+ * hintfmt
+ * --------------------------------------------------------------------------*/
+
+ TEST(hintfmt, percentStringWithoutArgs) {
+
+ const char *teststr = "this is 100%s correct!";
+
+ ASSERT_STREQ(
+ hintfmt(teststr).str().c_str(),
+ teststr);
+
+ }
+
+ TEST(hintfmt, fmtToHintfmt) {
+
+ ASSERT_STREQ(
+ hintfmt(fmt("the color of this this text is %1%", "not yellow")).str().c_str(),
+ "the color of this this text is not yellow");
+
+ }
+
+ TEST(hintfmt, tooFewArguments) {
+
+ ASSERT_STREQ(
+ hintfmt("only one arg %1% %2%", "fulfilled").str().c_str(),
+ "only one arg " ANSI_YELLOW "fulfilled" ANSI_NORMAL " ");
+
+ }
+
+ TEST(hintfmt, tooManyArguments) {
+
+ ASSERT_STREQ(
+ hintfmt("what about this %1% %2%", "%3%", "one", "two").str().c_str(),
+ "what about this " ANSI_YELLOW "%3%" ANSI_NORMAL " " ANSI_YELLOW "one" ANSI_NORMAL);
+
+ }
}