diff options
Diffstat (limited to 'third_party/nix')
85 files changed, 862 insertions, 824 deletions
diff --git a/third_party/nix/src/build-remote/build-remote.cc b/third_party/nix/src/build-remote/build-remote.cc index 9403d3c35e99..351c660db1e9 100644 --- a/third_party/nix/src/build-remote/build-remote.cc +++ b/third_party/nix/src/build-remote/build-remote.cc @@ -30,7 +30,7 @@ std::string escapeUri(std::string uri) { return uri; } -static string currentLoad; +static std::string currentLoad; static AutoCloseFD openSlotLock(const Machine& m, unsigned long long slot) { return openLockFile(fmt("%s/%s-%d", currentLoad, escapeUri(m.storeUri), slot), @@ -86,8 +86,8 @@ static int _main(int argc, char* argv[]) { return 0; } - string drvPath; - string storeUri; + std::string drvPath; + std::string storeUri; while (true) { try { diff --git a/third_party/nix/src/cpptoml/cpptoml.h b/third_party/nix/src/cpptoml/cpptoml.h index 5a00da3b4cda..150b53ff863c 100644 --- a/third_party/nix/src/cpptoml/cpptoml.h +++ b/third_party/nix/src/cpptoml/cpptoml.h @@ -852,7 +852,7 @@ class array : public base } /** - * Obtains a option<vector<T>>. The option will be empty if the array + * Obtains a option<std::vector<T>>. The option will be empty if the array * contains values that are not of type T. */ template <class T> @@ -1041,7 +1041,7 @@ inline std::shared_ptr<array> make_element<array>() } // namespace detail /** - * Obtains a option<vector<T>>. The option will be empty if the array + * Obtains a option<std::vector<T>>. The option will be empty if the array * contains values that are not of type T. */ template <> diff --git a/third_party/nix/src/libexpr/attr-path.cc b/third_party/nix/src/libexpr/attr-path.cc index 1815b5e510d3..628b58c1b1e3 100644 --- a/third_party/nix/src/libexpr/attr-path.cc +++ b/third_party/nix/src/libexpr/attr-path.cc @@ -8,7 +8,7 @@ namespace nix { static Strings parseAttrPath(const std::string& s) { Strings res; std::string cur; - string::const_iterator i = s.begin(); + std::string::const_iterator i = s.begin(); while (i != s.end()) { if (*i == '.') { res.push_back(cur); diff --git a/third_party/nix/src/libexpr/common-eval-args.cc b/third_party/nix/src/libexpr/common-eval-args.cc index 2059d5374195..19271f2cc582 100644 --- a/third_party/nix/src/libexpr/common-eval-args.cc +++ b/third_party/nix/src/libexpr/common-eval-args.cc @@ -37,10 +37,10 @@ Bindings* MixEvalArgs::getAutoArgs(EvalState& state) { for (auto& i : autoArgs) { Value* v = state.allocValue(); if (i.second[0] == 'E') { - state.mkThunk_( - *v, state.parseExprFromString(string(i.second, 1), absPath("."))); + state.mkThunk_(*v, state.parseExprFromString(std::string(i.second, 1), + absPath("."))); } else { - mkString(*v, string(i.second, 1)); + mkString(*v, std::string(i.second, 1)); } res->push_back(Attr(state.symbols.Create(i.first), v)); } diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index 60d3cd012df8..d93f39bba4fe 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -136,7 +136,7 @@ const Value* getPrimOp(const Value& v) { return primOp; } -string showType(const Value& v) { +std::string showType(const Value& v) { switch (v.type) { case tInt: return "an integer"; @@ -163,10 +163,10 @@ string showType(const Value& v) { case tBlackhole: return "a black hole"; case tPrimOp: - return fmt("the built-in function '%s'", string(v.primOp->name)); + return fmt("the built-in function '%s'", std::string(v.primOp->name)); case tPrimOpApp: return fmt("the partially applied built-in function '%s'", - string(getPrimOp(v)->primOp->name)); + std::string(getPrimOp(v)->primOp->name)); case tExternal: return v.external->showType(); case tFloat: @@ -456,7 +456,8 @@ Value* EvalState::addConstant(const std::string& name, Value& v) { *v2 = v; staticBaseEnv.vars[symbols.Create(name)] = baseEnvDispl; baseEnv.values[baseEnvDispl++] = v2; - std::string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name; + std::string name2 = + std::string(name, 0, 2) == "__" ? std::string(name, 2) : name; baseEnv.values[0]->attrs->push_back(Attr(symbols.Create(name2), v2)); return v2; } @@ -469,7 +470,8 @@ Value* EvalState::addPrimOp(const std::string& name, size_t arity, return addConstant(name, v); } Value* v = allocValue(); - std::string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name; + std::string name2 = + std::string(name, 0, 2) == "__" ? std::string(name, 2) : name; Symbol sym = symbols.Create(name2); v->type = tPrimOp; v->primOp = new PrimOp(primOp, arity, sym); @@ -1423,7 +1425,7 @@ void EvalState::forceFunction(Value& v, const Pos& pos) { } } -string EvalState::forceString(Value& v, const Pos& pos) { +std::string EvalState::forceString(Value& v, const Pos& pos) { forceValue(v, pos); if (v.type != tString) { if (pos) { @@ -1433,7 +1435,7 @@ string EvalState::forceString(Value& v, const Pos& pos) { throwTypeError("value is %1% while a string was expected", v); } } - return string(v.string.s); + return std::string(v.string.s); } void copyContext(const Value& v, PathSet& context) { @@ -1444,13 +1446,13 @@ void copyContext(const Value& v, PathSet& context) { } } -string EvalState::forceString(Value& v, PathSet& context, const Pos& pos) { +std::string EvalState::forceString(Value& v, PathSet& context, const Pos& pos) { std::string s = forceString(v, pos); copyContext(v, context); return s; } -string EvalState::forceStringNoCtx(Value& v, const Pos& pos) { +std::string EvalState::forceStringNoCtx(Value& v, const Pos& pos) { std::string s = forceString(v, pos); if (v.string.context != nullptr) { if (pos) { @@ -1483,10 +1485,10 @@ bool EvalState::isDerivation(Value& v) { return strcmp(i->second.value->string.s, "derivation") == 0; } -std::optional<string> EvalState::tryAttrsToString(const Pos& pos, Value& v, - PathSet& context, - bool coerceMore, - bool copyToStore) { +std::optional<std::string> EvalState::tryAttrsToString(const Pos& pos, Value& v, + PathSet& context, + bool coerceMore, + bool copyToStore) { auto i = v.attrs->find(sToString); if (i != v.attrs->end()) { Value v1; @@ -1497,8 +1499,9 @@ std::optional<string> EvalState::tryAttrsToString(const Pos& pos, Value& v, return {}; } -string EvalState::coerceToString(const Pos& pos, Value& v, PathSet& context, - bool coerceMore, bool copyToStore) { +std::string EvalState::coerceToString(const Pos& pos, Value& v, + PathSet& context, bool coerceMore, + bool copyToStore) { forceValue(v); std::string s; @@ -1569,7 +1572,7 @@ string EvalState::coerceToString(const Pos& pos, Value& v, PathSet& context, throwTypeError("cannot coerce %1% to a string, at %2%", v, pos); } -string EvalState::copyPathToStore(PathSet& context, const Path& path) { +std::string EvalState::copyPathToStore(PathSet& context, const Path& path) { if (nix::isDerivation(path)) { throwEvalError("file names are not allowed to end in '%1%'", drvExtension); } @@ -1931,9 +1934,9 @@ size_t valueSize(Value& v) { return doValue(v); } -string ExternalValueBase::coerceToString(const Pos& pos, PathSet& context, - bool copyMore, - bool copyToStore) const { +std::string ExternalValueBase::coerceToString(const Pos& pos, PathSet& context, + bool copyMore, + bool copyToStore) const { throw TypeError(format("cannot coerce %1% to a string, at %2%") % showType() % pos); } diff --git a/third_party/nix/src/libexpr/eval.hh b/third_party/nix/src/libexpr/eval.hh index 531294c93ca2..f13e8553d14b 100644 --- a/third_party/nix/src/libexpr/eval.hh +++ b/third_party/nix/src/libexpr/eval.hh @@ -180,10 +180,10 @@ class EvalState { set with attribute `type = "derivation"'). */ bool isDerivation(Value& v); - std::optional<string> tryAttrsToString(const Pos& pos, Value& v, - PathSet& context, - bool coerceMore = false, - bool copyToStore = true); + std::optional<std::string> tryAttrsToString(const Pos& pos, Value& v, + PathSet& context, + bool coerceMore = false, + bool copyToStore = true); /* String coercion. Converts strings, paths and derivations to a string. If `coerceMore' is set, also converts nulls, integers, @@ -295,11 +295,11 @@ class EvalState { }; /* Return a string representing the type of the value `v'. */ -string showType(const Value& v); +std::string showType(const Value& v); /* Decode a context string ‘!<name>!<path>’ into a pair <path, name>. */ -std::pair<string, string> decodeContext(const std::string& s); +std::pair<std::string, std::string> decodeContext(const std::string& s); /* If `path' refers to a directory, then append "/default.nix". */ Path resolveExprPath(Path path); diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc index 6d4ad33be063..bc40ec3fef6c 100644 --- a/third_party/nix/src/libexpr/get-drvs.cc +++ b/third_party/nix/src/libexpr/get-drvs.cc @@ -44,7 +44,7 @@ DrvInfo::DrvInfo(EvalState& state, const ref<Store>& store, outPath = i->second.path; } -string DrvInfo::queryName() const { +std::string DrvInfo::queryName() const { if (name.empty() && (attrs != nullptr)) { auto i = attrs->find(state->sName); if (i == attrs->end()) { @@ -55,7 +55,7 @@ string DrvInfo::queryName() const { return name; } -string DrvInfo::querySystem() const { +std::string DrvInfo::querySystem() const { if (system.empty() && (attrs != nullptr)) { auto i = attrs->find(state->sSystem); system = i == attrs->end() @@ -65,7 +65,7 @@ string DrvInfo::querySystem() const { return system; } -string DrvInfo::queryDrvPath() const { +std::string DrvInfo::queryDrvPath() const { if (drvPath.empty() && (attrs != nullptr)) { Bindings::iterator i = attrs->find(state->sDrvPath); PathSet context; @@ -76,7 +76,7 @@ string DrvInfo::queryDrvPath() const { return drvPath; } -string DrvInfo::queryOutPath() const { +std::string DrvInfo::queryOutPath() const { if (outPath.empty() && (attrs != nullptr)) { Bindings::iterator i = attrs->find(state->sOutPath); PathSet context; @@ -149,7 +149,7 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall) { return result; } -string DrvInfo::queryOutputName() const { +std::string DrvInfo::queryOutputName() const { if (outputName.empty() && (attrs != nullptr)) { Bindings::iterator i = attrs->find(state->sOutputName); outputName = @@ -223,7 +223,7 @@ Value* DrvInfo::queryMeta(const std::string& name) { return a->second.value; } -string DrvInfo::queryMetaString(const std::string& name) { +std::string DrvInfo::queryMetaString(const std::string& name) { Value* v = queryMeta(name); if ((v == nullptr) || v->type != tString) { return ""; @@ -308,7 +308,7 @@ void DrvInfo::setMeta(const std::string& name, Value* v) { } /* Cache for already considered attrsets. */ -using Done = set<Bindings*>; +using Done = std::set<Bindings*>; /* Evaluate value `v'. If it evaluates to a set of type `derivation', then put information about it in `drvs' (unless it's already in `done'). diff --git a/third_party/nix/src/libexpr/get-drvs.hh b/third_party/nix/src/libexpr/get-drvs.hh index 3da23194616e..a0840ee9b280 100644 --- a/third_party/nix/src/libexpr/get-drvs.hh +++ b/third_party/nix/src/libexpr/get-drvs.hh @@ -9,7 +9,7 @@ namespace nix { struct DrvInfo { public: - typedef std::map<string, Path> Outputs; + typedef std::map<std::string, Path> Outputs; private: EvalState* state; @@ -68,9 +68,9 @@ struct DrvInfo { }; #if HAVE_BOEHMGC -typedef list<DrvInfo, traceable_allocator<DrvInfo> > DrvInfos; +typedef std::list<DrvInfo, traceable_allocator<DrvInfo> > DrvInfos; #else -typedef list<DrvInfo> DrvInfos; +typedef std::list<DrvInfo> DrvInfos; #endif /* If value `v' denotes a derivation, return a DrvInfo object diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc index ac8150532f25..20c326776cb7 100644 --- a/third_party/nix/src/libexpr/names.cc +++ b/third_party/nix/src/libexpr/names.cc @@ -18,8 +18,8 @@ DrvName::DrvName(const std::string& s) : hits(0) { for (unsigned int i = 0; i < s.size(); ++i) { /* !!! isalpha/isdigit are affected by the locale. */ if (s[i] == '-' && i + 1 < s.size() && (isalpha(s[i + 1]) == 0)) { - name = string(s, 0, i); - version = string(s, i + 1); + name = std::string(s, 0, i); + version = std::string(s, i + 1); break; } } @@ -37,8 +37,8 @@ bool DrvName::matches(DrvName& n) { return !(!version.empty() && version != n.version); } -string nextComponent(string::const_iterator& p, - const string::const_iterator end) { +std::string nextComponent(std::string::const_iterator& p, + const std::string::const_iterator end) { /* Skip any dots and dashes (component separators). */ while (p != end && (*p == '.' || *p == '-')) { ++p; @@ -91,8 +91,8 @@ static bool componentsLT(const std::string& c1, const std::string& c2) { } int compareVersions(const std::string& v1, const std::string& v2) { - string::const_iterator p1 = v1.begin(); - string::const_iterator p2 = v2.begin(); + std::string::const_iterator p1 = v1.begin(); + std::string::const_iterator p2 = v2.begin(); while (p1 != v1.end() || p2 != v2.end()) { std::string c1 = nextComponent(p1, v1.end()); diff --git a/third_party/nix/src/libexpr/names.hh b/third_party/nix/src/libexpr/names.hh index e2ddb5cb993e..521740152ca2 100644 --- a/third_party/nix/src/libexpr/names.hh +++ b/third_party/nix/src/libexpr/names.hh @@ -21,10 +21,10 @@ struct DrvName { std::unique_ptr<std::regex> regex; }; -typedef list<DrvName> DrvNames; +typedef std::list<DrvName> DrvNames; -string nextComponent(string::const_iterator& p, - const string::const_iterator end); +std::string nextComponent(std::string::const_iterator& p, + const std::string::const_iterator end); int compareVersions(const std::string& v1, const std::string& v2); DrvNames drvNamesFromArgs(const Strings& opArgs); diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc index 3d454d266ff0..ef4a75ed8d5b 100644 --- a/third_party/nix/src/libexpr/nixexpr.cc +++ b/third_party/nix/src/libexpr/nixexpr.cc @@ -16,7 +16,7 @@ std::ostream& operator<<(std::ostream& str, const Expr& e) { static void showString(std::ostream& str, const std::string& s) { str << '"'; - for (auto c : (string)s) { + for (auto c : (std::string)s) { if (c == '"' || c == '\\' || c == '$') { str << "\\" << c; } else if (c == '\n') { @@ -188,14 +188,14 @@ std::ostream& operator<<(std::ostream& str, const Pos& pos) { if (!pos) { str << "undefined position"; } else { - str << (format(ANSI_BOLD "%1%" ANSI_NORMAL ":%2%:%3%") % (string)pos.file % - pos.line % pos.column) + str << (format(ANSI_BOLD "%1%" ANSI_NORMAL ":%2%:%3%") % + (std::string)pos.file % pos.line % pos.column) .str(); } return str; } -string showAttrPath(const AttrPath& attrPath) { +std::string showAttrPath(const AttrPath& attrPath) { std::ostringstream out; bool first = true; for (auto& i : attrPath) { @@ -407,9 +407,10 @@ void ExprLambda::setName(Symbol& name) { body->setName(name); } -string ExprLambda::showNamePos() const { +std::string ExprLambda::showNamePos() const { return (format("%1% at %2%") % - (name.set() ? "'" + (string)name + "'" : "anonymous function") % pos) + (name.set() ? "'" + (std::string)name + "'" : "anonymous function") % + pos) .str(); } diff --git a/third_party/nix/src/libexpr/nixexpr.hh b/third_party/nix/src/libexpr/nixexpr.hh index 3ac651c94548..8817fbc9ddb8 100644 --- a/third_party/nix/src/libexpr/nixexpr.hh +++ b/third_party/nix/src/libexpr/nixexpr.hh @@ -8,15 +8,18 @@ namespace nix { -MakeError(EvalError, Error) MakeError(ParseError, Error) - MakeError(AssertionError, EvalError) MakeError(ThrownError, AssertionError) - MakeError(Abort, EvalError) MakeError(TypeError, EvalError) - MakeError(UndefinedVarError, Error) - MakeError(RestrictedPathError, Error) - - /* Position objects. */ - - struct Pos { +MakeError(EvalError, Error); +MakeError(ParseError, Error); +MakeError(AssertionError, EvalError); +MakeError(ThrownError, AssertionError); +MakeError(Abort, EvalError); +MakeError(TypeError, EvalError); +MakeError(UndefinedVarError, Error); +MakeError(RestrictedPathError, Error); + +/* Position objects. */ + +struct Pos { Symbol file; unsigned int line, column; Pos() : line(0), column(0){}; @@ -30,7 +33,7 @@ MakeError(EvalError, Error) MakeError(ParseError, Error) if (!p2.line) { return false; } - int d = ((string)file).compare((string)p2.file); + int d = ((std::string)file).compare((std::string)p2.file); if (d < 0) { return true; } @@ -66,7 +69,7 @@ struct AttrName { typedef std::vector<AttrName> AttrPath; -string showAttrPath(const AttrPath& attrPath); +std::string showAttrPath(const AttrPath& attrPath); /* Abstract syntax of Nix expressions. */ @@ -297,16 +300,20 @@ struct ExprOpNot : Expr { void eval(EvalState& state, Env& env, Value& v); \ }; -MakeBinOp(ExprApp, "") MakeBinOp(ExprOpEq, "==") MakeBinOp(ExprOpNEq, "!=") - MakeBinOp(ExprOpAnd, "&&") MakeBinOp(ExprOpOr, "||") - MakeBinOp(ExprOpImpl, "->") MakeBinOp(ExprOpUpdate, "//") - MakeBinOp(ExprOpConcatLists, "++") +MakeBinOp(ExprApp, ""); +MakeBinOp(ExprOpEq, "=="); +MakeBinOp(ExprOpNEq, "!="); +MakeBinOp(ExprOpAnd, "&&"); +MakeBinOp(ExprOpOr, "||"); +MakeBinOp(ExprOpImpl, "->"); +MakeBinOp(ExprOpUpdate, "//"); +MakeBinOp(ExprOpConcatLists, "++"); - struct ExprConcatStrings : Expr { +struct ExprConcatStrings : Expr { Pos pos; bool forceString; - vector<Expr*>* es; - ExprConcatStrings(const Pos& pos, bool forceString, vector<Expr*>* es) + std::vector<Expr*>* es; + ExprConcatStrings(const Pos& pos, bool forceString, std::vector<Expr*>* es) : pos(pos), forceString(forceString), es(es){}; COMMON_METHODS }; diff --git a/third_party/nix/src/libexpr/parser.y b/third_party/nix/src/libexpr/parser.y index bd62a7fd0f52..9ba053ee7b12 100644 --- a/third_party/nix/src/libexpr/parser.y +++ b/third_party/nix/src/libexpr/parser.y @@ -146,7 +146,7 @@ static void addFormal(const Pos & pos, Formals * formals, const Formal & formal) } -static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Expr *> & es) +static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, std::vector<Expr *> & es) { if (es.empty()) { return new ExprString(symbols.Create("")); } @@ -186,11 +186,11 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex } /* Strip spaces from each line. */ - vector<Expr *> * es2 = new vector<Expr *>; + std::vector<Expr *> * es2 = new std::vector<Expr *>; atStartOfLine = true; size_t curDropped = 0; size_t n = es.size(); - for (vector<Expr *>::iterator i = es.begin(); i != es.end(); ++i, --n) { + for (std::vector<Expr *>::iterator i = es.begin(); i != es.end(); ++i, --n) { ExprIndStr * e = dynamic_cast<ExprIndStr *>(*i); if (!e) { atStartOfLine = false; @@ -223,9 +223,10 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex /* Remove the last line if it is empty and consists only of spaces. */ if (n == 1) { - string::size_type p = s2.find_last_of('\n'); - if (p != string::npos && s2.find_first_not_of(' ', p + 1) == string::npos) - s2 = string(s2, 0, p + 1); + std::string::size_type p = s2.find_last_of('\n'); + if (p != std::string::npos && s2.find_first_not_of(' ', p + 1) == std::string::npos) { + s2 = std::string(s2, 0, p + 1); + } } es2->push_back(new ExprString(symbols.Create(s2))); @@ -354,7 +355,7 @@ expr_op | expr_op UPDATE expr_op { $$ = new ExprOpUpdate(CUR_POS, $1, $3); } | expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); } | expr_op '+' expr_op - { $$ = new ExprConcatStrings(CUR_POS, false, new vector<Expr *>({$1, $3})); } + { $$ = new ExprConcatStrings(CUR_POS, false, new std::vector<Expr *>({$1, $3})); } | expr_op '-' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__sub")), $1), $3); } | expr_op '*' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__mul")), $1), $3); } | expr_op '/' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__div")), $1), $3); } @@ -394,7 +395,7 @@ expr_simple $$ = stripIndentation(CUR_POS, data->symbols, *$2); } | PATH { $$ = new ExprPath(absPath($1, data->basePath)); } - | HPATH { $$ = new ExprPath(getHome() + string{$1 + 1}); } + | HPATH { $$ = new ExprPath(getHome() + std::string{$1 + 1}); } | SPATH { std::string path($1 + 1, strlen($1) - 2); $$ = new ExprApp(CUR_POS, @@ -424,9 +425,9 @@ string_parts string_parts_interpolated : string_parts_interpolated STR { $$ = $1; $1->push_back($2); } | string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $1->push_back($3); } - | DOLLAR_CURLY expr '}' { $$ = new vector<Expr *>; $$->push_back($2); } + | DOLLAR_CURLY expr '}' { $$ = new std::vector<Expr *>; $$->push_back($2); } | STR DOLLAR_CURLY expr '}' { - $$ = new vector<Expr *>; + $$ = new std::vector<Expr *>; $$->push_back($1); $$->push_back($3); } @@ -435,7 +436,7 @@ string_parts_interpolated ind_string_parts : ind_string_parts IND_STR { $$ = $1; $1->push_back($2); } | ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $1->push_back($3); } - | { $$ = new vector<Expr *>; } + | { $$ = new std::vector<Expr *>; } ; binds @@ -487,9 +488,9 @@ attrpath } else $$->push_back(AttrName($3)); } - | attr { $$ = new vector<AttrName>; $$->push_back(AttrName(data->symbols.Create($1))); } + | attr { $$ = new std::vector<AttrName>; $$->push_back(AttrName(data->symbols.Create($1))); } | string_attr - { $$ = new vector<AttrName>; + { $$ = new std::vector<AttrName>; ExprString *str = dynamic_cast<ExprString *>($1); if (str) { $$->push_back(AttrName(str->s)); @@ -603,7 +604,7 @@ Expr * EvalState::parseExprFromFile(const Path & path, StaticEnv & staticEnv) Expr * EvalState::parseExprFromString(const std::string & s, const Path & basePath, StaticEnv & staticEnv) { - return parse(s.c_str(), "(string)", basePath, staticEnv); + return parse(s.c_str(), "(std::string)", basePath, staticEnv); } @@ -625,11 +626,11 @@ void EvalState::addToSearchPath(const std::string & s) size_t pos = s.find('='); std::string prefix; Path path; - if (pos == string::npos) { + if (pos == std::string::npos) { path = s; } else { - prefix = string(s, 0, pos); - path = string(s, pos + 1); + prefix = std::string(s, 0, pos); + path = std::string(s, pos + 1); } searchPath.emplace_back(prefix, path); @@ -653,7 +654,7 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string & path, cons if (path.compare(0, s, i.first) != 0 || (path.size() > s && path[s] != '/')) continue; - suffix = path.size() == s ? "" : "/" + string(path, s); + suffix = path.size() == s ? "" : "/" + std::string(path, s); } auto r = resolveSearchPathElem(i); if (!r.first) { continue; } @@ -662,7 +663,7 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string & path, cons } format f = format( "file '%1%' was not found in the Nix search path (add it using $NIX_PATH or -I)" - + string(pos ? ", at %2%" : "")); + + std::string(pos ? ", at %2%" : "")); f.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); throw ThrownError(f % path % pos); } diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 5a9f1fe72076..fa0057041713 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -32,13 +32,14 @@ namespace nix { /* Decode a context string ‘!<name>!<path>’ into a pair <path, name>. */ -std::pair<string, string> decodeContext(const std::string& s) { +std::pair<std::string, std::string> decodeContext(const std::string& s) { if (s.at(0) == '!') { size_t index = s.find('!', 1); - return std::pair<string, string>(string(s, index + 1), - string(s, 1, index - 1)); + return std::pair<std::string, std::string>(std::string(s, index + 1), + std::string(s, 1, index - 1)); } - return std::pair<string, string>(s.at(0) == '/' ? s : string(s, 1), ""); + return std::pair<std::string, std::string>( + s.at(0) == '/' ? s : std::string(s, 1), ""); } InvalidPathError::InvalidPathError(const Path& path) @@ -48,7 +49,7 @@ void EvalState::realiseContext(const PathSet& context) { PathSet drvs; for (auto& i : context) { - std::pair<string, string> decoded = decodeContext(i); + std::pair<std::string, std::string> decoded = decodeContext(i); Path ctx = decoded.first; assert(store->isStorePath(ctx)); if (!store->isValidPath(ctx)) { @@ -382,9 +383,9 @@ struct CompareValues { }; #if HAVE_BOEHMGC -typedef list<Value*, gc_allocator<Value*>> ValueList; +typedef std::list<Value*, gc_allocator<Value*>> ValueList; #else -typedef list<Value*> ValueList; +typedef std::list<Value*> ValueList; #endif static void prim_genericClosure(EvalState& state, const Pos& pos, Value** args, @@ -418,7 +419,7 @@ static void prim_genericClosure(EvalState& state, const Pos& pos, Value** args, ValueList res; // `doneKeys' doesn't need to be a GC root, because its values are // reachable from res. - set<Value*, CompareValues> doneKeys; + std::set<Value*, CompareValues> doneKeys; while (!workSet.empty()) { Value* e = *(workSet.begin()); workSet.pop_front(); @@ -743,7 +744,7 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos, if (path.at(0) == '=') { /* !!! This doesn't work if readOnlyMode is set. */ PathSet refs; - state.store->computeFSClosure(string(path, 1), refs); + state.store->computeFSClosure(std::string(path, 1), refs); for (auto& j : refs) { drv.inputSrcs.insert(j); if (isDerivation(j)) { @@ -754,7 +755,7 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos, /* Handle derivation outputs of the form ‘!<name>!<path>’. */ else if (path.at(0) == '!') { - std::pair<string, string> ctx = decodeContext(path); + std::pair<std::string, std::string> ctx = decodeContext(path); drv.inputDrvs[ctx.first].insert(ctx.second); } @@ -965,7 +966,7 @@ static void prim_readFile(EvalState& state, const Pos& pos, Value** args, } std::string s = readFile(state.checkSourcePath(state.toRealPath(path, context))); - if (s.find((char)0) != string::npos) { + if (s.find((char)0) != std::string::npos) { throw Error(format("the contents of the file '%1%' cannot be represented " "as a Nix string") % path); @@ -1899,7 +1900,7 @@ static void prim_substring(EvalState& state, const Pos& pos, Value** args, pos); } - mkString(v, (unsigned int)start >= s.size() ? "" : string(s, start, len), + mkString(v, (unsigned int)start >= s.size() ? "" : std::string(s, start, len), context); } @@ -2066,13 +2067,13 @@ static void prim_replaceStrings(EvalState& state, const Pos& pos, Value** args, pos); } - vector<string> from; + std::vector<std::string> from; from.reserve(args[0]->listSize()); for (unsigned int n = 0; n < args[0]->listSize(); ++n) { from.push_back(state.forceString(*args[0]->listElems()[n], pos)); } - vector<std::pair<string, PathSet>> to; + std::vector<std::pair<std::string, PathSet>> to; to.reserve(args[1]->listSize()); for (unsigned int n = 0; n < args[1]->listSize(); ++n) { PathSet ctx; diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc index 2ae8ba8aa99e..481a2910bf84 100644 --- a/third_party/nix/src/libexpr/primops/context.cc +++ b/third_party/nix/src/libexpr/primops/context.cc @@ -36,7 +36,7 @@ static void prim_unsafeDiscardOutputDependency(EvalState& state, const Pos& pos, PathSet context2; for (auto& p : context) { - context2.insert(p.at(0) == '=' ? string(p, 1) : p); + context2.insert(p.at(0) == '=' ? std::string(p, 1) : p); } mkString(v, s, context2); @@ -79,10 +79,10 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args, std::string output; const Path* path = &p; if (p.at(0) == '=') { - drv = string(p, 1); + drv = std::string(p, 1); path = &drv; } else if (p.at(0) == '!') { - std::pair<string, string> ctx = decodeContext(p); + std::pair<std::string, std::string> ctx = decodeContext(p); drv = ctx.first; output = ctx.second; path = &drv; @@ -170,7 +170,7 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args, "derivation, to a string, at %s", i->name, i->pos); } - context.insert("=" + string(i->name)); + context.insert("=" + std::string(i->name)); } } @@ -186,7 +186,7 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args, for (unsigned int n = 0; n < iter->second.value->listSize(); ++n) { auto name = state.forceStringNoCtx(*iter->second.value->listElems()[n], *iter->second.pos); - context.insert("!" + name + "!" + string(i->name)); + context.insert("!" + name + "!" + std::string(i->name)); } } } diff --git a/third_party/nix/src/libmain/common-args.cc b/third_party/nix/src/libmain/common-args.cc index 3d9b8ebfaefd..f85eadbf70d9 100644 --- a/third_party/nix/src/libmain/common-args.cc +++ b/third_party/nix/src/libmain/common-args.cc @@ -6,7 +6,7 @@ namespace nix { -MixCommonArgs::MixCommonArgs(const string& programName) +MixCommonArgs::MixCommonArgs(const std::string& programName) : programName(programName) { mkFlag() .longName("option") diff --git a/third_party/nix/src/libmain/common-args.hh b/third_party/nix/src/libmain/common-args.hh index d8917b836778..88b51047dfbe 100644 --- a/third_party/nix/src/libmain/common-args.hh +++ b/third_party/nix/src/libmain/common-args.hh @@ -5,8 +5,8 @@ namespace nix { struct MixCommonArgs : virtual Args { - string programName; - MixCommonArgs(const string& programName); + std::string programName; + MixCommonArgs(const std::string& programName); }; struct MixDryRun : virtual Args { diff --git a/third_party/nix/src/libmain/shared.cc b/third_party/nix/src/libmain/shared.cc index d2b2a2800c46..549134872e91 100644 --- a/third_party/nix/src/libmain/shared.cc +++ b/third_party/nix/src/libmain/shared.cc @@ -83,8 +83,8 @@ void printMissing(const ref<Store>& store, const PathSet& willBuild, } } -string getArg(const string& opt, Strings::iterator& i, - const Strings::iterator& end) { +std::string getArg(const std::string& opt, Strings::iterator& i, + const Strings::iterator& end) { ++i; if (i == end) { throw UsageError(format("'%1%' requires an argument") % opt); @@ -246,13 +246,13 @@ void parseCmdLine( } void parseCmdLine( - const string& programName, const Strings& args, + const std::string& programName, const Strings& args, std::function<bool(Strings::iterator& arg, const Strings::iterator& end)> parseArg) { LegacyArgs(programName, std::move(parseArg)).parseCmdline(args); } -void printVersion(const string& programName) { +void printVersion(const std::string& programName) { std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl; // TODO(tazjin): figure out what the fuck this is @@ -273,18 +273,18 @@ void printVersion(const string& programName) { throw Exit(); } -void showManPage(const string& name) { +void showManPage(const std::string& name) { restoreSignals(); setenv("MANPATH", settings.nixManDir.c_str(), 1); execlp("man", "man", name.c_str(), nullptr); throw SysError(format("command 'man %1%' failed") % name.c_str()); } -int handleExceptions(const string& programName, +int handleExceptions(const std::string& programName, const std::function<void()>& fun) { ReceiveInterrupts receiveInterrupts; // FIXME: need better place for this - string error = ANSI_RED "error:" ANSI_NORMAL " "; + std::string error = ANSI_RED "error:" ANSI_NORMAL " "; try { try { fun(); @@ -328,7 +328,7 @@ RunPager::RunPager() { if (pager == nullptr) { pager = getenv("PAGER"); } - if (pager && ((string)pager == "" || (string)pager == "cat")) { + if (pager && ((std::string)pager == "" || (std::string)pager == "cat")) { return; } @@ -371,7 +371,7 @@ RunPager::~RunPager() { } } -string showBytes(unsigned long long bytes) { +std::string showBytes(unsigned long long bytes) { return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str(); } diff --git a/third_party/nix/src/libmain/shared.hh b/third_party/nix/src/libmain/shared.hh index da1c9cc66ac3..edd0a5159a9d 100644 --- a/third_party/nix/src/libmain/shared.hh +++ b/third_party/nix/src/libmain/shared.hh @@ -18,7 +18,7 @@ class Exit : public std::exception { virtual ~Exit(); }; -int handleExceptions(const string& programName, +int handleExceptions(const std::string& programName, const std::function<void()>& fun); /* Don't forget to call initPlugins() after settings are initialized! */ @@ -30,11 +30,11 @@ void parseCmdLine( parseArg); void parseCmdLine( - const string& programName, const Strings& args, + const std::string& programName, const Strings& args, std::function<bool(Strings::iterator& arg, const Strings::iterator& end)> parseArg); -void printVersion(const string& programName); +void printVersion(const std::string& programName); /* Ugh. No better place to put this. */ void printGCWarning(); @@ -47,17 +47,17 @@ void printMissing(const ref<Store>& store, const PathSet& willBuild, const PathSet& willSubstitute, const PathSet& unknown, unsigned long long downloadSize, unsigned long long narSize); -string getArg(const string& opt, Strings::iterator& i, - const Strings::iterator& end); +std::string getArg(const std::string& opt, Strings::iterator& i, + const Strings::iterator& end); template <class N> -N getIntArg(const string& opt, Strings::iterator& i, +N getIntArg(const std::string& opt, Strings::iterator& i, const Strings::iterator& end, bool allowUnit) { ++i; if (i == end) { throw UsageError(format("'%1%' requires an argument") % opt); } - string s = *i; + std::string s = *i; N multiplier = 1; if (allowUnit && !s.empty()) { char u = std::toupper(*s.rbegin()); @@ -98,7 +98,7 @@ struct LegacyArgs : public MixCommonArgs { }; /* Show the manual page for the specified program. */ -void showManPage(const string& name); +void showManPage(const std::string& name); /* The constructor of this class starts a pager if stdout is a terminal and $PAGER is set. Stdout is redirected to the pager. */ @@ -115,7 +115,7 @@ extern volatile ::sig_atomic_t blockInt; /* GC helpers. */ -string showBytes(unsigned long long bytes); +std::string showBytes(unsigned long long bytes); struct GCResults; diff --git a/third_party/nix/src/libstore/binary-cache-store.cc b/third_party/nix/src/libstore/binary-cache-store.cc index 487c12b5313e..37d1c1a440a2 100644 --- a/third_party/nix/src/libstore/binary-cache-store.cc +++ b/third_party/nix/src/libstore/binary-cache-store.cc @@ -289,7 +289,7 @@ void BinaryCacheStore::queryPathInfoUncached( }}); } -Path BinaryCacheStore::addToStore(const string& name, const Path& srcPath, +Path BinaryCacheStore::addToStore(const std::string& name, const Path& srcPath, bool recursive, HashType hashAlgo, PathFilter& filter, RepairFlag repair) { // FIXME: some cut&paste from LocalStore::addToStore(). @@ -316,7 +316,8 @@ Path BinaryCacheStore::addToStore(const string& name, const Path& srcPath, return info.path; } -Path BinaryCacheStore::addTextToStore(const string& name, const string& s, +Path BinaryCacheStore::addTextToStore(const std::string& name, + const std::string& s, const PathSet& references, RepairFlag repair) { ValidPathInfo info; diff --git a/third_party/nix/src/libstore/binary-cache-store.hh b/third_party/nix/src/libstore/binary-cache-store.hh index f5bd66bbd6e1..b8e1ccabf264 100644 --- a/third_party/nix/src/libstore/binary-cache-store.hh +++ b/third_party/nix/src/libstore/binary-cache-store.hh @@ -74,7 +74,7 @@ class BinaryCacheStore : public Store { const Path& path, Callback<std::shared_ptr<ValidPathInfo>> callback) noexcept override; - Path queryPathFromHashPart(const string& hashPart) override { + Path queryPathFromHashPart(const std::string& hashPart) override { unsupported("queryPathFromHashPart"); } @@ -84,11 +84,11 @@ class BinaryCacheStore : public Store { RepairFlag repair, CheckSigsFlag checkSigs, std::shared_ptr<FSAccessor> accessor) override; - Path addToStore(const string& name, const Path& srcPath, bool recursive, + Path addToStore(const std::string& name, const Path& srcPath, bool recursive, HashType hashAlgo, PathFilter& filter, RepairFlag repair) override; - Path addTextToStore(const string& name, const string& s, + Path addTextToStore(const std::string& name, const std::string& s, const PathSet& references, RepairFlag repair) override; void narFromPath(const Path& path, Sink& sink) override; diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc index 266cedc096ad..49204a72a8cd 100644 --- a/third_party/nix/src/libstore/build.cc +++ b/third_party/nix/src/libstore/build.cc @@ -73,9 +73,7 @@ namespace nix { -using std::map; - -static string pathNullDevice = "/dev/null"; +static std::string pathNullDevice = "/dev/null"; /* Forward definition. */ class Worker; @@ -92,11 +90,11 @@ struct CompareGoalPtrs { }; /* Set of goals. */ -typedef set<GoalPtr, CompareGoalPtrs> Goals; -using WeakGoals = list<WeakGoalPtr>; +typedef std::set<GoalPtr, CompareGoalPtrs> Goals; +using WeakGoals = std::list<WeakGoalPtr>; /* A map of paths to goals (and the other way around). */ -typedef map<Path, WeakGoalPtr> WeakGoalMap; +typedef std::map<Path, WeakGoalPtr> WeakGoalMap; class Goal : public std::enable_shared_from_this<Goal> { public: @@ -131,7 +129,7 @@ class Goal : public std::enable_shared_from_this<Goal> { unsigned int nrIncompleteClosure; /* Name of this goal for debugging purposes. */ - string name; + std::string name; /* Whether the goal is finished. */ ExitCode exitCode; @@ -150,13 +148,13 @@ class Goal : public std::enable_shared_from_this<Goal> { virtual void waiteeDone(GoalPtr waitee, ExitCode result); - virtual void handleChildOutput(int fd, const string& data) { abort(); } + virtual void handleChildOutput(int fd, const std::string& data) { abort(); } virtual void handleEOF(int fd) { abort(); } void trace(const FormatOrString& fs); - string getName() { return name; } + std::string getName() { return name; } ExitCode getExitCode() { return exitCode; } @@ -165,15 +163,15 @@ class Goal : public std::enable_shared_from_this<Goal> { by the worker (important!), etc. */ virtual void timedOut() = 0; - virtual string key() = 0; + virtual std::string key() = 0; protected: virtual void amDone(ExitCode result); }; bool CompareGoalPtrs::operator()(const GoalPtr& a, const GoalPtr& b) const { - string s1 = a->key(); - string s2 = b->key(); + std::string s1 = a->key(); + std::string s2 = b->key(); return s1 < s2; } @@ -185,7 +183,7 @@ using steady_time_point = std::chrono::time_point<std::chrono::steady_clock>; struct Child { WeakGoalPtr goal; Goal* goal2; // ugly hackery - set<int> fds; + std::set<int> fds; bool respectTimeouts; bool inBuildSlot; steady_time_point lastOutput; /* time we last got output on stdout/stderr */ @@ -293,8 +291,8 @@ class Worker { /* Registers a running child process. `inBuildSlot' means that the process counts towards the jobs limit. */ - void childStarted(const GoalPtr& goal, const set<int>& fds, bool inBuildSlot, - bool respectTimeouts); + void childStarted(const GoalPtr& goal, const std::set<int>& fds, + bool inBuildSlot, bool respectTimeouts); /* Unregisters a running child process. `wakeSleepers' should be false if there is no sense in waking up goals that are sleeping @@ -483,7 +481,7 @@ class UserLock { Path fnUserLock; AutoCloseFD fdUserLock; - string user; + std::string user; uid_t uid; gid_t gid; std::vector<gid_t> supplementaryGIDs; @@ -494,7 +492,7 @@ class UserLock { void kill(); - string getUser() { return user; } + std::string getUser() { return user; } uid_t getUID() { assert(uid); return uid; @@ -710,12 +708,12 @@ HookInstance::~HookInstance() { ////////////////////////////////////////////////////////////////////// -typedef map<std::string, std::string> StringRewrites; +typedef std::map<std::string, std::string> StringRewrites; std::string rewriteStrings(std::string s, const StringRewrites& rewrites) { for (auto& i : rewrites) { size_t j = 0; - while ((j = s.find(i.first, j)) != string::npos) { + while ((j = s.find(i.first, j)) != std::string::npos) { s.replace(j, i.first.size(), i.second); } } @@ -831,16 +829,16 @@ class DerivationGoal : public Goal { explicit ChrootPath(Path source = "", bool optional = false) : source(std::move(source)), optional(optional) {} }; - typedef map<Path, ChrootPath> + typedef std::map<Path, ChrootPath> DirsInChroot; // maps target path to source path DirsInChroot dirsInChroot; - typedef map<string, string> Environment; + typedef std::map<std::string, std::string> Environment; Environment env; /* Hash rewriting. */ StringRewrites inputRewrites, outputRewrites; - typedef map<Path, Path> RedirectedOutputs; + typedef std::map<Path, Path> RedirectedOutputs; RedirectedOutputs redirectedOutputs; BuildMode buildMode; @@ -886,7 +884,7 @@ class DerivationGoal : public Goal { void timedOut() override; - string key() override { + std::string key() override { /* Ensure that derivations get built in order of their name, i.e. a derivation named "aardvark" always comes before "baboon". And substitution goals always happen before @@ -956,7 +954,7 @@ class DerivationGoal : public Goal { void deleteTmpDir(bool force); /* Callback used by the worker to write to the log. */ - void handleChildOutput(int fd, const string& data) override; + void handleChildOutput(int fd, const std::string& data) override; void handleEOF(int fd) override; void flushLine(); @@ -975,7 +973,7 @@ class DerivationGoal : public Goal { void amDone(ExitCode result) override { Goal::amDone(result); } - void done(BuildResult::Status status, const string& msg = ""); + void done(BuildResult::Status status, const std::string& msg = ""); PathSet exportReferences(const PathSet& storePaths); }; @@ -1036,9 +1034,7 @@ DerivationGoal::~DerivationGoal() { } } -inline bool DerivationGoal::needsHashRewrite() { - return !useChroot; -} +inline bool DerivationGoal::needsHashRewrite() { return !useChroot; } void DerivationGoal::killChild() { if (pid != -1) { @@ -1762,11 +1758,11 @@ HookReply DerivationGoal::tryBuildHook() { /* Read the first line of input, which should be a word indicating whether the hook wishes to perform the build. */ - string reply; + std::string reply; while (true) { - string s = readLine(worker.hook->fromHook.readSide.get()); - if (string(s, 0, 2) == "# ") { - reply = string(s, 2); + std::string s = readLine(worker.hook->fromHook.readSide.get()); + if (std::string(s, 0, 2) == "# ") { + reply = std::string(s, 2); break; } s += "\n"; @@ -1816,7 +1812,7 @@ HookReply DerivationGoal::tryBuildHook() { /* Create the log file and pipe. */ Path logFile = openLogFile(); - set<int> fds; + std::set<int> fds; fds.insert(hook->fromHook.readSide.get()); fds.insert(hook->builderOut.readSide.get()); worker.childStarted(shared_from_this(), fds, false, false); @@ -1970,14 +1966,14 @@ void DerivationGoal::startBuilder() { temporary build directory. The text files have the format used by `nix-store --register-validity'. However, the deriver fields are left empty. */ - string s = get(drv->env, "exportReferencesGraph"); + std::string s = get(drv->env, "exportReferencesGraph"); auto ss = tokenizeString<Strings>(s); if (ss.size() % 2 != 0) { throw BuildError( format("odd number of tokens in 'exportReferencesGraph': '%1%'") % s); } for (auto i = ss.begin(); i != ss.end();) { - string fileName = *i++; + std::string fileName = *i++; checkStoreName(fileName); /* !!! abuse of this function */ Path storePath = *i++; @@ -2007,10 +2003,11 @@ void DerivationGoal::startBuilder() { i.pop_back(); } size_t p = i.find('='); - if (p == string::npos) { + if (p == std::string::npos) { dirsInChroot[i] = ChrootPath(i, optional); } else { - dirsInChroot[string(i, 0, p)] = ChrootPath(string(i, p + 1), optional); + dirsInChroot[std::string(i, 0, p)] = + ChrootPath(std::string(i, p + 1), optional); } } dirsInChroot[tmpDirInSandbox] = ChrootPath(tmpDir); @@ -2211,7 +2208,7 @@ void DerivationGoal::startBuilder() { auto state = stBegin; auto lines = runProgram(settings.preBuildHook, false, args); auto lastPos = std::string::size_type{0}; - for (auto nlPos = lines.find('\n'); nlPos != string::npos; + for (auto nlPos = lines.find('\n'); nlPos != std::string::npos; nlPos = lines.find('\n', lastPos)) { auto line = std::string{lines, lastPos, nlPos - lastPos}; lastPos = nlPos + 1; @@ -2226,10 +2223,11 @@ void DerivationGoal::startBuilder() { state = stBegin; } else { auto p = line.find('='); - if (p == string::npos) { + if (p == std::string::npos) { dirsInChroot[line] = ChrootPath(line); } else { - dirsInChroot[string(line, 0, p)] = ChrootPath(string(line, p + 1)); + dirsInChroot[std::string(line, 0, p)] = + ChrootPath(std::string(line, p + 1)); } } } @@ -2454,12 +2452,12 @@ void DerivationGoal::startBuilder() { /* Check if setting up the build environment failed. */ while (true) { - string msg = readLine(builderOut.readSide.get()); - if (string(msg, 0, 1) == "\1") { + std::string msg = readLine(builderOut.readSide.get()); + if (std::string(msg, 0, 1) == "\1") { if (msg.size() == 1) { break; } - throw Error(string(msg, 1)); + throw Error(std::string(msg, 1)); } DLOG(INFO) << msg; } @@ -2488,7 +2486,7 @@ void DerivationGoal::initTmpDir() { if (passAsFile.find(i.first) == passAsFile.end()) { env[i.first] = i.second; } else { - string fn = ".attr-" + std::to_string(fileNr++); + std::string fn = ".attr-" + std::to_string(fileNr++); Path p = tmpDir + "/" + fn; writeFile(p, rewriteStrings(i.second, inputRewrites)); chownToBuilder(p); @@ -3110,7 +3108,7 @@ void DerivationGoal::runChild() { if (!drv->isBuiltin()) { builder = drv->builder.c_str(); - string builderBasename = baseNameOf(drv->builder); + std::string builderBasename = baseNameOf(drv->builder); args.push_back(builderBasename); } @@ -3119,7 +3117,7 @@ void DerivationGoal::runChild() { } /* Indicate that we managed to set up the build environment. */ - writeFull(STDERR_FILENO, string("\1\n")); + writeFull(STDERR_FILENO, std::string("\1\n")); /* Execute the program. This should not return. */ if (drv->isBuiltin()) { @@ -3135,11 +3133,11 @@ void DerivationGoal::runChild() { builtinBuildenv(drv2); } else { throw Error(format("unsupported builtin function '%1%'") % - string(drv->builder, 8)); + std::string(drv->builder, 8)); } _exit(0); } catch (std::exception& e) { - writeFull(STDERR_FILENO, "error: " + string(e.what()) + "\n"); + writeFull(STDERR_FILENO, "error: " + std::string(e.what()) + "\n"); _exit(1); } } @@ -3151,7 +3149,7 @@ void DerivationGoal::runChild() { } catch (std::exception& e) { writeFull(STDERR_FILENO, "\1while setting up the build environment: " + - string(e.what()) + "\n"); + std::string(e.what()) + "\n"); _exit(1); } } @@ -3621,7 +3619,7 @@ void DerivationGoal::checkOutputs( } if (!badPaths.empty()) { - string badPathsStr; + std::string badPathsStr; for (auto& i : badPaths) { badPathsStr += "\n "; badPathsStr += i; @@ -3705,14 +3703,14 @@ Path DerivationGoal::openLogFile() { return ""; } - string baseName = baseNameOf(drvPath); + std::string baseName = baseNameOf(drvPath); /* Create a log file. */ Path dir = fmt("%s/%s/%s/", worker.store.logDir, nix::LocalStore::drvsLogDir, - string(baseName, 0, 2)); + std::string(baseName, 0, 2)); createDirs(dir); - Path logFileName = fmt("%s/%s%s", dir, string(baseName, 2), + Path logFileName = fmt("%s/%s%s", dir, std::string(baseName, 2), settings.compressLog ? ".bz2" : ""); fdLogFile = @@ -3759,7 +3757,7 @@ void DerivationGoal::deleteTmpDir(bool force) { } } -void DerivationGoal::handleChildOutput(int fd, const string& data) { +void DerivationGoal::handleChildOutput(int fd, const std::string& data) { if ((hook && fd == hook->builderOut.readSide.get()) || (!hook && fd == builderOut.readSide.get())) { logSize += data.size(); @@ -3839,12 +3837,13 @@ PathSet DerivationGoal::checkPathValidity(bool returnValid, bool checkHash) { } Path DerivationGoal::addHashRewrite(const Path& path) { - string h1 = string(path, worker.store.storeDir.size() + 1, 32); - string h2 = string(hashString(htSHA256, "rewrite:" + drvPath + ":" + path) - .to_string(Base32, false), - 0, 32); + std::string h1 = std::string(path, worker.store.storeDir.size() + 1, 32); + std::string h2 = + std::string(hashString(htSHA256, "rewrite:" + drvPath + ":" + path) + .to_string(Base32, false), + 0, 32); Path p = worker.store.storeDir + "/" + h2 + - string(path, worker.store.storeDir.size() + 33); + std::string(path, worker.store.storeDir.size() + 33); deletePath(p); assert(path.size() == p.size()); inputRewrites[h1] = h2; @@ -3853,7 +3852,7 @@ Path DerivationGoal::addHashRewrite(const Path& path) { return p; } -void DerivationGoal::done(BuildResult::Status status, const string& msg) { +void DerivationGoal::done(BuildResult::Status status, const std::string& msg) { result.status = status; result.errorMsg = msg; amDone(result.success() ? ecSuccess : ecFailed); @@ -3928,7 +3927,7 @@ class SubstitutionGoal : public Goal { void timedOut() override { abort(); }; - string key() override { + std::string key() override { /* "a$" ensures substitution goals happen before derivation goals. */ return "a$" + storePathToName(storePath) + "$" + storePath; @@ -3945,7 +3944,7 @@ class SubstitutionGoal : public Goal { void finished(); /* Callback used by the worker to write to the log. */ - void handleChildOutput(int fd, const string& data) override; + void handleChildOutput(int fd, const std::string& data) override; void handleEOF(int fd) override; Path getStorePath() { return storePath; } @@ -4204,7 +4203,7 @@ void SubstitutionGoal::finished() { amDone(ecSuccess); } -void SubstitutionGoal::handleChildOutput(int fd, const string& data) {} +void SubstitutionGoal::handleChildOutput(int fd, const std::string& data) {} void SubstitutionGoal::handleEOF(int fd) { if (fd == outPipe.readSide.get()) { @@ -4321,7 +4320,7 @@ void Worker::wakeUp(const GoalPtr& goal) { unsigned Worker::getNrLocalBuilds() { return nrLocalBuilds; } -void Worker::childStarted(const GoalPtr& goal, const set<int>& fds, +void Worker::childStarted(const GoalPtr& goal, const std::set<int>& fds, bool inBuildSlot, bool respectTimeouts) { Child child; child.goal = goal; @@ -4545,7 +4544,7 @@ void Worker::waitForInput() { GoalPtr goal = j->goal.lock(); assert(goal); - set<int> fds2(j->fds); + std::set<int> fds2(j->fds); std::vector<unsigned char> buffer(4096); for (auto& k : fds2) { if (FD_ISSET(k, &fds)) { @@ -4562,7 +4561,7 @@ void Worker::waitForInput() { } } else { DLOG(INFO) << goal->getName() << ": read " << rd << " bytes"; - string data((char*)buffer.data(), rd); + std::string data((char*)buffer.data(), rd); j->lastOutput = after; goal->handleChildOutput(k, data); } diff --git a/third_party/nix/src/libstore/builtins/buildenv.cc b/third_party/nix/src/libstore/builtins/buildenv.cc index 77ad722fab15..d14474a93d7e 100644 --- a/third_party/nix/src/libstore/builtins/buildenv.cc +++ b/third_party/nix/src/libstore/builtins/buildenv.cc @@ -133,7 +133,7 @@ static void addPkg(const Path& pkgDir, int priority) { createLinks(pkgDir, out, priority); try { - for (const auto& p : tokenizeString<std::vector<string>>( + for (const auto& p : tokenizeString<std::vector<std::string>>( readFile(pkgDir + "/nix-support/propagated-user-env-packages"), " \n")) if (!done.count(p)) { @@ -157,7 +157,7 @@ struct Package { typedef std::vector<Package> Packages; void builtinBuildenv(const BasicDerivation& drv) { - auto getAttr = [&](const string& name) { + auto getAttr = [&](const std::string& name) { auto i = drv.env.find(name); if (i == drv.env.end()) { throw Error("attribute '%s' missing", name); diff --git a/third_party/nix/src/libstore/builtins/fetchurl.cc b/third_party/nix/src/libstore/builtins/fetchurl.cc index c3f38a943f57..97260d2e5229 100644 --- a/third_party/nix/src/libstore/builtins/fetchurl.cc +++ b/third_party/nix/src/libstore/builtins/fetchurl.cc @@ -17,7 +17,7 @@ void builtinFetchurl(const BasicDerivation& drv, const std::string& netrcData) { writeFile(settings.netrcFile, netrcData, 0600); } - auto getAttr = [&](const string& name) { + auto getAttr = [&](const std::string& name) { auto i = drv.env.find(name); if (i == drv.env.end()) throw Error(format("attribute '%s' missing") % name); diff --git a/third_party/nix/src/libstore/crypto.cc b/third_party/nix/src/libstore/crypto.cc index 90580b8dc902..eb5bb6670738 100644 --- a/third_party/nix/src/libstore/crypto.cc +++ b/third_party/nix/src/libstore/crypto.cc @@ -9,7 +9,7 @@ namespace nix { -static std::pair<std::string, std::string> split(const string& s) { +static std::pair<std::string, std::string> split(const std::string& s) { size_t colon = s.find(':'); if (colon == std::string::npos || colon == 0) { return {"", ""}; @@ -17,7 +17,7 @@ static std::pair<std::string, std::string> split(const string& s) { return {std::string(s, 0, colon), std::string(s, colon + 1)}; } -Key::Key(const string& s) { +Key::Key(const std::string& s) { auto ss = split(s); name = ss.first; @@ -30,7 +30,7 @@ Key::Key(const string& s) { key = base64Decode(key); } -SecretKey::SecretKey(const string& s) : Key(s) { +SecretKey::SecretKey(const std::string& s) : Key(s) { #if HAVE_SODIUM if (key.size() != crypto_sign_SECRETKEYBYTES) { throw Error("secret key is not valid"); @@ -68,7 +68,7 @@ PublicKey SecretKey::toPublicKey() const { #endif } -PublicKey::PublicKey(const string& s) : Key(s) { +PublicKey::PublicKey(const std::string& s) : Key(s) { #if HAVE_SODIUM if (key.size() != crypto_sign_PUBLICKEYBYTES) { throw Error("public key is not valid"); diff --git a/third_party/nix/src/libstore/derivations.cc b/third_party/nix/src/libstore/derivations.cc index 9c71d7209e37..f8770327bf9e 100644 --- a/third_party/nix/src/libstore/derivations.cc +++ b/third_party/nix/src/libstore/derivations.cc @@ -11,11 +11,11 @@ namespace nix { void DerivationOutput::parseHashInfo(bool& recursive, Hash& hash) const { recursive = false; - string algo = hashAlgo; + std::string algo = hashAlgo; - if (string(algo, 0, 2) == "r:") { + if (std::string(algo, 0, 2) == "r:") { recursive = true; - algo = string(algo, 2); + algo = std::string(algo, 2); } HashType hashType = parseHashType(algo); @@ -26,7 +26,7 @@ void DerivationOutput::parseHashInfo(bool& recursive, Hash& hash) const { hash = Hash(this->hash, hashType); } -Path BasicDerivation::findOutput(const string& id) const { +Path BasicDerivation::findOutput(const std::string& id) const { auto i = outputs.find(id); if (i == outputs.end()) { throw Error(format("derivation has no output '%1%'") % id); @@ -35,11 +35,11 @@ Path BasicDerivation::findOutput(const string& id) const { } bool BasicDerivation::isBuiltin() const { - return string(builder, 0, 8) == "builtin:"; + return std::string(builder, 0, 8) == "builtin:"; } Path writeDerivation(const ref<Store>& store, const Derivation& drv, - const string& name, RepairFlag repair) { + const std::string& name, RepairFlag repair) { PathSet references; references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end()); for (auto& i : drv.inputDrvs) { @@ -48,25 +48,25 @@ Path writeDerivation(const ref<Store>& store, const Derivation& drv, /* Note that the outputs of a derivation are *not* references (that can be missing (of course) and should not necessarily be held during a garbage collection). */ - string suffix = name + drvExtension; - string contents = drv.unparse(); + std::string suffix = name + drvExtension; + std::string contents = drv.unparse(); return settings.readOnlyMode ? store->computeStorePathForText(suffix, contents, references) : store->addTextToStore(suffix, contents, references, repair); } /* Read string `s' from stream `str'. */ -static void expect(std::istream& str, const string& s) { +static void expect(std::istream& str, const std::string& s) { char s2[s.size()]; str.read(s2, s.size()); - if (string(s2, s.size()) != s) { + if (std::string(s2, s.size()) != s) { throw FormatError(format("expected string '%1%'") % s); } } /* Read a C-style string from stream `str'. */ -static string parseString(std::istream& str) { - string res; +static std::string parseString(std::istream& str) { + std::string res; expect(str, "\""); int c; while ((c = str.get()) != '"') { @@ -89,7 +89,7 @@ static string parseString(std::istream& str) { } static Path parsePath(std::istream& str) { - string s = parseString(str); + std::string s = parseString(str); if (s.empty() || s[0] != '/') { throw FormatError(format("bad path '%1%' in derivation") % s); } @@ -116,7 +116,7 @@ static StringSet parseStrings(std::istream& str, bool arePaths) { return res; } -static Derivation parseDerivation(const string& s) { +static Derivation parseDerivation(const std::string& s) { Derivation drv; istringstream_nocopy str(s); expect(str, "Derive(["); @@ -125,7 +125,7 @@ static Derivation parseDerivation(const string& s) { while (!endOfList(str)) { DerivationOutput out; expect(str, "("); - string id = parseString(str); + std::string id = parseString(str); expect(str, ","); out.path = parsePath(str); expect(str, ","); @@ -163,9 +163,9 @@ static Derivation parseDerivation(const string& s) { expect(str, ",["); while (!endOfList(str)) { expect(str, "("); - string name = parseString(str); + std::string name = parseString(str); expect(str, ","); - string value = parseString(str); + std::string value = parseString(str); expect(str, ")"); drv.env[name] = value; } @@ -195,7 +195,7 @@ Derivation Store::derivationFromPath(const Path& drvPath) { } } -static void printString(string& res, const string& s) { +static void printString(std::string& res, const std::string& s) { res += '"'; for (const char* i = s.c_str(); *i != 0; i++) { if (*i == '\"' || *i == '\\') { @@ -215,7 +215,8 @@ static void printString(string& res, const string& s) { } template <class ForwardIterator> -static void printStrings(string& res, ForwardIterator i, ForwardIterator j) { +static void printStrings(std::string& res, ForwardIterator i, + ForwardIterator j) { res += '['; bool first = true; for (; i != j; ++i) { @@ -229,8 +230,8 @@ static void printStrings(string& res, ForwardIterator i, ForwardIterator j) { res += ']'; } -string Derivation::unparse() const { - string s; +std::string Derivation::unparse() const { + std::string s; s.reserve(65536); s += "Derive(["; @@ -297,7 +298,7 @@ string Derivation::unparse() const { return s; } -bool isDerivation(const string& fileName) { +bool isDerivation(const std::string& fileName) { return hasSuffix(fileName, drvExtension); } @@ -354,22 +355,23 @@ Hash hashDerivationModulo(Store& store, Derivation drv) { return hashString(htSHA256, drv.unparse()); } -DrvPathWithOutputs parseDrvPathWithOutputs(const string& s) { +DrvPathWithOutputs parseDrvPathWithOutputs(const std::string& s) { size_t n = s.find('!'); return n == std::string::npos - ? DrvPathWithOutputs(s, std::set<string>()) - : DrvPathWithOutputs( - string(s, 0, n), - tokenizeString<std::set<string> >(string(s, n + 1), ",")); + ? DrvPathWithOutputs(s, std::set<std::string>()) + : DrvPathWithOutputs(std::string(s, 0, n), + tokenizeString<std::set<std::string> >( + std::string(s, n + 1), ",")); } Path makeDrvPathWithOutputs(const Path& drvPath, - const std::set<string>& outputs) { + const std::set<std::string>& outputs) { return outputs.empty() ? drvPath : drvPath + "!" + concatStringsSep(",", outputs); } -bool wantOutput(const string& output, const std::set<string>& wanted) { +bool wantOutput(const std::string& output, + const std::set<std::string>& wanted) { return wanted.empty() || wanted.find(output) != wanted.end(); } diff --git a/third_party/nix/src/libstore/derivations.hh b/third_party/nix/src/libstore/derivations.hh index 52b951f5e9d9..ae365e68bf3a 100644 --- a/third_party/nix/src/libstore/derivations.hh +++ b/third_party/nix/src/libstore/derivations.hh @@ -9,16 +9,16 @@ namespace nix { /* Extension of derivations in the Nix store. */ -const string drvExtension = ".drv"; +const std::string drvExtension = ".drv"; /* Abstract syntax of derivations. */ struct DerivationOutput { Path path; - string hashAlgo; /* hash used for expected hash computation */ - string hash; /* expected hash, may be null */ + std::string hashAlgo; /* hash used for expected hash computation */ + std::string hash; /* expected hash, may be null */ DerivationOutput() {} - DerivationOutput(Path path, string hashAlgo, string hash) { + DerivationOutput(Path path, std::string hashAlgo, std::string hash) { this->path = path; this->hashAlgo = hashAlgo; this->hash = hash; @@ -26,18 +26,18 @@ struct DerivationOutput { void parseHashInfo(bool& recursive, Hash& hash) const; }; -typedef std::map<string, DerivationOutput> DerivationOutputs; +typedef std::map<std::string, DerivationOutput> DerivationOutputs; /* For inputs that are sub-derivations, we specify exactly which output IDs we are interested in. */ typedef std::map<Path, StringSet> DerivationInputs; -typedef std::map<string, string> StringPairs; +typedef std::map<std::string, std::string> StringPairs; struct BasicDerivation { DerivationOutputs outputs; /* keyed on symbolic IDs */ PathSet inputSrcs; /* inputs that are sources */ - string platform; + std::string platform; Path builder; Strings args; StringPairs env; @@ -46,7 +46,7 @@ struct BasicDerivation { /* Return the path corresponding to the output identifier `id' in the given derivation. */ - Path findOutput(const string& id) const; + Path findOutput(const std::string& id) const; bool isBuiltin() const; @@ -68,14 +68,14 @@ class Store; /* Write a derivation to the Nix store, and return its path. */ Path writeDerivation(const ref<Store>& store, const Derivation& drv, - const string& name, RepairFlag repair = NoRepair); + const std::string& name, RepairFlag repair = NoRepair); /* Read a derivation from a file. */ Derivation readDerivation(const Path& drvPath); /* Check whether a file name ends with the extension for derivations. */ -bool isDerivation(const string& fileName); +bool isDerivation(const std::string& fileName); Hash hashDerivationModulo(Store& store, Derivation drv); @@ -87,13 +87,13 @@ extern DrvHashes drvHashes; // FIXME: global, not thread-safe /* Split a string specifying a derivation and a set of outputs (/nix/store/hash-foo!out1,out2,...) into the derivation path and the outputs. */ -typedef std::pair<string, std::set<string> > DrvPathWithOutputs; -DrvPathWithOutputs parseDrvPathWithOutputs(const string& s); +typedef std::pair<std::string, std::set<std::string> > DrvPathWithOutputs; +DrvPathWithOutputs parseDrvPathWithOutputs(const std::string& s); Path makeDrvPathWithOutputs(const Path& drvPath, - const std::set<string>& outputs); + const std::set<std::string>& outputs); -bool wantOutput(const string& output, const std::set<string>& wanted); +bool wantOutput(const std::string& output, const std::set<std::string>& wanted); struct Source; struct Sink; diff --git a/third_party/nix/src/libstore/download.cc b/third_party/nix/src/libstore/download.cc index 876734478785..c96caf474c0d 100644 --- a/third_party/nix/src/libstore/download.cc +++ b/third_party/nix/src/libstore/download.cc @@ -177,7 +177,7 @@ struct CurlDownloader : public Downloader { DLOG(INFO) << "got header for '" << request.uri << "': " << trim(line); if (line.compare(0, 5, "HTTP/") == 0) { // new response starts result.etag = ""; - auto ss = tokenizeString<vector<string>>(line, " "); + auto ss = tokenizeString<std::vector<std::string>>(line, " "); status = ss.size() >= 2 ? ss[1] : ""; result.data = std::make_shared<std::string>(); result.bodySize = 0; @@ -185,10 +185,10 @@ struct CurlDownloader : public Downloader { encoding = ""; } else { auto i = line.find(':'); - if (i != string::npos) { - string name = toLower(trim(string(line, 0, i))); + if (i != std::string::npos) { + std::string name = toLower(trim(std::string(line, 0, i))); if (name == "etag") { - result.etag = trim(string(line, i + 1)); + result.etag = trim(std::string(line, i + 1)); /* Hack to work around a GitHub bug: it sends ETags, but ignores If-None-Match. So if we get the expected ETag on a 200 response, then shut @@ -200,7 +200,7 @@ struct CurlDownloader : public Downloader { return 0; } } else if (name == "content-encoding") { - encoding = trim(string(line, i + 1)); + encoding = trim(std::string(line, i + 1)); } else if (name == "accept-ranges" && toLower(trim(std::string(line, i + 1))) == "bytes") { acceptRanges = true; @@ -868,8 +868,8 @@ CachedDownloadResult Downloader::downloadCached( auto name = request.name; if (name.empty()) { auto p = url.rfind('/'); - if (p != string::npos) { - name = string(url, p + 1); + if (p != std::string::npos) { + name = std::string(url, p + 1); } } @@ -888,8 +888,8 @@ CachedDownloadResult Downloader::downloadCached( Path cacheDir = getCacheDir() + "/nix/tarballs"; createDirs(cacheDir); - string urlHash = hashString(htSHA256, name + std::string("\0"s) + url) - .to_string(Base32, false); + std::string urlHash = hashString(htSHA256, name + std::string("\0"s) + url) + .to_string(Base32, false); Path dataFile = cacheDir + "/" + urlHash + ".info"; Path fileLink = cacheDir + "/" + urlHash + "-file"; @@ -898,7 +898,7 @@ CachedDownloadResult Downloader::downloadCached( Path storePath; - string expectedETag; + std::string expectedETag; bool skip = false; @@ -908,7 +908,8 @@ CachedDownloadResult Downloader::downloadCached( storePath = readLink(fileLink); store->addTempRoot(storePath); if (store->isValidPath(storePath)) { - auto ss = tokenizeString<vector<string>>(readFile(dataFile), "\n"); + auto ss = + tokenizeString<std::vector<std::string>>(readFile(dataFile), "\n"); if (ss.size() >= 3 && ss[0] == url) { time_t lastChecked; if (string2Int(ss[2], lastChecked) && @@ -1009,15 +1010,15 @@ CachedDownloadResult Downloader::downloadCached( return result; } -bool isUri(const string& s) { +bool isUri(const std::string& s) { if (s.compare(0, 8, "channel:") == 0) { return true; } size_t pos = s.find("://"); - if (pos == string::npos) { + if (pos == std::string::npos) { return false; } - string scheme(s, 0, pos); + std::string scheme(s, 0, pos); return scheme == "http" || scheme == "https" || scheme == "file" || scheme == "channel" || scheme == "git" || scheme == "s3" || scheme == "ssh"; diff --git a/third_party/nix/src/libstore/download.hh b/third_party/nix/src/libstore/download.hh index 9ddbdfc15955..a988ec682669 100644 --- a/third_party/nix/src/libstore/download.hh +++ b/third_party/nix/src/libstore/download.hh @@ -128,6 +128,6 @@ class DownloadError : public Error { : Error(fs), error(error) {} }; -bool isUri(const string& s); +bool isUri(const std::string& s); } // namespace nix diff --git a/third_party/nix/src/libstore/gc.cc b/third_party/nix/src/libstore/gc.cc index bc3393265e48..1b2364c25383 100644 --- a/third_party/nix/src/libstore/gc.cc +++ b/third_party/nix/src/libstore/gc.cc @@ -20,8 +20,8 @@ namespace nix { -static string gcLockName = "gc.lock"; -static string gcRootsDir = "gcroots"; +static std::string gcLockName = "gc.lock"; +static std::string gcRootsDir = "gcroots"; /* Acquire the global GC lock. This is used to prevent new Nix processes from starting after the temporary root files have been @@ -69,7 +69,7 @@ static void makeSymlink(const Path& link, const Path& target) { void LocalStore::syncWithGC() { AutoCloseFD fdGCLock = openGCLock(ltRead); } void LocalStore::addIndirectRoot(const Path& path) { - string hash = hashString(htSHA1, path).to_string(Base32, false); + std::string hash = hashString(htSHA1, path).to_string(Base32, false); Path realRoot = canonPath( (format("%1%/%2%/auto/%3%") % stateDir % gcRootsDir % hash).str()); makeSymlink(realRoot, path); @@ -105,7 +105,7 @@ Path LocalFSStore::addPermRoot(const Path& _storePath, const Path& _gcRoot, Path rootsDir = canonPath((format("%1%/%2%") % stateDir % gcRootsDir).str()); - if (string(gcRoot, 0, rootsDir.size() + 1) != rootsDir + "/") { + if (std::string(gcRoot, 0, rootsDir.size() + 1) != rootsDir + "/") { throw Error(format("path '%1%' is not a valid garbage collector root; " "it's not in the directory '%2%'") % gcRoot % rootsDir); @@ -184,7 +184,7 @@ void LocalStore::addTempRoot(const Path& path) { DLOG(INFO) << "acquiring write lock on " << fnTempRoots; lockFile(state->fdTempRoots.get(), ltWrite, true); - string s = path + '\0'; + std::string s = path + '\0'; writeFull(state->fdTempRoots.get(), s); /* Downgrade to a read lock. */ @@ -233,13 +233,13 @@ void LocalStore::findTempRoots(FDs& fds, Roots& tempRoots, bool censor) { lockFile(fd->get(), ltRead, true); /* Read the entire file. */ - string contents = readFile(fd->get()); + std::string contents = readFile(fd->get()); /* Extract the roots. */ - string::size_type pos = 0; - string::size_type end; + std::string::size_type pos = 0; + std::string::size_type end; - while ((end = contents.find((char)0, pos)) != string::npos) { + while ((end = contents.find((char)0, pos)) != std::string::npos) { Path root(contents, pos, end - pos); DLOG(INFO) << "got temporary root " << root; assertStorePath(root); @@ -341,7 +341,7 @@ Roots LocalStore::findRoots(bool censor) { return roots; } -static void readProcLink(const string& file, Roots& roots) { +static void readProcLink(const std::string& file, Roots& roots) { /* 64 is the starting buffer size gnu readlink uses... */ auto bufsiz = ssize_t{64}; try_again: @@ -365,7 +365,7 @@ try_again: } } -static string quoteRegexChars(const string& raw) { +static std::string quoteRegexChars(const std::string& raw) { static auto specialRegex = std::regex(R"([.^$\\*+?()\[\]{}|])"); return std::regex_replace(raw, specialRegex, R"(\$&)"); } @@ -421,7 +421,7 @@ void LocalStore::findRuntimeRoots(Roots& roots, bool censor) { try { auto mapFile = fmt("/proc/%s/maps", ent->d_name); - auto mapLines = tokenizeString<std::vector<string>>( + auto mapLines = tokenizeString<std::vector<std::string>>( readFile(mapFile, true), "\n"); for (const auto& line : mapLines) { auto match = std::smatch{}; @@ -458,7 +458,7 @@ void LocalStore::findRuntimeRoots(Roots& roots, bool censor) { if (getEnv("_NIX_TEST_NO_LSOF") == "") { try { std::regex lsofRegex(R"(^n(/.*)$)"); - auto lsofLines = tokenizeString<std::vector<string>>( + auto lsofLines = tokenizeString<std::vector<std::string>>( runProgram(LSOF, true, {"-n", "-w", "-F", "n"}), "\n"); for (const auto& line : lsofLines) { std::smatch match; @@ -511,10 +511,10 @@ struct LocalStore::GCState { }; bool LocalStore::isActiveTempFile(const GCState& state, const Path& path, - const string& suffix) { + const std::string& suffix) { return hasSuffix(path, suffix) && - state.tempRoots.find(string(path, 0, path.size() - suffix.size())) != - state.tempRoots.end(); + state.tempRoots.find(std::string( + path, 0, path.size() - suffix.size())) != state.tempRoots.end(); } void LocalStore::deleteGarbage(GCState& state, const Path& path) { @@ -720,7 +720,7 @@ void LocalStore::removeUnusedLinks(const GCState& state) { struct dirent* dirent; while (errno = 0, dirent = readdir(dir.get())) { checkInterrupt(); - string name = dirent->d_name; + std::string name = dirent->d_name; if (name == "." || name == "..") { continue; } @@ -863,7 +863,7 @@ void LocalStore::collectGarbage(const GCOptions& options, GCResults& results) { struct dirent* dirent; while (errno = 0, dirent = readdir(dir.get())) { checkInterrupt(); - string name = dirent->d_name; + std::string name = dirent->d_name; if (name == "." || name == "..") { continue; } @@ -882,7 +882,7 @@ void LocalStore::collectGarbage(const GCOptions& options, GCResults& results) { less biased towards deleting paths that come alphabetically first (e.g. /nix/store/000...). This matters when using --max-freed etc. */ - vector<Path> entries_(entries.begin(), entries.end()); + std::vector<Path> entries_(entries.begin(), entries.end()); std::mt19937 gen(1); std::shuffle(entries_.begin(), entries_.end(), gen); diff --git a/third_party/nix/src/libstore/globals.cc b/third_party/nix/src/libstore/globals.cc index 856b858368ef..61293dffed50 100644 --- a/third_party/nix/src/libstore/globals.cc +++ b/third_party/nix/src/libstore/globals.cc @@ -105,7 +105,7 @@ StringSet Settings::getDefaultSystemFeatures() { return features; } -const string nixVersion = PACKAGE_VERSION; +const std::string nixVersion = PACKAGE_VERSION; template <> void BaseSetting<SandboxMode>::set(const std::string& str) { diff --git a/third_party/nix/src/libstore/globals.hh b/third_party/nix/src/libstore/globals.hh index 71bc2b1e7407..feff54879070 100644 --- a/third_party/nix/src/libstore/globals.hh +++ b/third_party/nix/src/libstore/globals.hh @@ -468,6 +468,6 @@ void initPlugins(); void loadConfFile(); -extern const string nixVersion; +extern const std::string nixVersion; } // namespace nix diff --git a/third_party/nix/src/libstore/http-binary-cache-store.cc b/third_party/nix/src/libstore/http-binary-cache-store.cc index 1a46423b3542..c75d5f2860a7 100644 --- a/third_party/nix/src/libstore/http-binary-cache-store.cc +++ b/third_party/nix/src/libstore/http-binary-cache-store.cc @@ -94,7 +94,7 @@ class HttpBinaryCacheStore : public BinaryCacheStore { void upsertFile(const std::string& path, const std::string& data, const std::string& mimeType) override { auto req = DownloadRequest(cacheUri + "/" + path); - req.data = std::make_shared<string>(data); // FIXME: inefficient + req.data = std::make_shared<std::string>(data); // FIXME: inefficient req.mimeType = mimeType; try { getDownloader()->download(req); diff --git a/third_party/nix/src/libstore/legacy-ssh-store.cc b/third_party/nix/src/libstore/legacy-ssh-store.cc index 9a84e0295657..9e6870f0da6b 100644 --- a/third_party/nix/src/libstore/legacy-ssh-store.cc +++ b/third_party/nix/src/libstore/legacy-ssh-store.cc @@ -43,7 +43,7 @@ struct LegacySSHStore : public Store { SSHMaster master; - LegacySSHStore(const string& host, const Params& params) + LegacySSHStore(const std::string& host, const Params& params) : Store(params), host(host), connections(make_ref<Pool<Connection>>( @@ -85,7 +85,7 @@ struct LegacySSHStore : public Store { return conn; }; - string getUri() override { return uriScheme + host; } + std::string getUri() override { return uriScheme + host; } void queryPathInfoUncached( const Path& path, @@ -176,17 +176,17 @@ struct LegacySSHStore : public Store { copyNAR(conn->from, sink); } - Path queryPathFromHashPart(const string& hashPart) override { + Path queryPathFromHashPart(const std::string& hashPart) override { unsupported("queryPathFromHashPart"); } - Path addToStore(const string& name, const Path& srcPath, bool recursive, + Path addToStore(const std::string& name, const Path& srcPath, bool recursive, HashType hashAlgo, PathFilter& filter, RepairFlag repair) override { unsupported("addToStore"); } - Path addTextToStore(const string& name, const string& s, + Path addTextToStore(const std::string& name, const std::string& s, const PathSet& references, RepairFlag repair) override { unsupported("addTextToStore"); } diff --git a/third_party/nix/src/libstore/local-fs-store.cc b/third_party/nix/src/libstore/local-fs-store.cc index 2120afc0ce7c..f11c84b182a6 100644 --- a/third_party/nix/src/libstore/local-fs-store.cc +++ b/third_party/nix/src/libstore/local-fs-store.cc @@ -79,7 +79,7 @@ void LocalFSStore::narFromPath(const Path& path, Sink& sink) { dumpPath(getRealStoreDir() + std::string(path, storeDir.size()), sink); } -const string LocalFSStore::drvsLogDir = "drvs"; +const std::string LocalFSStore::drvsLogDir = "drvs"; std::shared_ptr<std::string> LocalFSStore::getBuildLog(const Path& path_) { auto path(path_); @@ -97,12 +97,13 @@ std::shared_ptr<std::string> LocalFSStore::getBuildLog(const Path& path_) { } } - string baseName = baseNameOf(path); + std::string baseName = baseNameOf(path); for (int j = 0; j < 2; j++) { - Path logPath = j == 0 ? fmt("%s/%s/%s/%s", logDir, drvsLogDir, - string(baseName, 0, 2), string(baseName, 2)) - : fmt("%s/%s/%s", logDir, drvsLogDir, baseName); + Path logPath = + j == 0 ? fmt("%s/%s/%s/%s", logDir, drvsLogDir, + std::string(baseName, 0, 2), std::string(baseName, 2)) + : fmt("%s/%s/%s", logDir, drvsLogDir, baseName); Path logBz2Path = logPath + ".bz2"; if (pathExists(logPath)) { diff --git a/third_party/nix/src/libstore/local-store.cc b/third_party/nix/src/libstore/local-store.cc index a89c6a79757d..84055740de2c 100644 --- a/third_party/nix/src/libstore/local-store.cc +++ b/third_party/nix/src/libstore/local-store.cc @@ -10,10 +10,16 @@ #include <fcntl.h> #include <glog/logging.h> #include <grp.h> +#include <sched.h> +#include <sqlite3.h> +#include <sys/ioctl.h> +#include <sys/mount.h> #include <sys/select.h> #include <sys/stat.h> +#include <sys/statvfs.h> #include <sys/time.h> #include <sys/types.h> +#include <sys/xattr.h> #include <unistd.h> #include <utime.h> @@ -24,13 +30,6 @@ #include "pathlocks.hh" #include "worker-protocol.hh" -#include <sched.h> -#include <sys/ioctl.h> -#include <sys/mount.h> -#include <sys/statvfs.h> -#include <sys/xattr.h> -#include <sqlite3.h> - namespace nix { LocalStore::LocalStore(const Params& params) @@ -136,7 +135,7 @@ LocalStore::LocalStore(const Params& params) res = posix_fallocate(fd.get(), 0, settings.reservedSize); #endif if (res == -1) { - writeFull(fd.get(), string(settings.reservedSize, 'X')); + writeFull(fd.get(), std::string(settings.reservedSize, 'X')); [[gnu::unused]] auto res2 = ftruncate(fd.get(), settings.reservedSize); } } @@ -295,7 +294,7 @@ std::string LocalStore::getUri() { return "local"; } int LocalStore::getSchema() { int curSchema = 0; if (pathExists(schemaPath)) { - string s = readFile(schemaPath); + std::string s = readFile(schemaPath); if (!string2Int(s, curSchema)) { throw Error(format("'%1%' is corrupt") % schemaPath); } @@ -310,7 +309,7 @@ void LocalStore::openDB(State& state, bool create) { } /* Open the Nix database. */ - string dbPath = dbDir + "/db.sqlite"; + std::string dbPath = dbDir + "/db.sqlite"; auto& db(state.db); if (sqlite3_open_v2(dbPath.c_str(), &db.db, SQLITE_OPEN_READWRITE | (create ? SQLITE_OPEN_CREATE : 0), @@ -341,20 +340,20 @@ void LocalStore::openDB(State& state, bool create) { should be safe enough. If the user asks for it, don't sync at all. This can cause database corruption if the system crashes. */ - string syncMode = settings.fsyncMetadata ? "normal" : "off"; + std::string syncMode = settings.fsyncMetadata ? "normal" : "off"; db.exec("pragma synchronous = " + syncMode); /* Set the SQLite journal mode. WAL mode is fastest, so it's the default. */ - string mode = settings.useSQLiteWAL ? "wal" : "truncate"; - string prevMode; + std::string mode = settings.useSQLiteWAL ? "wal" : "truncate"; + std::string prevMode; { SQLiteStmt stmt; stmt.create(db, "pragma main.journal_mode;"); if (sqlite3_step(stmt) != SQLITE_ROW) { throwSQLiteError(db, "querying journal mode"); } - prevMode = string((const char*)sqlite3_column_text(stmt, 0)); + prevMode = std::string((const char*)sqlite3_column_text(stmt, 0)); } if (prevMode != mode && sqlite3_exec(db, ("pragma main.journal_mode = " + mode + ";").c_str(), @@ -563,9 +562,9 @@ void canonicalisePathMetaData(const Path& path, uid_t fromUid) { void LocalStore::checkDerivationOutputs(const Path& drvPath, const Derivation& drv) { - string drvName = storePathToName(drvPath); + std::string drvName = storePathToName(drvPath); assert(isDerivation(drvName)); - drvName = string(drvName, 0, drvName.size() - drvExtension.size()); + drvName = std::string(drvName, 0, drvName.size() - drvExtension.size()); if (drv.isFixedOutput()) { auto out = drv.outputs.find("out"); @@ -843,7 +842,7 @@ StringSet LocalStore::queryDerivationOutputNames(const Path& path) { }); } -Path LocalStore::queryPathFromHashPart(const string& hashPart) { +Path LocalStore::queryPathFromHashPart(const std::string& hashPart) { if (hashPart.size() != storePathHashLen) { throw Error("invalid hash part"); } @@ -1096,9 +1095,9 @@ void LocalStore::addToStore(const ValidPathInfo& info, Source& source, } } -Path LocalStore::addToStoreFromDump(const string& dump, const string& name, - bool recursive, HashType hashAlgo, - RepairFlag repair) { +Path LocalStore::addToStoreFromDump(const std::string& dump, + const std::string& name, bool recursive, + HashType hashAlgo, RepairFlag repair) { Hash h = hashString(hashAlgo, dump); Path dstPath = makeFixedOutputPath(recursive, h, name); @@ -1155,7 +1154,7 @@ Path LocalStore::addToStoreFromDump(const string& dump, const string& name, return dstPath; } -Path LocalStore::addToStore(const string& name, const Path& _srcPath, +Path LocalStore::addToStore(const std::string& name, const Path& _srcPath, bool recursive, HashType hashAlgo, PathFilter& filter, RepairFlag repair) { Path srcPath(absPath(_srcPath)); @@ -1173,7 +1172,7 @@ Path LocalStore::addToStore(const string& name, const Path& _srcPath, return addToStoreFromDump(*sink.s, name, recursive, hashAlgo, repair); } -Path LocalStore::addTextToStore(const string& name, const string& s, +Path LocalStore::addTextToStore(const std::string& name, const std::string& s, const PathSet& references, RepairFlag repair) { auto hash = hashString(htSHA256, s); auto dstPath = makeTextPath(name, hash, references); diff --git a/third_party/nix/src/libstore/local-store.hh b/third_party/nix/src/libstore/local-store.hh index 1a58df81613b..c1bfc0876412 100644 --- a/third_party/nix/src/libstore/local-store.hh +++ b/third_party/nix/src/libstore/local-store.hh @@ -125,7 +125,7 @@ class LocalStore : public LocalFSStore { StringSet queryDerivationOutputNames(const Path& path) override; - Path queryPathFromHashPart(const string& hashPart) override; + Path queryPathFromHashPart(const std::string& hashPart) override; PathSet querySubstitutablePaths(const PathSet& paths) override; @@ -136,7 +136,7 @@ class LocalStore : public LocalFSStore { CheckSigsFlag checkSigs, std::shared_ptr<FSAccessor> accessor) override; - Path addToStore(const string& name, const Path& srcPath, bool recursive, + Path addToStore(const std::string& name, const Path& srcPath, bool recursive, HashType hashAlgo, PathFilter& filter, RepairFlag repair) override; @@ -144,11 +144,11 @@ class LocalStore : public LocalFSStore { in `dump', which is either a NAR serialisation (if recursive == true) or simply the contents of a regular file (if recursive == false). */ - Path addToStoreFromDump(const string& dump, const string& name, + Path addToStoreFromDump(const std::string& dump, const std::string& name, bool recursive = true, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair); - Path addTextToStore(const string& name, const string& s, + Path addTextToStore(const std::string& name, const std::string& s, const PathSet& references, RepairFlag repair) override; void buildPaths(const PathSet& paths, BuildMode buildMode) override; @@ -166,7 +166,7 @@ class LocalStore : public LocalFSStore { private: typedef std::shared_ptr<AutoCloseFD> FDPtr; - typedef list<FDPtr> FDs; + typedef std::list<FDPtr> FDs; void findTempRoots(FDs& fds, Roots& roots, bool censor); @@ -248,7 +248,7 @@ class LocalStore : public LocalFSStore { void deletePathRecursive(GCState& state, const Path& path); static bool isActiveTempFile(const GCState& state, const Path& path, - const string& suffix); + const std::string& suffix); AutoCloseFD openGCLock(LockType lockType); @@ -290,7 +290,7 @@ class LocalStore : public LocalFSStore { }; typedef std::pair<dev_t, ino_t> Inode; -typedef set<Inode> InodesSeen; +typedef std::set<Inode> InodesSeen; /* "Fix", or canonicalise, the meta-data of the files in a store path after it has been built. In particular: diff --git a/third_party/nix/src/libstore/machines.cc b/third_party/nix/src/libstore/machines.cc index 5b0c7e72ddba..2f1a7289bd84 100644 --- a/third_party/nix/src/libstore/machines.cc +++ b/third_party/nix/src/libstore/machines.cc @@ -32,22 +32,22 @@ Machine::Machine(decltype(storeUri)& storeUri, mandatoryFeatures(mandatoryFeatures), sshPublicHostKey(sshPublicHostKey) {} -bool Machine::allSupported(const std::set<string>& features) const { +bool Machine::allSupported(const std::set<std::string>& features) const { return std::all_of(features.begin(), features.end(), - [&](const string& feature) { + [&](const std::string& feature) { return (supportedFeatures.count(feature) != 0u) || (mandatoryFeatures.count(feature) != 0u); }); } -bool Machine::mandatoryMet(const std::set<string>& features) const { +bool Machine::mandatoryMet(const std::set<std::string>& features) const { return std::all_of( mandatoryFeatures.begin(), mandatoryFeatures.end(), - [&](const string& feature) { return features.count(feature); }); + [&](const std::string& feature) { return features.count(feature); }); } void parseMachines(const std::string& s, Machines& machines) { - for (auto line : tokenizeString<std::vector<string>>(s, "\n;")) { + for (auto line : tokenizeString<std::vector<std::string>>(s, "\n;")) { trim(line); line.erase(std::find(line.begin(), line.end(), '#'), line.end()); if (line.empty()) { @@ -67,7 +67,7 @@ void parseMachines(const std::string& s, Machines& machines) { continue; } - auto tokens = tokenizeString<std::vector<string>>(line); + auto tokens = tokenizeString<std::vector<std::string>>(line); auto sz = tokens.size(); if (sz < 1) { throw FormatError("bad machine specification '%s'", line); @@ -79,14 +79,14 @@ void parseMachines(const std::string& s, Machines& machines) { machines.emplace_back( tokens[0], - isSet(1) ? tokenizeString<std::vector<string>>(tokens[1], ",") - : std::vector<string>{settings.thisSystem}, + isSet(1) ? tokenizeString<std::vector<std::string>>(tokens[1], ",") + : std::vector<std::string>{settings.thisSystem}, isSet(2) ? tokens[2] : "", isSet(3) ? std::stoull(tokens[3]) : 1LL, isSet(4) ? std::stoull(tokens[4]) : 1LL, - isSet(5) ? tokenizeString<std::set<string>>(tokens[5], ",") - : std::set<string>{}, - isSet(6) ? tokenizeString<std::set<string>>(tokens[6], ",") - : std::set<string>{}, + isSet(5) ? tokenizeString<std::set<std::string>>(tokens[5], ",") + : std::set<std::string>{}, + isSet(6) ? tokenizeString<std::set<std::string>>(tokens[6], ",") + : std::set<std::string>{}, isSet(7) ? tokens[7] : ""); } } diff --git a/third_party/nix/src/libstore/machines.hh b/third_party/nix/src/libstore/machines.hh index aef8054c250e..23712e676056 100644 --- a/third_party/nix/src/libstore/machines.hh +++ b/third_party/nix/src/libstore/machines.hh @@ -5,19 +5,19 @@ namespace nix { struct Machine { - const string storeUri; - const std::vector<string> systemTypes; - const string sshKey; + const std::string storeUri; + const std::vector<std::string> systemTypes; + const std::string sshKey; const unsigned int maxJobs; const unsigned int speedFactor; - const std::set<string> supportedFeatures; - const std::set<string> mandatoryFeatures; + const std::set<std::string> supportedFeatures; + const std::set<std::string> mandatoryFeatures; const std::string sshPublicHostKey; bool enabled = true; - bool allSupported(const std::set<string>& features) const; + bool allSupported(const std::set<std::string>& features) const; - bool mandatoryMet(const std::set<string>& features) const; + bool mandatoryMet(const std::set<std::string>& features) const; Machine(decltype(storeUri)& storeUri, decltype(systemTypes)& systemTypes, decltype(sshKey)& sshKey, decltype(maxJobs) maxJobs, diff --git a/third_party/nix/src/libstore/nar-accessor.cc b/third_party/nix/src/libstore/nar-accessor.cc index 7f6e0377aed4..84bfb531ecd6 100644 --- a/third_party/nix/src/libstore/nar-accessor.cc +++ b/third_party/nix/src/libstore/nar-accessor.cc @@ -74,7 +74,7 @@ struct NarAccessor : public FSAccessor { void isExecutable() override { parents.top()->isExecutable = true; } void preallocateContents(unsigned long long size) override { - currentStart = string(s, pos, 16); + currentStart = std::string(s, pos, 16); assert(size <= std::numeric_limits<size_t>::max()); parents.top()->size = (size_t)size; parents.top()->start = pos; @@ -83,12 +83,12 @@ struct NarAccessor : public FSAccessor { void receiveContents(unsigned char* data, unsigned int len) override { // Sanity check if (!currentStart.empty()) { - assert(len < 16 || currentStart == string((char*)data, 16)); + assert(len < 16 || currentStart == std::string((char*)data, 16)); currentStart.clear(); } } - void createSymlink(const Path& path, const string& target) override { + void createSymlink(const Path& path, const std::string& target) override { createMember(path, NarMember{FSAccessor::Type::tSymlink, false, 0, 0, target}); } diff --git a/third_party/nix/src/libstore/nar-info.cc b/third_party/nix/src/libstore/nar-info.cc index 91cf471554f3..5a217d1b617d 100644 --- a/third_party/nix/src/libstore/nar-info.cc +++ b/third_party/nix/src/libstore/nar-info.cc @@ -10,7 +10,7 @@ NarInfo::NarInfo(const Store& store, const std::string& s, throw Error(format("NAR info file '%1%' is corrupt") % whence); }; - auto parseHashField = [&](const string& s) { + auto parseHashField = [&](const std::string& s) { try { return Hash(s); } catch (BadHash&) { diff --git a/third_party/nix/src/libstore/optimise-store.cc b/third_party/nix/src/libstore/optimise-store.cc index caeff72363a4..7217d54ca9af 100644 --- a/third_party/nix/src/libstore/optimise-store.cc +++ b/third_party/nix/src/libstore/optimise-store.cc @@ -83,7 +83,7 @@ Strings LocalStore::readDirectoryIgnoringInodes(const Path& path, continue; } - string name = dirent->d_name; + std::string name = dirent->d_name; if (name == "." || name == "..") { continue; } @@ -271,7 +271,7 @@ void LocalStore::optimiseStore(OptimiseStats& stats) { } } -static string showBytes(unsigned long long bytes) { +static std::string showBytes(unsigned long long bytes) { return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str(); } diff --git a/third_party/nix/src/libstore/pathlocks.cc b/third_party/nix/src/libstore/pathlocks.cc index eeee5ee1e9c9..642e64a62bac 100644 --- a/third_party/nix/src/libstore/pathlocks.cc +++ b/third_party/nix/src/libstore/pathlocks.cc @@ -73,12 +73,12 @@ bool lockFile(int fd, LockType lockType, bool wait) { PathLocks::PathLocks() : deletePaths(false) {} -PathLocks::PathLocks(const PathSet& paths, const string& waitMsg) +PathLocks::PathLocks(const PathSet& paths, const std::string& waitMsg) : deletePaths(false) { lockPaths(paths, waitMsg); } -bool PathLocks::lockPaths(const PathSet& paths, const string& waitMsg, +bool PathLocks::lockPaths(const PathSet& paths, const std::string& waitMsg, bool wait) { assert(fds.empty()); diff --git a/third_party/nix/src/libstore/pathlocks.hh b/third_party/nix/src/libstore/pathlocks.hh index 90184989cde3..201e3f01b4df 100644 --- a/third_party/nix/src/libstore/pathlocks.hh +++ b/third_party/nix/src/libstore/pathlocks.hh @@ -19,13 +19,13 @@ bool lockFile(int fd, LockType lockType, bool wait); class PathLocks { private: typedef std::pair<int, Path> FDPair; - list<FDPair> fds; + std::list<FDPair> fds; bool deletePaths; public: PathLocks(); - PathLocks(const PathSet& paths, const string& waitMsg = ""); - bool lockPaths(const PathSet& _paths, const string& waitMsg = "", + PathLocks(const PathSet& paths, const std::string& waitMsg = ""); + bool lockPaths(const PathSet& _paths, const std::string& waitMsg = "", bool wait = true); ~PathLocks(); void unlock(); diff --git a/third_party/nix/src/libstore/profiles.cc b/third_party/nix/src/libstore/profiles.cc index bdb90b7388f7..7c802d754935 100644 --- a/third_party/nix/src/libstore/profiles.cc +++ b/third_party/nix/src/libstore/profiles.cc @@ -19,17 +19,17 @@ static bool cmpGensByNumber(const Generation& a, const Generation& b) { /* Parse a generation name of the format `<profilename>-<number>-link'. */ -static int parseName(const string& profileName, const string& name) { - if (string(name, 0, profileName.size() + 1) != profileName + "-") { +static int parseName(const std::string& profileName, const std::string& name) { + if (std::string(name, 0, profileName.size() + 1) != profileName + "-") { return -1; } - string s = string(name, profileName.size() + 1); - string::size_type p = s.find("-link"); - if (p == string::npos) { + std::string s = std::string(name, profileName.size() + 1); + std::string::size_type p = s.find("-link"); + if (p == std::string::npos) { return -1; } int n; - if (string2Int(string(s, 0, p), n) && n >= 0) { + if (string2Int(std::string(s, 0, p), n) && n >= 0) { return n; } return -1; @@ -39,7 +39,7 @@ Generations findGenerations(const Path& profile, int& curGen) { Generations gens; Path profileDir = dirOf(profile); - string profileName = baseNameOf(profile); + std::string profileName = baseNameOf(profile); for (auto& i : readDirectory(profileDir)) { int n; @@ -212,10 +212,10 @@ void deleteGenerationsOlderThan(const Path& profile, time_t t, bool dryRun) { } } -void deleteGenerationsOlderThan(const Path& profile, const string& timeSpec, - bool dryRun) { +void deleteGenerationsOlderThan(const Path& profile, + const std::string& timeSpec, bool dryRun) { time_t curTime = time(nullptr); - string strDays = string(timeSpec, 0, timeSpec.size() - 1); + std::string strDays = std::string(timeSpec, 0, timeSpec.size() - 1); int days; if (!string2Int(strDays, days) || days < 1) { @@ -242,7 +242,7 @@ void lockProfile(PathLocks& lock, const Path& profile) { lock.setDeletion(true); } -string optimisticLockProfile(const Path& profile) { +std::string optimisticLockProfile(const Path& profile) { return pathExists(profile) ? readLink(profile) : ""; } diff --git a/third_party/nix/src/libstore/profiles.hh b/third_party/nix/src/libstore/profiles.hh index ab31cc993af5..9f31083b32ee 100644 --- a/third_party/nix/src/libstore/profiles.hh +++ b/third_party/nix/src/libstore/profiles.hh @@ -15,7 +15,7 @@ struct Generation { operator bool() const { return number != -1; } }; -typedef list<Generation> Generations; +typedef std::list<Generation> Generations; /* Returns the list of currently present generations for the specified profile, sorted by generation number. */ @@ -38,8 +38,8 @@ void deleteOldGenerations(const Path& profile, bool dryRun); void deleteGenerationsOlderThan(const Path& profile, time_t t, bool dryRun); -void deleteGenerationsOlderThan(const Path& profile, const string& timeSpec, - bool dryRun); +void deleteGenerationsOlderThan(const Path& profile, + const std::string& timeSpec, bool dryRun); void switchLink(const Path& link, Path target); @@ -56,6 +56,6 @@ void lockProfile(PathLocks& lock, const Path& profile); generally cheap, since the build results are still in the Nix store. Most of the time, only the user environment has to be rebuilt. */ -string optimisticLockProfile(const Path& profile); +std::string optimisticLockProfile(const Path& profile); } // namespace nix diff --git a/third_party/nix/src/libstore/references.cc b/third_party/nix/src/libstore/references.cc index c8cebaec08f3..6b9b7137c4e5 100644 --- a/third_party/nix/src/libstore/references.cc +++ b/third_party/nix/src/libstore/references.cc @@ -40,7 +40,7 @@ static void search(const unsigned char* s, size_t len, StringSet& hashes, if (!match) { continue; } - string ref((const char*)s + i, refLength); + std::string ref((const char*)s + i, refLength); if (hashes.find(ref) != hashes.end()) { DLOG(INFO) << "found reference to '" << ref << "' at offset " << i; seen.insert(ref); @@ -55,7 +55,7 @@ struct RefScanSink : Sink { StringSet hashes; StringSet seen; - string tail; + std::string tail; RefScanSink() : hashSink(htSHA256) {} @@ -68,34 +68,34 @@ void RefScanSink::operator()(const unsigned char* data, size_t len) { /* It's possible that a reference spans the previous and current fragment, so search in the concatenation of the tail of the previous fragment and the start of the current fragment. */ - string s = - tail + string((const char*)data, len > refLength ? refLength : len); + std::string s = + tail + std::string((const char*)data, len > refLength ? refLength : len); search((const unsigned char*)s.data(), s.size(), hashes, seen); search(data, len, hashes, seen); size_t tailLen = len <= refLength ? len : refLength; - tail = string(tail, tail.size() < refLength - tailLen - ? 0 - : tail.size() - (refLength - tailLen)) + - string((const char*)data + len - tailLen, tailLen); + tail = std::string(tail, tail.size() < refLength - tailLen + ? 0 + : tail.size() - (refLength - tailLen)) + + std::string((const char*)data + len - tailLen, tailLen); } -PathSet scanForReferences(const string& path, const PathSet& refs, +PathSet scanForReferences(const std::string& path, const PathSet& refs, HashResult& hash) { RefScanSink sink; - std::map<string, Path> backMap; + std::map<std::string, Path> backMap; /* For efficiency (and a higher hit rate), just search for the hash part of the file name. (This assumes that all references have the form `HASH-bla'). */ for (auto& i : refs) { - string baseName = baseNameOf(i); - string::size_type pos = baseName.find('-'); - if (pos == string::npos) { + std::string baseName = baseNameOf(i); + std::string::size_type pos = baseName.find('-'); + if (pos == std::string::npos) { throw Error(format("bad reference '%1%'") % i); } - string s = string(baseName, 0, pos); + std::string s = std::string(baseName, 0, pos); assert(s.size() == refLength); assert(backMap.find(s) == backMap.end()); // parseHash(htSHA256, s); @@ -109,7 +109,7 @@ PathSet scanForReferences(const string& path, const PathSet& refs, /* Map the hashes found back to their store paths. */ PathSet found; for (auto& i : sink.seen) { - std::map<string, Path>::iterator j; + std::map<std::string, Path>::iterator j; if ((j = backMap.find(i)) == backMap.end()) { abort(); } diff --git a/third_party/nix/src/libstore/remote-store.cc b/third_party/nix/src/libstore/remote-store.cc index cc6f6ebae993..c5d1dac6cb6c 100644 --- a/third_party/nix/src/libstore/remote-store.cc +++ b/third_party/nix/src/libstore/remote-store.cc @@ -102,7 +102,7 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection() { } closeOnExec(conn->fd.get()); - string socketPath = path ? *path : settings.nixDaemonSocketFile; + std::string socketPath = path ? *path : settings.nixDaemonSocketFile; struct sockaddr_un addr; addr.sun_family = AF_UNIX; @@ -412,7 +412,7 @@ PathSet RemoteStore::queryDerivationOutputNames(const Path& path) { return readStrings<PathSet>(conn->from); } -Path RemoteStore::queryPathFromHashPart(const string& hashPart) { +Path RemoteStore::queryPathFromHashPart(const std::string& hashPart) { auto conn(getConnection()); conn->to << wopQueryPathFromHashPart << hashPart; conn.processStderr(); @@ -460,7 +460,7 @@ void RemoteStore::addToStore(const ValidPathInfo& info, Source& source, } } -Path RemoteStore::addToStore(const string& name, const Path& _srcPath, +Path RemoteStore::addToStore(const std::string& name, const Path& _srcPath, bool recursive, HashType hashAlgo, PathFilter& filter, RepairFlag repair) { if (repair != 0u) { @@ -503,7 +503,7 @@ Path RemoteStore::addToStore(const string& name, const Path& _srcPath, return readStorePath(*this, conn->from); } -Path RemoteStore::addTextToStore(const string& name, const string& s, +Path RemoteStore::addTextToStore(const std::string& name, const std::string& s, const PathSet& references, RepairFlag repair) { if (repair != 0u) { throw Error( @@ -537,7 +537,7 @@ void RemoteStore::buildPaths(const PathSet& drvPaths, BuildMode buildMode) { identifiers. */ PathSet drvPaths2; for (auto& i : drvPaths) { - drvPaths2.insert(string(i, 0, i.find('!'))); + drvPaths2.insert(std::string(i, 0, i.find('!'))); } conn->to << drvPaths2; } @@ -692,7 +692,7 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink* sink, auto msg = readNum<uint64_t>(from); if (msg == STDERR_WRITE) { - string s = readString(from); + std::string s = readString(from); if (sink == nullptr) { throw Error("no sink"); } @@ -710,7 +710,7 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink* sink, } else if (msg == STDERR_ERROR) { - string error = readString(from); + std::string error = readString(from); unsigned int status = readInt(from); return std::make_exception_ptr(Error(status, error)); } diff --git a/third_party/nix/src/libstore/remote-store.hh b/third_party/nix/src/libstore/remote-store.hh index dc44cd32ac47..e61e72892c34 100644 --- a/third_party/nix/src/libstore/remote-store.hh +++ b/third_party/nix/src/libstore/remote-store.hh @@ -52,7 +52,7 @@ class RemoteStore : public virtual Store { StringSet queryDerivationOutputNames(const Path& path) override; - Path queryPathFromHashPart(const string& hashPart) override; + Path queryPathFromHashPart(const std::string& hashPart) override; PathSet querySubstitutablePaths(const PathSet& paths) override; @@ -63,12 +63,12 @@ class RemoteStore : public virtual Store { CheckSigsFlag checkSigs, std::shared_ptr<FSAccessor> accessor) override; - Path addToStore(const string& name, const Path& srcPath, + Path addToStore(const std::string& name, const Path& srcPath, bool recursive = true, HashType hashAlgo = htSHA256, PathFilter& filter = defaultPathFilter, RepairFlag repair = NoRepair) override; - Path addTextToStore(const string& name, const string& s, + Path addTextToStore(const std::string& name, const std::string& s, const PathSet& references, RepairFlag repair) override; void buildPaths(const PathSet& paths, BuildMode buildMode) override; diff --git a/third_party/nix/src/libstore/s3-binary-cache-store.cc b/third_party/nix/src/libstore/s3-binary-cache-store.cc index df3afab3cf32..2b25fd874437 100644 --- a/third_party/nix/src/libstore/s3-binary-cache-store.cc +++ b/third_party/nix/src/libstore/s3-binary-cache-store.cc @@ -77,8 +77,8 @@ static void initAWS() { }); } -S3Helper::S3Helper(const string& profile, const string& region, - const string& scheme, const string& endpoint) +S3Helper::S3Helper(const std::string& profile, const std::string& region, + const std::string& scheme, const std::string& endpoint) : config(makeConfig(region, scheme, endpoint)), client(make_ref<Aws::S3::S3Client>( profile == "" @@ -114,7 +114,8 @@ class RetryStrategy : public Aws::Client::DefaultRetryStrategy { }; ref<Aws::Client::ClientConfiguration> S3Helper::makeConfig( - const string& region, const string& scheme, const string& endpoint) { + const std::string& region, const std::string& scheme, + const std::string& endpoint) { initAWS(); auto res = make_ref<Aws::Client::ClientConfiguration>(); res->region = region; diff --git a/third_party/nix/src/libstore/sqlite.cc b/third_party/nix/src/libstore/sqlite.cc index 2dea952d0275..dbdaa29d4fd9 100644 --- a/third_party/nix/src/libstore/sqlite.cc +++ b/third_party/nix/src/libstore/sqlite.cc @@ -54,7 +54,7 @@ void SQLite::exec(const std::string& stmt) { }); } -void SQLiteStmt::create(sqlite3* db, const string& sql) { +void SQLiteStmt::create(sqlite3* db, const std::string& sql) { checkInterrupt(); assert(!stmt); if (sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) { diff --git a/third_party/nix/src/libstore/store-api.cc b/third_party/nix/src/libstore/store-api.cc index 50e9b3b6ea86..e6891395cdc5 100644 --- a/third_party/nix/src/libstore/store-api.cc +++ b/third_party/nix/src/libstore/store-api.cc @@ -48,7 +48,7 @@ Path Store::followLinksToStore(const Path& _path) const { if (!isLink(path)) { break; } - string target = readLink(path); + std::string target = readLink(path); path = absPath(target, dirOf(path)); } if (!isInStore(path)) { @@ -61,22 +61,23 @@ Path Store::followLinksToStorePath(const Path& path) const { return toStorePath(followLinksToStore(path)); } -string storePathToName(const Path& path) { +std::string storePathToName(const Path& path) { auto base = baseNameOf(path); assert(base.size() == storePathHashLen || (base.size() > storePathHashLen && base[storePathHashLen] == '-')); - return base.size() == storePathHashLen ? "" - : string(base, storePathHashLen + 1); + return base.size() == storePathHashLen + ? "" + : std::string(base, storePathHashLen + 1); } -string storePathToHash(const Path& path) { +std::string storePathToHash(const Path& path) { auto base = baseNameOf(path); assert(base.size() >= storePathHashLen); - return string(base, 0, storePathHashLen); + return std::string(base, 0, storePathHashLen); } -void checkStoreName(const string& name) { - string validChars = "+-._?="; +void checkStoreName(const std::string& name) { + std::string validChars = "+-._?="; auto baseError = format( @@ -90,7 +91,7 @@ void checkStoreName(const string& name) { /* Disallow names starting with a dot for possible security reasons (e.g., "." and ".."). */ - if (string(name, 0, 1) == ".") { + if (std::string(name, 0, 1) == ".") { throw Error(baseError % "it is illegal to start the name with a period"); } /* Disallow names longer than 211 characters. ext4’s max is 256, @@ -100,7 +101,7 @@ void checkStoreName(const string& name) { } for (auto& i : name) { if (!((i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z') || - (i >= '0' && i <= '9') || validChars.find(i) != string::npos)) { + (i >= '0' && i <= '9') || validChars.find(i) != std::string::npos)) { throw Error(baseError % (format("the '%1%' character is invalid") % i)); } } @@ -176,10 +177,11 @@ void checkStoreName(const string& name) { "source:". */ -Path Store::makeStorePath(const string& type, const Hash& hash, - const string& name) const { +Path Store::makeStorePath(const std::string& type, const Hash& hash, + const std::string& name) const { /* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */ - string s = type + ":" + hash.to_string(Base16) + ":" + storeDir + ":" + name; + std::string s = + type + ":" + hash.to_string(Base16) + ":" + storeDir + ":" + name; checkStoreName(name); @@ -188,31 +190,32 @@ Path Store::makeStorePath(const string& type, const Hash& hash, "-" + name; } -Path Store::makeOutputPath(const string& id, const Hash& hash, - const string& name) const { +Path Store::makeOutputPath(const std::string& id, const Hash& hash, + const std::string& name) const { return makeStorePath("output:" + id, hash, name + (id == "out" ? "" : "-" + id)); } Path Store::makeFixedOutputPath(bool recursive, const Hash& hash, - const string& name) const { + const std::string& name) const { return hash.type == htSHA256 && recursive ? makeStorePath("source", hash, name) : makeStorePath( "output:out", - hashString(htSHA256, - "fixed:out:" + (recursive ? (string) "r:" : "") + - hash.to_string(Base16) + ":"), + hashString( + htSHA256, + "fixed:out:" + (recursive ? (std::string) "r:" : "") + + hash.to_string(Base16) + ":"), name); } -Path Store::makeTextPath(const string& name, const Hash& hash, +Path Store::makeTextPath(const std::string& name, const Hash& hash, const PathSet& references) const { assert(hash.type == htSHA256); /* Stuff the references (if any) into the type. This is a bit hacky, but we can't put them in `s' since that would be ambiguous. */ - string type = "text"; + std::string type = "text"; for (auto& i : references) { type += ":"; type += i; @@ -220,7 +223,7 @@ Path Store::makeTextPath(const string& name, const Hash& hash, return makeStorePath(type, hash, name); } -std::pair<Path, Hash> Store::computeStorePathForPath(const string& name, +std::pair<Path, Hash> Store::computeStorePathForPath(const std::string& name, const Path& srcPath, bool recursive, HashType hashAlgo, @@ -231,7 +234,8 @@ std::pair<Path, Hash> Store::computeStorePathForPath(const string& name, return std::pair<Path, Hash>(dstPath, h); } -Path Store::computeStorePathForText(const string& name, const string& s, +Path Store::computeStorePathForText(const std::string& name, + const std::string& s, const PathSet& references) const { return makeTextPath(name, hashString(htSHA256, s), references); } @@ -428,9 +432,9 @@ PathSet Store::queryValidPaths(const PathSet& paths, /* Return a string accepted by decodeValidPathInfo() that registers the specified paths as valid. Note: it's the responsibility of the caller to provide a closure. */ -string Store::makeValidityRegistration(const PathSet& paths, bool showDerivers, - bool showHash) { - string s = s; +std::string Store::makeValidityRegistration(const PathSet& paths, + bool showDerivers, bool showHash) { + std::string s = s; for (auto& i : paths) { s += i + "\n"; @@ -710,7 +714,7 @@ ValidPathInfo decodeValidPathInfo(std::istream& str, bool hashGiven) { return info; } if (hashGiven) { - string s; + std::string s; getline(str, s); info.narHash = Hash(s, htSHA256); getline(str, s); @@ -719,7 +723,7 @@ ValidPathInfo decodeValidPathInfo(std::istream& str, bool hashGiven) { } } getline(str, info.deriver); - string s; + std::string s; int n; getline(str, s); if (!string2Int(s, n)) { @@ -735,8 +739,8 @@ ValidPathInfo decodeValidPathInfo(std::istream& str, bool hashGiven) { return info; } -string showPaths(const PathSet& paths) { - string s; +std::string showPaths(const PathSet& paths) { + std::string s; for (auto& i : paths) { if (!s.empty()) { s += ", "; diff --git a/third_party/nix/src/libstore/store-api.hh b/third_party/nix/src/libstore/store-api.hh index 242a3e65621e..cf2520c6ca98 100644 --- a/third_party/nix/src/libstore/store-api.hh +++ b/third_party/nix/src/libstore/store-api.hh @@ -18,12 +18,14 @@ namespace nix { -MakeError(SubstError, Error) - MakeError(BuildError, Error) /* denotes a permanent build failure */ - MakeError(InvalidPath, Error) MakeError(Unsupported, Error) - MakeError(SubstituteGone, Error) MakeError(SubstituterDisabled, Error) - - struct BasicDerivation; +MakeError(SubstError, Error); +MakeError(BuildError, Error); /* denotes a permanent build failure */ +MakeError(InvalidPath, Error); +MakeError(Unsupported, Error); +MakeError(SubstituteGone, Error); +MakeError(SubstituterDisabled, Error); + +struct BasicDerivation; struct Derivation; class FSAccessor; class NarInfoDiskCache; @@ -175,7 +177,7 @@ struct ValidPathInfo { virtual ~ValidPathInfo() {} }; -typedef list<ValidPathInfo> ValidPathInfos; +typedef std::list<ValidPathInfo> ValidPathInfos; enum BuildMode { bmNormal, bmRepair, bmCheck }; @@ -274,23 +276,23 @@ class Store : public std::enable_shared_from_this<Store>, public Config { Path followLinksToStorePath(const Path& path) const; /* Constructs a unique store path name. */ - Path makeStorePath(const string& type, const Hash& hash, - const string& name) const; + Path makeStorePath(const std::string& type, const Hash& hash, + const std::string& name) const; - Path makeOutputPath(const string& id, const Hash& hash, - const string& name) const; + Path makeOutputPath(const std::string& id, const Hash& hash, + const std::string& name) const; Path makeFixedOutputPath(bool recursive, const Hash& hash, - const string& name) const; + const std::string& name) const; - Path makeTextPath(const string& name, const Hash& hash, + Path makeTextPath(const std::string& name, const Hash& hash, const PathSet& references) const; /* This is the preparatory part of addToStore(); it computes the store path to which srcPath is to be copied. Returns the store path and the cryptographic hash of the contents of srcPath. */ std::pair<Path, Hash> computeStorePathForPath( - const string& name, const Path& srcPath, bool recursive = true, + const std::string& name, const Path& srcPath, bool recursive = true, HashType hashAlgo = htSHA256, PathFilter& filter = defaultPathFilter) const; @@ -308,7 +310,7 @@ class Store : public std::enable_shared_from_this<Store>, public Config { simply yield a different store path, so other users wouldn't be affected), but it has some backwards compatibility issues (the hashing scheme changes), so I'm not doing that for now. */ - Path computeStorePathForText(const string& name, const string& s, + Path computeStorePathForText(const std::string& name, const std::string& s, const PathSet& references) const; /* Check whether a path is valid. */ @@ -368,7 +370,7 @@ class Store : public std::enable_shared_from_this<Store>, public Config { /* Query the full store path given the hash part of a valid store path, or "" if the path doesn't exist. */ - virtual Path queryPathFromHashPart(const string& hashPart) = 0; + virtual Path queryPathFromHashPart(const std::string& hashPart) = 0; /* Query which of the given paths have substitutes. */ virtual PathSet querySubstitutablePaths(const PathSet& paths) { return {}; }; @@ -400,14 +402,14 @@ class Store : public std::enable_shared_from_this<Store>, public Config { validity the resulting path. The resulting path is returned. The function object `filter' can be used to exclude files (see libutil/archive.hh). */ - virtual Path addToStore(const string& name, const Path& srcPath, + virtual Path addToStore(const std::string& name, const Path& srcPath, bool recursive = true, HashType hashAlgo = htSHA256, PathFilter& filter = defaultPathFilter, RepairFlag repair = NoRepair) = 0; /* Like addToStore, but the contents written to the output path is a regular file containing the given string. */ - virtual Path addTextToStore(const string& name, const string& s, + virtual Path addTextToStore(const std::string& name, const std::string& s, const PathSet& references, RepairFlag repair = NoRepair) = 0; @@ -484,8 +486,8 @@ class Store : public std::enable_shared_from_this<Store>, public Config { /* Return a string representing information about the path that can be loaded into the database using `nix-store --load-db' or `nix-store --register-validity'. */ - string makeValidityRegistration(const PathSet& paths, bool showDerivers, - bool showHash); + std::string makeValidityRegistration(const PathSet& paths, bool showDerivers, + bool showHash); /* Write a JSON representation of store path metadata, such as the hash and the references. If ‘includeImpureInfo’ is true, @@ -637,7 +639,7 @@ class LocalFSStore : public virtual Store { rootDir != "" ? rootDir + "/nix/var/log/nix" : settings.nixLogDir, "log", "directory where Nix will store state"}; - const static string drvsLogDir; + const static std::string drvsLogDir; LocalFSStore(const Params& params); @@ -660,15 +662,15 @@ class LocalFSStore : public virtual Store { }; /* Extract the name part of the given store path. */ -string storePathToName(const Path& path); +std::string storePathToName(const Path& path); /* Extract the hash part of the given store path. */ -string storePathToHash(const Path& path); +std::string storePathToHash(const Path& path); /* Check whether ‘name’ is a valid store path name part, i.e. contains only the characters [a-zA-Z0-9\+\-\.\_\?\=] and doesn't start with a dot. */ -void checkStoreName(const string& name); +void checkStoreName(const std::string& name); /* Copy a path from one store to another. */ void copyStorePath(ref<Store> srcStore, const ref<Store>& dstStore, @@ -756,7 +758,7 @@ struct RegisterStoreImplementation { /* Display a set of paths in human-readable form (i.e., between quotes and separated by commas). */ -string showPaths(const PathSet& paths); +std::string showPaths(const PathSet& paths); ValidPathInfo decodeValidPathInfo(std::istream& str, bool hashGiven = false); diff --git a/third_party/nix/src/libutil/archive.cc b/third_party/nix/src/libutil/archive.cc index 32bad07f22da..f78727c5fb46 100644 --- a/third_party/nix/src/libutil/archive.cc +++ b/third_party/nix/src/libutil/archive.cc @@ -38,7 +38,7 @@ static GlobalConfig::Register r1(&archiveSettings); const std::string narVersionMagic1 = "nix-archive-1"; -static string caseHackSuffix = "~nix~case~hack~"; +static std::string caseHackSuffix = "~nix~case~hack~"; PathFilter defaultPathFilter = [](const Path& /*unused*/) { return true; }; @@ -89,12 +89,12 @@ static void dump(const Path& path, Sink& sink, PathFilter& filter) { /* If we're on a case-insensitive system like macOS, undo the case hack applied by restorePath(). */ - std::map<string, string> unhacked; + std::map<std::string, std::string> unhacked; for (auto& i : readDirectory(path)) { if (archiveSettings.useCaseHack) { - string name(i.name); + std::string name(i.name); size_t pos = i.name.find(caseHackSuffix); - if (pos != string::npos) { + if (pos != std::string::npos) { DLOG(INFO) << "removing case hack suffix from " << path << "/" << i.name; @@ -145,7 +145,7 @@ void dumpString(const std::string& s, Sink& sink) { << "contents" << s << ")"; } -static SerialisationError badArchive(const string& s) { +static SerialisationError badArchive(const std::string& s) { return SerialisationError("bad archive: " + s); } @@ -182,13 +182,13 @@ static void parseContents(ParseSink& sink, Source& source, const Path& path) { } struct CaseInsensitiveCompare { - bool operator()(const string& a, const string& b) const { + bool operator()(const std::string& a, const std::string& b) const { return strcasecmp(a.c_str(), b.c_str()) < 0; } }; static void parse(ParseSink& sink, Source& source, const Path& path) { - string s; + std::string s; s = readString(source); if (s != "(") { @@ -212,7 +212,7 @@ static void parse(ParseSink& sink, Source& source, const Path& path) { if (type != tpUnknown) { throw badArchive("multiple type fields"); } - string t = readString(source); + std::string t = readString(source); if (t == "regular") { type = tpRegular; @@ -247,8 +247,8 @@ static void parse(ParseSink& sink, Source& source, const Path& path) { } else if (s == "entry" && type == tpDirectory) { - string name; - string prevName; + std::string name; + std::string prevName; s = readString(source); if (s != "(") { @@ -266,8 +266,8 @@ static void parse(ParseSink& sink, Source& source, const Path& path) { if (s == "name") { name = readString(source); if (name.empty() || name == "." || name == ".." || - name.find('/') != string::npos || - name.find((char)0) != string::npos) { + name.find('/') != std::string::npos || + name.find((char)0) != std::string::npos) { throw Error(format("NAR contains invalid file name '%1%'") % name); } if (name <= prevName) { @@ -297,7 +297,7 @@ static void parse(ParseSink& sink, Source& source, const Path& path) { } else if (s == "target" && type == tpSymlink) { - string target = readString(source); + std::string target = readString(source); sink.createSymlink(path, target); } @@ -308,7 +308,7 @@ static void parse(ParseSink& sink, Source& source, const Path& path) { } void parseDump(ParseSink& sink, Source& source) { - string version; + std::string version; try { version = readString(source, narVersionMagic1.size()); } catch (SerialisationError& e) { @@ -369,7 +369,7 @@ struct RestoreSink : ParseSink { writeFull(fd.get(), data, len); } - void createSymlink(const Path& path, const string& target) override { + void createSymlink(const Path& path, const std::string& target) override { Path p = dstPath + path; nix::createSymlink(target, p); } diff --git a/third_party/nix/src/libutil/archive.hh b/third_party/nix/src/libutil/archive.hh index 9a656edae4a3..0afa8893efdd 100644 --- a/third_party/nix/src/libutil/archive.hh +++ b/third_party/nix/src/libutil/archive.hh @@ -56,7 +56,7 @@ struct ParseSink { virtual void preallocateContents(unsigned long long size){}; virtual void receiveContents(unsigned char* data, unsigned int len){}; - virtual void createSymlink(const Path& path, const string& target){}; + virtual void createSymlink(const Path& path, const std::string& target){}; }; struct TeeSink : ParseSink { diff --git a/third_party/nix/src/libutil/args.cc b/third_party/nix/src/libutil/args.cc index 48fa715fdf0f..4e7bcb3ae72b 100644 --- a/third_party/nix/src/libutil/args.cc +++ b/third_party/nix/src/libutil/args.cc @@ -27,14 +27,14 @@ void Args::parseCmdline(const Strings& _cmdline) { `-j3` -> `-j 3`). */ if (!dashDash && arg.length() > 2 && arg[0] == '-' && arg[1] != '-' && (isalpha(arg[1]) != 0)) { - *pos = (string) "-" + arg[1]; + *pos = (std::string) "-" + arg[1]; auto next = pos; ++next; for (unsigned int j = 2; j < arg.length(); j++) { if (isalpha(arg[j]) != 0) { - cmdline.insert(next, (string) "-" + arg[j]); + cmdline.insert(next, (std::string) "-" + arg[j]); } else { - cmdline.insert(next, string(arg, j)); + cmdline.insert(next, std::string(arg, j)); break; } } @@ -59,7 +59,7 @@ void Args::parseCmdline(const Strings& _cmdline) { processArgs(pendingArgs, true); } -void Args::printHelp(const string& programName, std::ostream& out) { +void Args::printHelp(const std::string& programName, std::ostream& out) { std::cout << "Usage: " << programName << " <FLAGS>..."; for (auto& exp : expectedArgs) { std::cout << renderLabels({exp.label}); @@ -121,15 +121,15 @@ bool Args::processFlag(Strings::iterator& pos, Strings::iterator end) { return true; }; - if (string(*pos, 0, 2) == "--") { - auto i = longFlags.find(string(*pos, 2)); + if (std::string(*pos, 0, 2) == "--") { + auto i = longFlags.find(std::string(*pos, 2)); if (i == longFlags.end()) { return false; } return process("--" + i->first, *i->second); } - if (string(*pos, 0, 1) == "-" && pos->size() == 2) { + if (std::string(*pos, 0, 1) == "-" && pos->size() == 2) { auto c = (*pos)[1]; auto i = shortFlags.find(c); if (i == shortFlags.end()) { diff --git a/third_party/nix/src/libutil/args.hh b/third_party/nix/src/libutil/args.hh index 20233d353424..20a6379fecba 100644 --- a/third_party/nix/src/libutil/args.hh +++ b/third_party/nix/src/libutil/args.hh @@ -18,7 +18,7 @@ class Args { wrong. */ void parseCmdline(const Strings& cmdline); - virtual void printHelp(const string& programName, std::ostream& out); + virtual void printHelp(const std::string& programName, std::ostream& out); virtual std::string description() { return ""; } @@ -187,7 +187,7 @@ class Args { } /* Expect a string argument. */ - void expectArg(const std::string& label, string* dest, + void expectArg(const std::string& label, std::string* dest, bool optional = false) { expectedArgs.push_back( ExpectedArg{label, 1, optional, diff --git a/third_party/nix/src/libutil/config.cc b/third_party/nix/src/libutil/config.cc index 828ee1811bdb..c7c952abf16f 100644 --- a/third_party/nix/src/libutil/config.cc +++ b/third_party/nix/src/libutil/config.cc @@ -82,23 +82,23 @@ void Config::getSettings(std::map<std::string, SettingInfo>& res, void AbstractConfig::applyConfigFile(const Path& path) { try { - string contents = readFile(path); + std::string contents = readFile(path); unsigned int pos = 0; while (pos < contents.size()) { - string line; + std::string line; while (pos < contents.size() && contents[pos] != '\n') { line += contents[pos++]; } pos++; - string::size_type hash = line.find('#'); - if (hash != string::npos) { - line = string(line, 0, hash); + std::string::size_type hash = line.find('#'); + if (hash != std::string::npos) { + line = std::string(line, 0, hash); } - auto tokens = tokenizeString<vector<string> >(line); + auto tokens = tokenizeString<std::vector<std::string> >(line); if (tokens.empty()) { continue; } @@ -136,7 +136,7 @@ void AbstractConfig::applyConfigFile(const Path& path) { path); } - string name = tokens[0]; + std::string name = tokens[0]; auto i = tokens.begin(); advance(i, 2); diff --git a/third_party/nix/src/libutil/hash.cc b/third_party/nix/src/libutil/hash.cc index 81d8628e972b..07a9730551da 100644 --- a/third_party/nix/src/libutil/hash.cc +++ b/third_party/nix/src/libutil/hash.cc @@ -63,26 +63,26 @@ bool Hash::operator<(const Hash& h) const { return false; } -const string base16Chars = "0123456789abcdef"; +const std::string base16Chars = "0123456789abcdef"; -static string printHash16(const Hash& hash) { +static std::string printHash16(const Hash& hash) { char buf[hash.hashSize * 2]; for (unsigned int i = 0; i < hash.hashSize; i++) { buf[i * 2] = base16Chars[hash.hash[i] >> 4]; buf[i * 2 + 1] = base16Chars[hash.hash[i] & 0x0f]; } - return string(buf, hash.hashSize * 2); + return std::string(buf, hash.hashSize * 2); } // omitted: E O U T -const string base32Chars = "0123456789abcdfghijklmnpqrsvwxyz"; +const std::string base32Chars = "0123456789abcdfghijklmnpqrsvwxyz"; -static string printHash32(const Hash& hash) { +static std::string printHash32(const Hash& hash) { assert(hash.hashSize); size_t len = hash.base32Len(); assert(len); - string s; + std::string s; s.reserve(len); for (int n = (int)len - 1; n >= 0; n--) { @@ -98,7 +98,7 @@ static string printHash32(const Hash& hash) { return s; } -string printHash16or32(const Hash& hash) { +std::string printHash16or32(const Hash& hash) { return hash.to_string(hash.type == htMD5 ? Base16 : Base32, false); } @@ -128,17 +128,17 @@ Hash::Hash(const std::string& s, HashType type) : type(type) { bool isSRI = false; auto sep = s.find(':'); - if (sep == string::npos) { + if (sep == std::string::npos) { sep = s.find('-'); - if (sep != string::npos) { + if (sep != std::string::npos) { isSRI = true; } else if (type == htUnknown) { throw BadHash("hash '%s' does not include a type", s); } } - if (sep != string::npos) { - string hts = string(s, 0, sep); + if (sep != std::string::npos) { + std::string hts = std::string(s, 0, sep); this->type = parseHashType(hts); if (this->type == htUnknown) { throw BadHash("unknown hash type '%s'", hts); @@ -259,7 +259,7 @@ static void finish(HashType ht, Ctx& ctx, unsigned char* hash) { } } -Hash hashString(HashType ht, const string& s) { +Hash hashString(HashType ht, const std::string& s) { Ctx ctx; Hash hash(ht); start(ht, ctx); @@ -338,7 +338,7 @@ Hash compressHash(const Hash& hash, unsigned int newSize) { return h; } -HashType parseHashType(const string& s) { +HashType parseHashType(const std::string& s) { if (s == "md5") { return htMD5; } @@ -353,7 +353,7 @@ HashType parseHashType(const string& s) { } } -string printHashType(HashType ht) { +std::string printHashType(HashType ht) { if (ht == htMD5) { return "md5"; } diff --git a/third_party/nix/src/libutil/hash.hh b/third_party/nix/src/libutil/hash.hh index a9002023fa31..f9c63c155ead 100644 --- a/third_party/nix/src/libutil/hash.hh +++ b/third_party/nix/src/libutil/hash.hh @@ -14,7 +14,7 @@ const int sha1HashSize = 20; const int sha256HashSize = 32; const int sha512HashSize = 64; -extern const string base32Chars; +extern const std::string base32Chars; enum Base : int { Base64, Base32, Base16, SRI }; @@ -68,10 +68,10 @@ struct Hash { }; /* Print a hash in base-16 if it's MD5, or base-32 otherwise. */ -string printHash16or32(const Hash& hash); +std::string printHash16or32(const Hash& hash); /* Compute the hash of the given string. */ -Hash hashString(HashType ht, const string& s); +Hash hashString(HashType ht, const std::string& s); /* Compute the hash of the given file. */ Hash hashFile(HashType ht, const Path& path); @@ -87,10 +87,10 @@ HashResult hashPath(HashType ht, const Path& path, Hash compressHash(const Hash& hash, unsigned int newSize); /* Parse a string representing a hash type. */ -HashType parseHashType(const string& s); +HashType parseHashType(const std::string& s); /* And the reverse. */ -string printHashType(HashType ht); +std::string printHashType(HashType ht); union Ctx; diff --git a/third_party/nix/src/libutil/serialise.cc b/third_party/nix/src/libutil/serialise.cc index 34af4e840ab6..52f0b5542601 100644 --- a/third_party/nix/src/libutil/serialise.cc +++ b/third_party/nix/src/libutil/serialise.cc @@ -223,7 +223,7 @@ void writeString(const unsigned char* buf, size_t len, Sink& sink) { writePadding(len, sink); } -Sink& operator<<(Sink& sink, const string& s) { +Sink& operator<<(Sink& sink, const std::string& s) { writeString((const unsigned char*)s.data(), s.size(), sink); return sink; } @@ -269,7 +269,7 @@ size_t readString(unsigned char* buf, size_t max, Source& source) { return len; } -string readString(Source& source, size_t max) { +std::string readString(Source& source, size_t max) { auto len = readNum<size_t>(source); if (len > max) { throw SerialisationError("string is too long"); @@ -280,7 +280,7 @@ string readString(Source& source, size_t max) { return res; } -Source& operator>>(Source& in, string& s) { +Source& operator>>(Source& in, std::string& s) { s = readString(in); return in; } diff --git a/third_party/nix/src/libutil/serialise.hh b/third_party/nix/src/libutil/serialise.hh index a5992b50ec6e..dc877487ee7e 100644 --- a/third_party/nix/src/libutil/serialise.hh +++ b/third_party/nix/src/libutil/serialise.hh @@ -135,9 +135,9 @@ struct StringSink : Sink { /* A source that reads data from a string. */ struct StringSource : Source { - const string& s; + const std::string& s; size_t pos; - StringSource(const string& _s) : s(_s), pos(0) {} + StringSource(const std::string& _s) : s(_s), pos(0) {} size_t read(unsigned char* data, size_t len) override; }; @@ -231,7 +231,7 @@ inline Sink& operator<<(Sink& sink, uint64_t n) { return sink; } -Sink& operator<<(Sink& sink, const string& s); +Sink& operator<<(Sink& sink, const std::string& s); Sink& operator<<(Sink& sink, const Strings& s); Sink& operator<<(Sink& sink, const StringSet& s); @@ -265,12 +265,12 @@ inline uint64_t readLongLong(Source& source) { void readPadding(size_t len, Source& source); size_t readString(unsigned char* buf, size_t max, Source& source); -string readString(Source& source, - size_t max = std::numeric_limits<size_t>::max()); +std::string readString(Source& source, + size_t max = std::numeric_limits<size_t>::max()); template <class T> T readStrings(Source& source); -Source& operator>>(Source& in, string& s); +Source& operator>>(Source& in, std::string& s); template <typename T> Source& operator>>(Source& in, T& n) { diff --git a/third_party/nix/src/libutil/types.hh b/third_party/nix/src/libutil/types.hh index ac1b802ce0f1..ad44719afe3a 100644 --- a/third_party/nix/src/libutil/types.hh +++ b/third_party/nix/src/libutil/types.hh @@ -22,10 +22,6 @@ namespace nix { /* Inherit some names from other namespaces for convenience. */ using boost::format; -using std::list; -using std::set; -using std::string; -using std::vector; /* A variadic template that does nothing. Useful to call a function for all variadic arguments but ignoring the result. */ @@ -35,8 +31,8 @@ struct nop { }; struct FormatOrString { - string s; - FormatOrString(const string& s) : s(s){}; + std::string s; + FormatOrString(const std::string& s) : s(s){}; FormatOrString(const format& f) : s(f.str()){}; FormatOrString(const char* s) : s(s){}; }; @@ -64,8 +60,8 @@ inline std::string fmt(const std::string& fs, Args... args) { a subclass. Catch Error instead. */ class BaseError : public std::exception { protected: - string prefix_; // used for location traces etc. - string err; + std::string prefix_; // used for location traces etc. + std::string err; public: unsigned int status = 1; // exit status @@ -84,8 +80,8 @@ class BaseError : public std::exception { const char* what() const noexcept { return err.c_str(); } #endif - const string& msg() const { return err; } - const string& prefix() const { return prefix_; } + const std::string& msg() const { return err; } + const std::string& prefix() const { return prefix_; } BaseError& addPrefix(const FormatOrString& fs); }; @@ -108,13 +104,13 @@ MakeError(Error, BaseError) std::string addErrno(const std::string& s); }; -typedef list<string> Strings; -typedef set<string> StringSet; +typedef std::list<std::string> Strings; +typedef std::set<std::string> StringSet; typedef std::map<std::string, std::string> StringMap; /* Paths are just strings. */ -typedef string Path; -typedef list<Path> Paths; -typedef set<Path> PathSet; +typedef std::string Path; +typedef std::list<Path> Paths; +typedef std::set<Path> PathSet; } // namespace nix diff --git a/third_party/nix/src/libutil/util.cc b/third_party/nix/src/libutil/util.cc index 53d037cf5801..696a8ff2365e 100644 --- a/third_party/nix/src/libutil/util.cc +++ b/third_party/nix/src/libutil/util.cc @@ -42,9 +42,9 @@ std::string SysError::addErrno(const std::string& s) { return s + ": " + strerror(errNo); } -string getEnv(const string& key, const string& def) { +std::string getEnv(const std::string& key, const std::string& def) { char* value = getenv(key.c_str()); - return value != nullptr ? string(value) : def; + return value != nullptr ? std::string(value) : def; } std::map<std::string, std::string> getEnv() { @@ -101,15 +101,15 @@ return canonPath(path); Path canonPath(const Path& path, bool resolveSymlinks) { assert(!path.empty()); - string s; + std::string s; if (path[0] != '/') { throw Error(format("not an absolute path: '%1%'") % path); } - string::const_iterator i = path.begin(); - string::const_iterator end = path.end(); - string temp; + std::string::const_iterator i = path.begin(); + std::string::const_iterator end = path.end(); + std::string temp; /* Count the number of times we follow a symlink and stop at some arbitrary (but high) limit to prevent infinite loops. */ @@ -153,7 +153,7 @@ Path canonPath(const Path& path, bool resolveSymlinks) { throw Error(format("infinite symlink recursion in path '%1%'") % path); } - temp = absPath(readLink(s), dirOf(s)) + string(i, end); + temp = absPath(readLink(s), dirOf(s)) + std::string(i, end); i = temp.begin(); /* restart */ end = temp.end(); s = ""; @@ -166,13 +166,13 @@ Path canonPath(const Path& path, bool resolveSymlinks) { Path dirOf(const Path& path) { Path::size_type pos = path.rfind('/'); - if (pos == string::npos) { + if (pos == std::string::npos) { return "."; } return pos == 0 ? "/" : Path(path, 0, pos); } -string baseNameOf(const Path& path) { +std::string baseNameOf(const Path& path) { if (path.empty()) { return ""; } @@ -183,17 +183,17 @@ string baseNameOf(const Path& path) { } Path::size_type pos = path.rfind('/', last); - if (pos == string::npos) { + if (pos == std::string::npos) { pos = 0; } else { pos += 1; } - return string(path, pos, last - pos + 1); + return std::string(path, pos, last - pos + 1); } bool isInDir(const Path& path, const Path& dir) { - return path[0] == '/' && string(path, 0, dir.size()) == dir && + return path[0] == '/' && std::string(path, 0, dir.size()) == dir && path.size() >= dir.size() + 2 && path[dir.size()] == '/'; } @@ -235,7 +235,7 @@ Path readLink(const Path& path) { throw SysError("reading symbolic link '%1%'", path); } else if (rlSize < bufSize) { - return string(buf.data(), rlSize); + return std::string(buf.data(), rlSize); } } } @@ -252,7 +252,7 @@ DirEntries readDirectory(DIR* dir, const Path& path) { struct dirent* dirent; while (errno = 0, dirent = readdir(dir)) { /* sic */ checkInterrupt(); - string name = dirent->d_name; + std::string name = dirent->d_name; if (name == "." || name == "..") { continue; } @@ -294,7 +294,7 @@ unsigned char getFileType(const Path& path) { return DT_UNKNOWN; } -string readFile(int fd) { +std::string readFile(int fd) { struct stat st; if (fstat(fd, &st) == -1) { throw SysError("statting file"); @@ -303,10 +303,10 @@ string readFile(int fd) { std::vector<unsigned char> buf(st.st_size); readFull(fd, buf.data(), st.st_size); - return string((char*)buf.data(), st.st_size); + return std::string((char*)buf.data(), st.st_size); } -string readFile(const Path& path, bool drain) { +std::string readFile(const Path& path, bool drain) { AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC); if (!fd) { throw SysError(format("opening file '%1%'") % path); @@ -322,7 +322,7 @@ void readFile(const Path& path, Sink& sink) { drainFD(fd.get(), sink); } -void writeFile(const Path& path, const string& s, mode_t mode) { +void writeFile(const Path& path, const std::string& s, mode_t mode) { AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode); if (!fd) { @@ -350,8 +350,8 @@ void writeFile(const Path& path, Source& source, mode_t mode) { } } -string readLine(int fd) { - string s; +std::string readLine(int fd) { + std::string s; while (true) { checkInterrupt(); char ch; @@ -372,7 +372,7 @@ string readLine(int fd) { } } -void writeLine(int fd, string s) { +void writeLine(int fd, std::string s) { s += '\n'; writeFull(fd, s); } @@ -381,7 +381,7 @@ static void _deletePath(int parentfd, const Path& path, unsigned long long& bytesFreed) { checkInterrupt(); - string name(baseNameOf(path)); + std::string name(baseNameOf(path)); struct stat st; if (fstatat(parentfd, name.c_str(), &st, AT_SYMLINK_NOFOLLOW) == -1) { @@ -539,8 +539,8 @@ Path getConfigDir() { std::vector<Path> getConfigDirs() { Path configHome = getConfigDir(); - string configDirs = getEnv("XDG_CONFIG_DIRS"); - auto result = tokenizeString<std::vector<string>>(configDirs, ":"); + std::string configDirs = getEnv("XDG_CONFIG_DIRS"); + auto result = tokenizeString<std::vector<std::string>>(configDirs, ":"); result.insert(result.begin(), configHome); return result; } @@ -643,11 +643,11 @@ void writeFull(int fd, const unsigned char* buf, size_t count, } } -void writeFull(int fd, const string& s, bool allowInterrupts) { +void writeFull(int fd, const std::string& s, bool allowInterrupts) { writeFull(fd, (const unsigned char*)s.data(), s.size(), allowInterrupts); } -string drainFD(int fd, bool block) { +std::string drainFD(int fd, bool block) { StringSink sink; drainFD(fd, sink, block); return std::move(*sink.s); @@ -694,7 +694,7 @@ void drainFD(int fd, Sink& sink, bool block) { AutoDelete::AutoDelete() : del{false} {} -AutoDelete::AutoDelete(string p, bool recursive) : path(std::move(p)) { +AutoDelete::AutoDelete(std::string p, bool recursive) : path(std::move(p)) { del = true; this->recursive = recursive; } @@ -812,7 +812,7 @@ int Pid::kill() { process group, send the signal to every process in the child process group (which hopefully includes *all* its children). */ if (::kill(separatePG ? -pid : pid, killSignal) != 0) { - LOG(ERROR) << SysError("killing process %d", pid).msg(); + LOG(ERROR) << SysError("killing process %d", pid).msg(); } return wait(); @@ -950,8 +950,9 @@ std::vector<char*> stringsToCharPtrs(const Strings& ss) { return res; } -string runProgram(const Path& program, bool searchPath, const Strings& args, - const std::optional<std::string>& input) { +std::string runProgram(const Path& program, bool searchPath, + const Strings& args, + const std::optional<std::string>& input) { RunOptions opts(program, args); opts.searchPath = searchPath; opts.input = input; @@ -1114,7 +1115,7 @@ void runProgram2(const RunOptions& options) { } } -void closeMostFDs(const set<int>& exceptions) { +void closeMostFDs(const std::set<int>& exceptions) { #if __linux__ try { for (auto& s : readDirectory("/proc/self/fd")) { @@ -1168,28 +1169,30 @@ void _interrupted() { ////////////////////////////////////////////////////////////////////// template <class C> -C tokenizeString(const string& s, const string& separators) { +C tokenizeString(const std::string& s, const std::string& separators) { C result; - string::size_type pos = s.find_first_not_of(separators, 0); - while (pos != string::npos) { - string::size_type end = s.find_first_of(separators, pos + 1); - if (end == string::npos) { + std::string::size_type pos = s.find_first_not_of(separators, 0); + while (pos != std::string::npos) { + std::string::size_type end = s.find_first_of(separators, pos + 1); + if (end == std::string::npos) { end = s.size(); } - string token(s, pos, end - pos); + std::string token(s, pos, end - pos); result.insert(result.end(), token); pos = s.find_first_not_of(separators, end); } return result; } -template Strings tokenizeString(const string& s, const string& separators); -template StringSet tokenizeString(const string& s, const string& separators); -template vector<string> tokenizeString(const string& s, - const string& separators); +template Strings tokenizeString(const std::string& s, + const std::string& separators); +template StringSet tokenizeString(const std::string& s, + const std::string& separators); +template std::vector<std::string> tokenizeString(const std::string& s, + const std::string& separators); -string concatStringsSep(const string& sep, const Strings& ss) { - string s; +std::string concatStringsSep(const std::string& sep, const Strings& ss) { + std::string s; for (auto& i : ss) { if (!s.empty()) { s += sep; @@ -1199,8 +1202,8 @@ string concatStringsSep(const string& sep, const Strings& ss) { return s; } -string concatStringsSep(const string& sep, const StringSet& ss) { - string s; +std::string concatStringsSep(const std::string& sep, const StringSet& ss) { + std::string s; for (auto& i : ss) { if (!s.empty()) { s += sep; @@ -1210,21 +1213,21 @@ string concatStringsSep(const string& sep, const StringSet& ss) { return s; } -string trim(const string& s, const string& whitespace) { +std::string trim(const std::string& s, const std::string& whitespace) { auto i = s.find_first_not_of(whitespace); - if (i == string::npos) { + if (i == std::string::npos) { return ""; } auto j = s.find_last_not_of(whitespace); - return string(s, i, j == string::npos ? j : j - i + 1); + return std::string(s, i, j == std::string::npos ? j : j - i + 1); } -string replaceStrings(const std::string& s, const std::string& from, - const std::string& to) { +std::string replaceStrings(const std::string& s, const std::string& from, + const std::string& to) { if (from.empty()) { return s; } - string res = s; + std::string res = s; size_t pos = 0; while ((pos = res.find(from, pos)) != std::string::npos) { res.replace(pos, from.size(), to); @@ -1233,7 +1236,7 @@ string replaceStrings(const std::string& s, const std::string& from, return res; } -string statusToString(int status) { +std::string statusToString(int status) { if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { if (WIFEXITED(status)) { return (format("failed with exit code %1%") % WEXITSTATUS(status)).str(); @@ -1259,13 +1262,13 @@ bool statusOk(int status) { return WIFEXITED(status) && WEXITSTATUS(status) == 0; } -bool hasPrefix(const string& s, const string& prefix) { +bool hasPrefix(const std::string& s, const std::string& prefix) { return s.compare(0, prefix.size(), prefix) == 0; } -bool hasSuffix(const string& s, const string& suffix) { +bool hasSuffix(const std::string& s, const std::string& suffix) { return s.size() >= suffix.size() && - string(s, s.size() - suffix.size()) == suffix; + std::string(s, s.size() - suffix.size()) == suffix; } std::string toLower(const std::string& s) { @@ -1361,8 +1364,8 @@ std::string filterANSIEscapes(const std::string& s, bool filterAll, static char base64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -string base64Encode(const string& s) { - string res; +std::string base64Encode(const std::string& s) { + std::string res; int data = 0; int nbits = 0; @@ -1385,7 +1388,7 @@ string base64Encode(const string& s) { return res; } -string base64Decode(const string& s) { +std::string base64Decode(const std::string& s) { bool init = false; char decode[256]; if (!init) { @@ -1397,7 +1400,7 @@ string base64Decode(const string& s) { init = true; } - string res; + std::string res; unsigned int d = 0; unsigned int bits = 0; diff --git a/third_party/nix/src/libutil/util.hh b/third_party/nix/src/libutil/util.hh index 3c8d4bd70c06..7d10df50bf5b 100644 --- a/third_party/nix/src/libutil/util.hh +++ b/third_party/nix/src/libutil/util.hh @@ -32,7 +32,7 @@ struct Source; extern const std::string nativeSystem; /* Return an environment variable. */ -string getEnv(const string& key, const string& def = ""); +std::string getEnv(const std::string& key, const std::string& def = ""); /* Get the entire environment. */ std::map<std::string, std::string> getEnv(); @@ -59,7 +59,7 @@ Path dirOf(const Path& path); /* Return the base name of the given canonical path, i.e., everything following the final `/'. */ -string baseNameOf(const Path& path); +std::string baseNameOf(const Path& path); /* Check whether 'path' is a descendant of 'dir'. */ bool isInDir(const Path& path, const Path& dir); @@ -82,34 +82,34 @@ bool isLink(const Path& path); /* Read the contents of a directory. The entries `.' and `..' are removed. */ struct DirEntry { - string name; + std::string name; ino_t ino; unsigned char type; // one of DT_* - DirEntry(const string& name, ino_t ino, unsigned char type) + DirEntry(const std::string& name, ino_t ino, unsigned char type) : name(name), ino(ino), type(type) {} }; -typedef vector<DirEntry> DirEntries; +typedef std::vector<DirEntry> DirEntries; DirEntries readDirectory(const Path& path); 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); +std::string readFile(int fd); +std::string readFile(const Path& path, bool drain = false); void readFile(const Path& path, Sink& sink); /* Write a string to a file. */ -void writeFile(const Path& path, const string& s, mode_t mode = 0666); +void writeFile(const Path& path, const std::string& s, mode_t mode = 0666); void writeFile(const Path& path, Source& source, mode_t mode = 0666); /* Read a line from a file descriptor. */ -string readLine(int fd); +std::string readLine(int fd); /* Write a line to a file descriptor. */ -void writeLine(int fd, string s); +void writeLine(int fd, std::string s); /* Delete a path; i.e., in the case of a directory, it is deleted recursively. It's not an error if the path does not exist. The @@ -155,12 +155,12 @@ void replaceSymlink(const Path& target, const Path& link); void readFull(int fd, unsigned char* buf, size_t count); void writeFull(int fd, const unsigned char* buf, size_t count, bool allowInterrupts = true); -void writeFull(int fd, const string& s, bool allowInterrupts = true); +void writeFull(int fd, const std::string& s, bool allowInterrupts = true); -MakeError(EndOfFile, Error) +MakeError(EndOfFile, Error); - /* Read a file descriptor until EOF occurs. */ - string drainFD(int fd, bool block = true); +/* Read a file descriptor until EOF occurs. */ +std::string drainFD(int fd, bool block = true); void drainFD(int fd, Sink& sink, bool block = true); @@ -235,7 +235,7 @@ void killUser(uid_t uid); /* Fork a process that runs the given function, and return the child pid to the caller. */ struct ProcessOptions { - string errorPrefix = "error: "; + std::string errorPrefix = "error: "; bool dieWithParent = true; bool runExitHandlers = false; bool allowVfork = true; @@ -246,9 +246,9 @@ pid_t startProcess(std::function<void()> fun, /* Run a program and return its stdout in a string (i.e., like the shell backtick operator). */ -string runProgram(const Path& program, bool searchPath = false, - const Strings& args = Strings(), - const std::optional<std::string>& input = {}); +std::string runProgram(const Path& program, bool searchPath = false, + const Strings& args = Strings(), + const std::optional<std::string>& input = {}); struct RunOptions { std::optional<uid_t> uid; @@ -292,7 +292,7 @@ std::vector<char*> stringsToCharPtrs(const Strings& ss); /* Close all file descriptors except those listed in the given set. Good practice in child processes. */ -void closeMostFDs(const set<int>& exceptions); +void closeMostFDs(const std::set<int>& exceptions); /* Set the close-on-exec flag for the given file descriptor. */ void closeOnExec(int fd); @@ -311,36 +311,38 @@ void inline checkInterrupt() { if (_isInterrupted || (interruptCheck && interruptCheck())) _interrupted(); } -MakeError(Interrupted, BaseError) +MakeError(Interrupted, BaseError); - MakeError(FormatError, Error) +MakeError(FormatError, Error); - /* String tokenizer. */ - template <class C> - C tokenizeString(const string& s, const string& separators = " \t\n\r"); +/* String tokenizer. */ +template <class C> +C tokenizeString(const std::string& s, + const std::string& separators = " \t\n\r"); /* Concatenate the given strings with a separator between the elements. */ -string concatStringsSep(const string& sep, const Strings& ss); -string concatStringsSep(const string& sep, const StringSet& ss); +std::string concatStringsSep(const std::string& sep, const Strings& ss); +std::string concatStringsSep(const std::string& sep, const StringSet& ss); /* Remove whitespace from the start and end of a string. */ -string trim(const string& s, const string& whitespace = " \n\r\t"); +std::string trim(const std::string& s, + const std::string& whitespace = " \n\r\t"); /* Replace all occurrences of a string inside another string. */ -string replaceStrings(const std::string& s, const std::string& from, - const std::string& to); +std::string replaceStrings(const std::string& s, const std::string& from, + const std::string& to); /* Convert the exit status of a child as returned by wait() into an error string. */ -string statusToString(int status); +std::string statusToString(int status); bool statusOk(int status); /* Parse a string into an integer. */ template <class N> -bool string2Int(const string& s, N& n) { - if (string(s, 0, 1) == "-" && !std::numeric_limits<N>::is_signed) +bool string2Int(const std::string& s, N& n) { + if (std::string(s, 0, 1) == "-" && !std::numeric_limits<N>::is_signed) return false; std::istringstream str(s); str >> n; @@ -349,17 +351,17 @@ bool string2Int(const string& s, N& n) { /* Parse a string into a float. */ template <class N> -bool string2Float(const string& s, N& n) { +bool string2Float(const std::string& s, N& n) { std::istringstream str(s); str >> n; return str && str.get() == EOF; } /* Return true iff `s' starts with `prefix'. */ -bool hasPrefix(const string& s, const string& prefix); +bool hasPrefix(const std::string& s, const std::string& prefix); /* Return true iff `s' ends in `suffix'. */ -bool hasSuffix(const string& s, const string& suffix); +bool hasSuffix(const std::string& s, const std::string& suffix); /* Convert a string to lower case. */ std::string toLower(const std::string& s); @@ -389,13 +391,14 @@ std::string filterANSIEscapes( unsigned int width = std::numeric_limits<unsigned int>::max()); /* Base64 encoding/decoding. */ -string base64Encode(const string& s); -string base64Decode(const string& s); +std::string base64Encode(const std::string& s); +std::string base64Decode(const std::string& s); /* Get a value for the specified key from an associate container, or a default value if the key doesn't exist. */ template <class T> -string get(const T& map, const string& key, const string& def = "") { +std::string get(const T& map, const std::string& key, + const std::string& def = "") { auto i = map.find(key); return i == map.end() ? def : i->second; } diff --git a/third_party/nix/src/libutil/xml-writer.cc b/third_party/nix/src/libutil/xml-writer.cc index 11cd632399ad..d34e9a2f0d59 100644 --- a/third_party/nix/src/libutil/xml-writer.cc +++ b/third_party/nix/src/libutil/xml-writer.cc @@ -26,10 +26,10 @@ void XMLWriter::indent_(size_t depth) { if (!indent) { return; } - output << string(depth * 2, ' '); + output << std::string(depth * 2, ' '); } -void XMLWriter::openElement(const string& name, const XMLAttrs& attrs) { +void XMLWriter::openElement(const std::string& name, const XMLAttrs& attrs) { assert(!closed); indent_(pendingElems.size()); output << "<" << name; @@ -54,7 +54,8 @@ void XMLWriter::closeElement() { } } -void XMLWriter::writeEmptyElement(const string& name, const XMLAttrs& attrs) { +void XMLWriter::writeEmptyElement(const std::string& name, + const XMLAttrs& attrs) { assert(!closed); indent_(pendingElems.size()); output << "<" << name; diff --git a/third_party/nix/src/libutil/xml-writer.hh b/third_party/nix/src/libutil/xml-writer.hh index 3a2d9a66d8e1..76f3c7e3a2f4 100644 --- a/third_party/nix/src/libutil/xml-writer.hh +++ b/third_party/nix/src/libutil/xml-writer.hh @@ -11,7 +11,7 @@ using std::list; using std::map; using std::string; -typedef map<string, string> XMLAttrs; +typedef map<std::string, std::string> XMLAttrs; class XMLWriter { private: @@ -20,7 +20,7 @@ class XMLWriter { bool indent; bool closed; - list<string> pendingElems; + std::list<std::string> pendingElems; public: XMLWriter(bool indent, std::ostream& output); @@ -28,10 +28,10 @@ class XMLWriter { void close(); - void openElement(const string& name, const XMLAttrs& attrs = XMLAttrs()); + void openElement(const std::string& name, const XMLAttrs& attrs = XMLAttrs()); void closeElement(); - void writeEmptyElement(const string& name, + void writeEmptyElement(const std::string& name, const XMLAttrs& attrs = XMLAttrs()); private: @@ -45,7 +45,7 @@ class XMLOpenElement { XMLWriter& writer; public: - XMLOpenElement(XMLWriter& writer, const string& name, + XMLOpenElement(XMLWriter& writer, const std::string& name, const XMLAttrs& attrs = XMLAttrs()) : writer(writer) { writer.openElement(name, attrs); diff --git a/third_party/nix/src/nix-build/nix-build.cc b/third_party/nix/src/nix-build/nix-build.cc index a98603f35109..6906a805830e 100644 --- a/third_party/nix/src/nix-build/nix-build.cc +++ b/third_party/nix/src/nix-build/nix-build.cc @@ -27,10 +27,10 @@ using namespace std::string_literals; /* Recreate the effect of the perl shellwords function, breaking up a * string into arguments like a shell word, including escapes */ -std::vector<string> shellwords(const string& s) { +std::vector<std::string> shellwords(const std::string& s) { std::regex whitespace("^(\\s+).*"); auto begin = s.cbegin(); - std::vector<string> res; + std::vector<std::string> res; std::string cur; enum state { sBegin, sQuote }; state st = sBegin; @@ -90,14 +90,14 @@ static void _main(int argc, char** argv) { auto inShebang = false; std::string script; - std::vector<string> savedArgs; + std::vector<std::string> savedArgs; AutoDelete tmpDir(createTempDir("", myName)); std::string outLink = "./result"; // List of environment variables kept for --pure - std::set<string> keepVars{ + std::set<std::string> keepVars{ "HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM", "IN_NIX_SHELL", "TZ", "PAGER", "NIX_BUILD_SHELL", "SHLVL"}; @@ -405,7 +405,7 @@ static void _main(int argc, char** argv) { // Build or fetch all dependencies of the derivation. for (const auto& input : drv.inputDrvs) { if (std::all_of(envExclude.cbegin(), envExclude.cend(), - [&](const string& exclude) { + [&](const std::string& exclude) { return !std::regex_search(input.first, std::regex(exclude)); })) { @@ -452,7 +452,7 @@ static void _main(int argc, char** argv) { for (auto& var : drv.env) { if (passAsFile.count(var.first) != 0u) { keepTmp = true; - string fn = ".attr-" + std::to_string(fileNr++); + std::string fn = ".attr-" + std::to_string(fileNr++); Path p = (Path)tmpDir + "/" + fn; writeFile(p, var.second); env[var.first + "Path"] = p; @@ -489,7 +489,7 @@ static void _main(int argc, char** argv) { (Path)tmpDir, (pure ? "" : "p=$PATH; "), (pure ? "" : "PATH=$PATH:$p; unset p; "), dirOf(shell), shell, (getenv("TZ") != nullptr - ? (string("export TZ='") + getenv("TZ") + "'; ") + ? (std::string("export TZ='") + getenv("TZ") + "'; ") : ""), envCommand)); diff --git a/third_party/nix/src/nix-channel/nix-channel.cc b/third_party/nix/src/nix-channel/nix-channel.cc index 1a094f8cdb35..04a492d80a03 100644 --- a/third_party/nix/src/nix-channel/nix-channel.cc +++ b/third_party/nix/src/nix-channel/nix-channel.cc @@ -12,7 +12,7 @@ using namespace nix; -typedef std::map<string, string> Channels; +typedef std::map<std::string, std::string> Channels; static Channels channels; static Path channelsList; @@ -25,12 +25,12 @@ static void readChannels() { auto channelsFile = readFile(channelsList); for (const auto& line : - tokenizeString<std::vector<string>>(channelsFile, "\n")) { + tokenizeString<std::vector<std::string>>(channelsFile, "\n")) { absl::StripTrailingAsciiWhitespace(line); if (std::regex_search(line, std::regex("^\\s*\\#"))) { continue; } - auto split = tokenizeString<std::vector<string>>(line, " "); + auto split = tokenizeString<std::vector<std::string>>(line, " "); auto url = std::regex_replace(split[0], std::regex("/*$"), ""); auto name = split.size() > 1 ? split[1] : baseNameOf(url); channels[name] = url; @@ -50,7 +50,7 @@ static void writeChannels() { } // Adds a channel. -static void addChannel(const string& url, const string& name) { +static void addChannel(const std::string& url, const std::string& name) { if (!regex_search(url, std::regex("^(file|http|https)://"))) { throw Error(format("invalid channel URL '%1%'") % url); } @@ -65,7 +65,7 @@ static void addChannel(const string& url, const string& name) { static Path profile; // Remove a channel. -static void removeChannel(const string& name) { +static void removeChannel(const std::string& name) { readChannels(); channels.erase(name); writeChannels(); @@ -109,7 +109,7 @@ static void update(const StringSet& channelNames) { std::smatch match; auto urlBase = baseNameOf(url); if (std::regex_search(urlBase, match, std::regex("(-\\d.*)$"))) { - cname = cname + (string)match[1]; + cname = cname + (std::string)match[1]; } std::string extraAttrs; @@ -188,7 +188,7 @@ static int _main(int argc, char** argv) { getUserName()); enum { cNone, cAdd, cRemove, cList, cUpdate, cRollback } cmd = cNone; - std::vector<string> args; + std::vector<std::string> args; parseCmdLine(argc, argv, [&](Strings::iterator& arg, const Strings::iterator& end) { if (*arg == "--help") { diff --git a/third_party/nix/src/nix-collect-garbage/nix-collect-garbage.cc b/third_party/nix/src/nix-collect-garbage/nix-collect-garbage.cc index 0050bdda15fb..548e492664de 100644 --- a/third_party/nix/src/nix-collect-garbage/nix-collect-garbage.cc +++ b/third_party/nix/src/nix-collect-garbage/nix-collect-garbage.cc @@ -40,7 +40,7 @@ void removeOldGenerations(const std::string& dir) { continue; } } - if (link.find("link") != string::npos) { + if (link.find("link") != std::string::npos) { LOG(INFO) << "removing old generations of profile " << path; if (!deleteOlderThan.empty()) { deleteGenerationsOlderThan(path, deleteOlderThan, dryRun); diff --git a/third_party/nix/src/nix-daemon/nix-daemon.cc b/third_party/nix/src/nix-daemon/nix-daemon.cc index 5a38e023fa9b..5b62d67dbe1c 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon.cc @@ -115,7 +115,7 @@ struct TunnelLogger { /* stopWork() means that we're done; stop sending stderr to the client. */ - void stopWork(bool success = true, const string& msg = "", + void stopWork(bool success = true, const std::string& msg = "", unsigned int status = 0) { auto state(state_.lock()); @@ -175,7 +175,7 @@ struct TunnelSource : BufferedSource { the contents of the file to `s'. Otherwise barf. */ struct RetrieveRegularNARSink : ParseSink { bool regular{true}; - string s; + std::string s; RetrieveRegularNARSink() {} @@ -185,7 +185,7 @@ struct RetrieveRegularNARSink : ParseSink { s.append((const char*)data, len); } - void createSymlink(const Path& path, const string& target) override { + void createSymlink(const Path& path, const std::string& target) override { regular = false; } }; @@ -286,7 +286,7 @@ static void performOp(TunnelLogger* logger, const ref<Store>& store, } case wopQueryPathFromHashPart: { - string hashPart = readString(from); + std::string hashPart = readString(from); logger->startWork(); Path path = store->queryPathFromHashPart(hashPart); logger->stopWork(); @@ -340,8 +340,8 @@ static void performOp(TunnelLogger* logger, const ref<Store>& store, } case wopAddTextToStore: { - string suffix = readString(from); - string s = readString(from); + std::string suffix = readString(from); + std::string s = readString(from); auto refs = readStorePaths<PathSet>(*store, from); logger->startWork(); Path path = store->addTextToStore(suffix, s, refs, NoRepair); @@ -505,8 +505,8 @@ static void performOp(TunnelLogger* logger, const ref<Store>& store, if (GET_PROTOCOL_MINOR(clientVersion) >= 12) { unsigned int n = readInt(from); for (unsigned int i = 0; i < n; i++) { - string name = readString(from); - string value = readString(from); + std::string name = readString(from); + std::string value = readString(from); overrides.emplace(name, value); } } @@ -855,7 +855,8 @@ static void setSigChldAction(bool autoReap) { } } -bool matchUser(const string& user, const string& group, const Strings& users) { +bool matchUser(const std::string& user, const std::string& group, + const Strings& users) { if (find(users.begin(), users.end(), "*") != users.end()) { return true; } @@ -865,8 +866,8 @@ bool matchUser(const string& user, const string& group, const Strings& users) { } for (auto& i : users) { - if (string(i, 0, 1) == "@") { - if (group == string(i, 1)) { + if (std::string(i, 0, 1) == "@") { + if (group == std::string(i, 1)) { return true; } struct group* gr = getgrnam(i.c_str() + 1); @@ -874,7 +875,7 @@ bool matchUser(const string& user, const string& group, const Strings& users) { continue; } for (char** mem = gr->gr_mem; *mem != nullptr; mem++) { - if (user == string(*mem)) { + if (user == std::string(*mem)) { return true; } } @@ -953,7 +954,7 @@ static void daemonLoop(char** argv) { throw SysError("cannot create Unix domain socket"); } - string socketPath = settings.nixDaemonSocketFile; + std::string socketPath = settings.nixDaemonSocketFile; createDirs(dirOf(socketPath)); @@ -1018,10 +1019,11 @@ static void daemonLoop(char** argv) { PeerInfo peer = getPeerInfo(remote.get()); struct passwd* pw = peer.uidKnown ? getpwuid(peer.uid) : nullptr; - string user = pw != nullptr ? pw->pw_name : std::to_string(peer.uid); + std::string user = pw != nullptr ? pw->pw_name : std::to_string(peer.uid); struct group* gr = peer.gidKnown ? getgrgid(peer.gid) : nullptr; - string group = gr != nullptr ? gr->gr_name : std::to_string(peer.gid); + std::string group = + gr != nullptr ? gr->gr_name : std::to_string(peer.gid); Strings trustedUsers = settings.trustedUsers; Strings allowedUsers = settings.allowedUsers; @@ -1062,7 +1064,7 @@ static void daemonLoop(char** argv) { /* For debugging, stuff the pid into argv[1]. */ if (peer.pidKnown && (argv[1] != nullptr)) { - string processName = std::to_string(peer.pid); + std::string processName = std::to_string(peer.pid); strncpy(argv[1], processName.c_str(), strlen(argv[1])); } diff --git a/third_party/nix/src/nix-env/nix-env.cc b/third_party/nix/src/nix-env/nix-env.cc index e5b76979245d..794250e603b1 100644 --- a/third_party/nix/src/nix-env/nix-env.cc +++ b/third_party/nix/src/nix-env/nix-env.cc @@ -40,9 +40,9 @@ typedef enum { struct InstallSourceInfo { InstallSourceType type; - Path nixExprPath; /* for srcNixExprDrvs, srcNixExprs */ - Path profile; /* for srcProfile */ - string systemFilter; /* for srcNixExprDrvs */ + Path nixExprPath; /* for srcNixExprDrvs, srcNixExprs */ + Path profile; /* for srcProfile */ + std::string systemFilter; /* for srcNixExprDrvs */ Bindings* autoArgs; }; @@ -53,13 +53,14 @@ struct Globals { bool dryRun; bool preserveInstalled; bool removeAll; - string forceName; + std::string forceName; bool prebuiltOnly; }; using Operation = void (*)(Globals&, Strings, Strings); -static string needArg(Strings::iterator& i, Strings& args, const string& arg) { +static std::string needArg(Strings::iterator& i, Strings& args, + const std::string& arg) { if (i == args.end()) { throw UsageError(format("'%1%' requires an argument") % arg); } @@ -67,7 +68,7 @@ static string needArg(Strings::iterator& i, Strings& args, const string& arg) { } static bool parseInstallSourceOptions(Globals& globals, Strings::iterator& i, - Strings& args, const string& arg) { + Strings& args, const std::string& arg) { if (arg == "--from-expression" || arg == "-E") { globals.instSource.type = srcNixExprs; } else if (arg == "--from-profile") { @@ -114,9 +115,9 @@ static void getAllExprs(EvalState& state, const Path& path, StringSet& attrs, otherwise the attribute cannot be selected with the `-A' option. Useful if you want to stick a Nix expression directly in ~/.nix-defexpr. */ - string attrName = i; + std::string attrName = i; if (hasSuffix(attrName, ".nix")) { - attrName = string(attrName, 0, attrName.size() - 4); + attrName = std::string(attrName, 0, attrName.size() - 4); } if (attrs.find(attrName) != attrs.end()) { LOG(WARNING) << "name collision in input Nix expressions, skipping '" @@ -167,8 +168,8 @@ static void loadSourceExpr(EvalState& state, const Path& path, Value& v) { } static void loadDerivations(EvalState& state, const Path& nixExprPath, - const string& systemFilter, Bindings& autoArgs, - const string& pathPrefix, DrvInfos& elems) { + const std::string& systemFilter, Bindings& autoArgs, + const std::string& pathPrefix, DrvInfos& elems) { Value vRoot; loadSourceExpr(state, nixExprPath, vRoot); @@ -223,10 +224,10 @@ static DrvInfos filterBySelector(EvalState& state, const DrvInfos& allElems, } DrvInfos elems; - set<unsigned int> done; + std::set<unsigned int> done; for (auto& i : selectors) { - typedef list<std::pair<DrvInfo, unsigned int> > Matches; + typedef std::list<std::pair<DrvInfo, unsigned int> > Matches; Matches matches; unsigned int n = 0; for (auto j = allElems.begin(); j != allElems.end(); ++j, ++n) { @@ -246,7 +247,7 @@ static DrvInfos filterBySelector(EvalState& state, const DrvInfos& allElems, arbitrarily pick the first one. */ if (newestOnly) { /* Map from package names to derivations. */ - typedef map<string, std::pair<DrvInfo, unsigned int> > Newest; + typedef map<std::string, std::pair<DrvInfo, unsigned int> > Newest; Newest newest; StringSet multiple; @@ -308,7 +309,9 @@ static DrvInfos filterBySelector(EvalState& state, const DrvInfos& allElems, return elems; } -static bool isPath(const string& s) { return s.find('/') != string::npos; } +static bool isPath(const std::string& s) { + return s.find('/') != std::string::npos; +} static void queryInstSources(EvalState& state, InstallSourceInfo& instSource, const Strings& args, DrvInfos& elems, @@ -364,10 +367,10 @@ static void queryInstSources(EvalState& state, InstallSourceInfo& instSource, for (auto& i : args) { Path path = state.store->followLinksToStorePath(i); - string name = baseNameOf(path); - string::size_type dash = name.find('-'); - if (dash != string::npos) { - name = string(name, dash + 1); + std::string name = baseNameOf(path); + std::string::size_type dash = name.find('-'); + if (dash != std::string::npos) { + name = std::string(name, dash + 1); } DrvInfo elem(state, "", nullptr); @@ -378,8 +381,9 @@ static void queryInstSources(EvalState& state, InstallSourceInfo& instSource, elem.setOutPath( state.store->derivationFromPath(path).findOutput("out")); if (name.size() >= drvExtension.size() && - string(name, name.size() - drvExtension.size()) == drvExtension) { - name = string(name, 0, name.size() - drvExtension.size()); + std::string(name, name.size() - drvExtension.size()) == + drvExtension) { + name = std::string(name, 0, name.size() - drvExtension.size()); } } else { elem.setOutPath(path); @@ -457,7 +461,7 @@ static void installDerivations(Globals& globals, const Strings& args, } while (true) { - string lockToken = optimisticLockProfile(profile); + std::string lockToken = optimisticLockProfile(profile); DrvInfos allElems(newElems); @@ -496,7 +500,7 @@ static void installDerivations(Globals& globals, const Strings& args, static void opInstall(Globals& globals, Strings opFlags, Strings opArgs) { for (auto i = opFlags.begin(); i != opFlags.end();) { - string arg = *i++; + std::string arg = *i++; if (parseInstallSourceOptions(globals, i, opFlags, arg)) { ; } else if (arg == "--preserve-installed" || arg == "-P") { @@ -523,7 +527,7 @@ static void upgradeDerivations(Globals& globals, const Strings& args, name and a higher version number. */ while (true) { - string lockToken = optimisticLockProfile(globals.profile); + std::string lockToken = optimisticLockProfile(globals.profile); DrvInfos installedElems = queryInstalled(*globals.state, globals.profile); @@ -551,7 +555,7 @@ static void upgradeDerivations(Globals& globals, const Strings& args, take the one with the highest version. Do not upgrade if it would decrease the priority. */ auto bestElem = availElems.end(); - string bestVersion; + std::string bestVersion; for (auto j = availElems.begin(); j != availElems.end(); ++j) { if (comparePriorities(*globals.state, i, *j) > 0) { continue; @@ -614,7 +618,7 @@ static void upgradeDerivations(Globals& globals, const Strings& args, static void opUpgrade(Globals& globals, Strings opFlags, Strings opArgs) { UpgradeType upgradeType = utLt; for (auto i = opFlags.begin(); i != opFlags.end();) { - string arg = *i++; + std::string arg = *i++; if (parseInstallSourceOptions(globals, i, opFlags, arg)) { ; } else if (arg == "--lt") { @@ -633,8 +637,8 @@ static void opUpgrade(Globals& globals, Strings opFlags, Strings opArgs) { upgradeDerivations(globals, opArgs, upgradeType); } -static void setMetaFlag(EvalState& state, DrvInfo& drv, const string& name, - const string& value) { +static void setMetaFlag(EvalState& state, DrvInfo& drv, const std::string& name, + const std::string& value) { Value* v = state.allocValue(); mkString(*v, value.c_str()); drv.setMeta(name, v); @@ -649,12 +653,12 @@ static void opSetFlag(Globals& globals, Strings opFlags, Strings opArgs) { } auto arg = opArgs.begin(); - string flagName = *arg++; - string flagValue = *arg++; + std::string flagName = *arg++; + std::string flagValue = *arg++; DrvNames selectors = drvNamesFromArgs(Strings(arg, opArgs.end())); while (true) { - string lockToken = optimisticLockProfile(globals.profile); + std::string lockToken = optimisticLockProfile(globals.profile); DrvInfos installedElems = queryInstalled(*globals.state, globals.profile); @@ -688,7 +692,7 @@ static void opSet(Globals& globals, Strings opFlags, Strings opArgs) { } for (auto i = opFlags.begin(); i != opFlags.end();) { - string arg = *i++; + std::string arg = *i++; if (parseInstallSourceOptions(globals, i, opFlags, arg)) { ; } else { @@ -734,7 +738,7 @@ static void opSet(Globals& globals, Strings opFlags, Strings opArgs) { static void uninstallDerivations(Globals& globals, Strings& selectors, Path& profile) { while (true) { - string lockToken = optimisticLockProfile(profile); + std::string lockToken = optimisticLockProfile(profile); DrvInfos installedElems = queryInstalled(*globals.state, profile); DrvInfos newElems; @@ -786,12 +790,12 @@ static bool cmpElemByName(const DrvInfo& a, const DrvInfo& b) { b_name.end(), cmpChars); } -using Table = list<Strings>; +using Table = std::list<Strings>; void printTable(Table& table) { auto nrColumns = !table.empty() ? table.front().size() : 0; - vector<size_t> widths; + std::vector<size_t> widths; widths.resize(nrColumns); for (auto& i : table) { @@ -809,11 +813,11 @@ void printTable(Table& table) { Strings::iterator j; size_t column; for (j = i.begin(), column = 0; j != i.end(); ++j, ++column) { - string s = *j; + std::string s = *j; replace(s.begin(), s.end(), '\n', ' '); cout << s; if (column < nrColumns - 1) { - cout << string(widths[column] - s.size() + 2, ' '); + cout << std::string(widths[column] - s.size() + 2, ' '); } } cout << std::endl; @@ -831,7 +835,7 @@ typedef enum { cvLess, cvEqual, cvGreater, cvUnavail } VersionDiff; static VersionDiff compareVersionAgainstSet(const DrvInfo& elem, const DrvInfos& elems, - string& version) { + std::string& version) { DrvName name(elem.queryName()); VersionDiff diff = cvUnavail; @@ -859,7 +863,7 @@ static VersionDiff compareVersionAgainstSet(const DrvInfo& elem, return diff; } -static void queryJSON(Globals& globals, vector<DrvInfo>& elems) { +static void queryJSON(Globals& globals, std::vector<DrvInfo>& elems) { JSONObject topObj(cout, true); for (auto& i : elems) { JSONObject pkgObj = topObj.object(i.attrPath); @@ -889,7 +893,7 @@ static void queryJSON(Globals& globals, vector<DrvInfo>& elems) { static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { Strings remaining; - string attrPath; + std::string attrPath; bool printStatus = false; bool printName = true; @@ -908,7 +912,7 @@ static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { settings.readOnlyMode = true; /* makes evaluation a bit faster */ for (auto i = opFlags.begin(); i != opFlags.end();) { - string arg = *i++; + std::string arg = *i++; if (arg == "--status" || arg == "-s") { printStatus = true; } else if (arg == "--no-name") { @@ -964,7 +968,7 @@ static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { /* Sort them by name. */ /* !!! */ - vector<DrvInfo> elems; + std::vector<DrvInfo> elems; for (auto& i : elems_) { elems.push_back(i); } @@ -1045,7 +1049,7 @@ static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { attrs["valid"] = isValid ? "1" : "0"; attrs["substitutable"] = hasSubs ? "1" : "0"; } else { - columns.push_back((string)(isInstalled ? "I" : "-") + + columns.push_back((std::string)(isInstalled ? "I" : "-") + (isValid ? "P" : "-") + (hasSubs ? "S" : "-")); } } @@ -1070,7 +1074,7 @@ static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { same named packages in either the set of available elements, or the set of installed elements. !!! This is O(N * M), should be O(N * lg M). */ - string version; + std::string version; VersionDiff diff = compareVersionAgainstSet(i, otherElems, version); char ch; @@ -1097,7 +1101,7 @@ static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { attrs["maxComparedVersion"] = version; } } else { - string column = (string) "" + ch + " " + version; + std::string column = (std::string) "" + ch + " " + version; if (diff == cvGreater && tty) { column = ANSI_RED + column + ANSI_NORMAL; } @@ -1114,7 +1118,7 @@ static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { } if (printDrvPath) { - string drvPath = i.queryDrvPath(); + std::string drvPath = i.queryDrvPath(); if (xmlOutput) { if (!drvPath.empty()) { attrs["drvPath"] = drvPath; @@ -1126,7 +1130,7 @@ static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { if (printOutPath && !xmlOutput) { DrvInfo::Outputs outputs = i.queryOutputs(); - string s; + std::string s; for (auto& j : outputs) { if (!s.empty()) { s += ';'; @@ -1141,7 +1145,7 @@ static void opQuery(Globals& globals, Strings opFlags, Strings opArgs) { } if (printDescription) { - string descr = i.queryMetaString("description"); + std::string descr = i.queryMetaString("description"); if (xmlOutput) { if (!descr.empty()) { attrs["description"] = descr; @@ -1354,14 +1358,16 @@ static void opDeleteGenerations(Globals& globals, Strings opFlags, if (opArgs.size() == 1 && opArgs.front() == "old") { deleteOldGenerations(globals.profile, globals.dryRun); - } else if (opArgs.size() == 1 && opArgs.front().find('d') != string::npos) { + } else if (opArgs.size() == 1 && + opArgs.front().find('d') != std::string::npos) { deleteGenerationsOlderThan(globals.profile, opArgs.front(), globals.dryRun); - } else if (opArgs.size() == 1 && opArgs.front().find('+') != string::npos) { + } else if (opArgs.size() == 1 && + opArgs.front().find('+') != std::string::npos) { if (opArgs.front().size() < 2) { throw Error(format("invalid number of generations ‘%1%’") % opArgs.front()); } - string str_max = string(opArgs.front(), 1, opArgs.front().size()); + string str_max = std::string(opArgs.front(), 1, opArgs.front().size()); int max; if (!string2Int(str_max, max) || max == 0) { throw Error(format("invalid number of generations to keep ‘%1%’") % @@ -1391,7 +1397,7 @@ static int _main(int argc, char** argv) { Strings opArgs; Operation op = nullptr; RepairFlag repair = NoRepair; - string file; + std::string file; Globals globals; diff --git a/third_party/nix/src/nix-env/user-env.cc b/third_party/nix/src/nix-env/user-env.cc index 2ca56ed96620..c8eee4aac09b 100644 --- a/third_party/nix/src/nix-env/user-env.cc +++ b/third_party/nix/src/nix-env/user-env.cc @@ -26,7 +26,7 @@ DrvInfos queryInstalled(EvalState& state, const Path& userEnv) { } bool createUserEnv(EvalState& state, DrvInfos& elems, const Path& profile, - bool keepDerivations, const string& lockToken) { + bool keepDerivations, const std::string& lockToken) { /* Build the components in the user environment, if they don't exist already. */ PathSet drvsToBuild; diff --git a/third_party/nix/src/nix-env/user-env.hh b/third_party/nix/src/nix-env/user-env.hh index 6111b21c353d..a117d5c2ad67 100644 --- a/third_party/nix/src/nix-env/user-env.hh +++ b/third_party/nix/src/nix-env/user-env.hh @@ -7,6 +7,6 @@ namespace nix { DrvInfos queryInstalled(EvalState& state, const Path& userEnv); bool createUserEnv(EvalState& state, DrvInfos& elems, const Path& profile, - bool keepDerivations, const string& lockToken); + bool keepDerivations, const std::string& lockToken); } // namespace nix diff --git a/third_party/nix/src/nix-instantiate/nix-instantiate.cc b/third_party/nix/src/nix-instantiate/nix-instantiate.cc index 95e5341ade4a..8e1c7afe1c91 100644 --- a/third_party/nix/src/nix-instantiate/nix-instantiate.cc +++ b/third_party/nix/src/nix-instantiate/nix-instantiate.cc @@ -62,7 +62,7 @@ void processExpr(EvalState& state, const Strings& attrPaths, bool parseOnly, Path drvPath = i.queryDrvPath(); /* What output do we want? */ - string outputName = i.queryOutputName(); + std::string outputName = i.queryOutputName(); if (outputName.empty()) { throw Error( format("derivation '%1%' lacks an 'outputName' attribute ") % diff --git a/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc b/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc index fa88dc9bc67e..a2cd570986e8 100644 --- a/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc +++ b/third_party/nix/src/nix-prefetch-url/nix-prefetch-url.cc @@ -20,17 +20,17 @@ using namespace nix; /* If ‘uri’ starts with ‘mirror://’, then resolve it using the list of mirrors defined in Nixpkgs. */ -string resolveMirrorUri(EvalState& state, string uri) { - if (string(uri, 0, 9) != "mirror://") { +std::string resolveMirrorUri(EvalState& state, std::string uri) { + if (std::string(uri, 0, 9) != "mirror://") { return uri; } - string s(uri, 9); + std::string s(uri, 9); auto p = s.find('/'); - if (p == string::npos) { + if (p == std::string::npos) { throw Error("invalid mirror URI"); } - string mirrorName(s, 0, p); + std::string mirrorName(s, 0, p); Value vMirrors; state.eval( @@ -49,19 +49,20 @@ string resolveMirrorUri(EvalState& state, string uri) { throw Error(format("mirror URI '%1%' did not expand to anything") % uri); } - string mirror = state.forceString(*mirrorList->second.value->listElems()[0]); - return mirror + (hasSuffix(mirror, "/") ? "" : "/") + string(s, p + 1); + std::string mirror = + state.forceString(*mirrorList->second.value->listElems()[0]); + return mirror + (hasSuffix(mirror, "/") ? "" : "/") + std::string(s, p + 1); } static int _main(int argc, char** argv) { { HashType ht = htSHA256; - std::vector<string> args; + std::vector<std::string> args; bool printPath = !getEnv("PRINT_PATH").empty(); bool fromExpr = false; - string attrPath; + std::string attrPath; bool unpack = false; - string name; + std::string name; struct MyArgs : LegacyArgs, MixEvalArgs { using LegacyArgs::LegacyArgs; @@ -74,7 +75,7 @@ static int _main(int argc, char** argv) { } else if (*arg == "--version") { printVersion("nix-prefetch-url"); } else if (*arg == "--type") { - string s = getArg(*arg, arg, end); + std::string s = getArg(*arg, arg, end); ht = parseHashType(s); if (ht == htUnknown) { throw UsageError(format("unknown hash type '%1%'") % s); @@ -111,7 +112,7 @@ static int _main(int argc, char** argv) { /* If -A is given, get the URI from the specified Nix expression. */ - string uri; + std::string uri; if (!fromExpr) { if (args.empty()) { throw UsageError("you must specify a URI"); diff --git a/third_party/nix/src/nix-store/dotgraph.cc b/third_party/nix/src/nix-store/dotgraph.cc index 0186a7b22ebd..ef335bb5318d 100644 --- a/third_party/nix/src/nix-store/dotgraph.cc +++ b/third_party/nix/src/nix-store/dotgraph.cc @@ -9,23 +9,23 @@ using std::cout; namespace nix { -static string dotQuote(const string& s) { return "\"" + s + "\""; } +static std::string dotQuote(const std::string& s) { return "\"" + s + "\""; } -static string nextColour() { +static std::string nextColour() { static int n = 0; - static string colours[] = {"black", "red", "green", - "blue", "magenta", "burlywood"}; - return colours[n++ % (sizeof(colours) / sizeof(string))]; + static std::string colours[] = {"black", "red", "green", + "blue", "magenta", "burlywood"}; + return colours[n++ % (sizeof(colours) / sizeof(std::string))]; } -static string makeEdge(const string& src, const string& dst) { +static std::string makeEdge(const std::string& src, const std::string& dst) { format f = format("%1% -> %2% [color = %3%];\n") % dotQuote(src) % dotQuote(dst) % dotQuote(nextColour()); return f.str(); } -static string makeNode(const string& id, const string& label, - const string& colour) { +static std::string makeNode(const std::string& id, const std::string& label, + const std::string& colour) { format f = format( "%1% [label = %2%, shape = box, " "style = filled, fillcolor = %3%];\n") % @@ -33,15 +33,15 @@ static string makeNode(const string& id, const string& label, return f.str(); } -static string symbolicName(const string& path) { - string p = baseNameOf(path); - return string(p, p.find('-') + 1); +static std::string symbolicName(const std::string& path) { + std::string p = baseNameOf(path); + return std::string(p, p.find('-') + 1); } #if 0 -string pathLabel(const Path & nePath, const string & elemPath) +std::string pathLabel(const Path & nePath, const std::string & elemPath) { - return (string) nePath + "-" + elemPath; + return (std::string) nePath + "-" + elemPath; } diff --git a/third_party/nix/src/nix-store/graphml.cc b/third_party/nix/src/nix-store/graphml.cc index a1a16cc8f28a..86b1c6b94231 100644 --- a/third_party/nix/src/nix-store/graphml.cc +++ b/third_party/nix/src/nix-store/graphml.cc @@ -10,23 +10,23 @@ using std::cout; namespace nix { -static inline const string& xmlQuote(const string& s) { +static inline const std::string& xmlQuote(const std::string& s) { // Luckily, store paths shouldn't contain any character that needs to be // quoted. return s; } -static string symbolicName(const string& path) { - string p = baseNameOf(path); - return string(p, p.find('-') + 1); +static std::string symbolicName(const std::string& path) { + std::string p = baseNameOf(path); + return std::string(p, p.find('-') + 1); } -static string makeEdge(const string& src, const string& dst) { +static std::string makeEdge(const std::string& src, const std::string& dst) { return fmt(" <edge source=\"%1%\" target=\"%2%\"/>\n", xmlQuote(src), xmlQuote(dst)); } -static string makeNode(const ValidPathInfo& info) { +static std::string makeNode(const ValidPathInfo& info) { return fmt( " <node id=\"%1%\">\n" " <data key=\"narSize\">%2%</data>\n" diff --git a/third_party/nix/src/nix-store/nix-store.cc b/third_party/nix/src/nix-store/nix-store.cc index 40d6f01cd96c..713439308ae8 100644 --- a/third_party/nix/src/nix-store/nix-store.cc +++ b/third_party/nix/src/nix-store/nix-store.cc @@ -252,8 +252,8 @@ static void opPrintFixedPath(Strings opFlags, Strings opArgs) { auto i = opArgs.begin(); HashType hashAlgo = parseHashType(*i++); - string hash = *i++; - string name = *i++; + std::string hash = *i++; + std::string name = *i++; cout << format("%1%\n") % store->makeFixedOutputPath(recursive, Hash(hash, hashAlgo), name); @@ -279,12 +279,12 @@ static PathSet maybeUseOutputs(const Path& storePath, bool useOutput, graph. Topological sorting is used to keep the tree relatively flat. */ -const string treeConn = "+---"; -const string treeLine = "| "; -const string treeNull = " "; +const std::string treeConn = "+---"; +const std::string treeLine = "| "; +const std::string treeNull = " "; -static void printTree(const Path& path, const string& firstPad, - const string& tailPad, PathSet& done) { +static void printTree(const Path& path, const std::string& firstPad, + const std::string& tailPad, PathSet& done) { if (done.find(path) != done.end()) { cout << format("%1%%2% [...]\n") % firstPad % path; return; @@ -334,7 +334,7 @@ static void opQuery(Strings opFlags, Strings opArgs) { bool useOutput = false; bool includeOutputs = false; bool forceRealise = false; - string bindingName; + std::string bindingName; for (auto& i : opFlags) { QueryType prev = query; @@ -776,7 +776,7 @@ static void opDump(Strings opFlags, Strings opArgs) { } FdSink sink(STDOUT_FILENO); - string path = *opArgs.begin(); + std::string path = *opArgs.begin(); dumpPath(path, sink); sink.flush(); } @@ -1154,9 +1154,9 @@ static void opGenerateBinaryCacheKey(Strings opFlags, Strings opArgs) { throw UsageError("three arguments expected"); } auto i = opArgs.begin(); - string keyName = *i++; - string secretKeyFile = *i++; - string publicKeyFile = *i++; + std::string keyName = *i++; + std::string secretKeyFile = *i++; + std::string publicKeyFile = *i++; #if HAVE_SODIUM if (sodium_init() == -1) { @@ -1169,13 +1169,13 @@ static void opGenerateBinaryCacheKey(Strings opFlags, Strings opArgs) { throw Error("key generation failed"); } - writeFile(publicKeyFile, - keyName + ":" + - base64Encode(string((char*)pk, crypto_sign_PUBLICKEYBYTES))); + writeFile(publicKeyFile, keyName + ":" + + base64Encode(std::string( + (char*)pk, crypto_sign_PUBLICKEYBYTES))); umask(0077); - writeFile(secretKeyFile, - keyName + ":" + - base64Encode(string((char*)sk, crypto_sign_SECRETKEYBYTES))); + writeFile(secretKeyFile, keyName + ":" + + base64Encode(std::string( + (char*)sk, crypto_sign_SECRETKEYBYTES))); #else throw Error( "Nix was not compiled with libsodium, required for signed binary cache " diff --git a/third_party/nix/src/nix/command.cc b/third_party/nix/src/nix/command.cc index 439f22dc3b67..34fcde80033e 100644 --- a/third_party/nix/src/nix/command.cc +++ b/third_party/nix/src/nix/command.cc @@ -9,7 +9,7 @@ namespace nix { Commands* RegisterCommand::commands = nullptr; -void Command::printHelp(const string& programName, std::ostream& out) { +void Command::printHelp(const std::string& programName, std::ostream& out) { Args::printHelp(programName, out); auto exs = examples(); @@ -37,7 +37,8 @@ MultiCommand::MultiCommand(Commands _commands) }}); } -void MultiCommand::printHelp(const string& programName, std::ostream& out) { +void MultiCommand::printHelp(const std::string& programName, + std::ostream& out) { if (command) { command->printHelp(programName + " " + command->name(), out); return; diff --git a/third_party/nix/src/nix/command.hh b/third_party/nix/src/nix/command.hh index 4122bdd0e58f..c297bfbd38dd 100644 --- a/third_party/nix/src/nix/command.hh +++ b/third_party/nix/src/nix/command.hh @@ -27,7 +27,7 @@ struct Command : virtual Args { virtual Examples examples() { return Examples(); } - void printHelp(const string& programName, std::ostream& out) override; + void printHelp(const std::string& programName, std::ostream& out) override; }; class Store; @@ -151,7 +151,7 @@ class MultiCommand : virtual Args { MultiCommand(Commands commands); - void printHelp(const string& programName, std::ostream& out) override; + void printHelp(const std::string& programName, std::ostream& out) override; bool processFlag(Strings::iterator& pos, Strings::iterator end) override; diff --git a/third_party/nix/src/nix/hash.cc b/third_party/nix/src/nix/hash.cc index 74ff45d0d84e..c500dc4f3ca6 100644 --- a/third_party/nix/src/nix/hash.cc +++ b/third_party/nix/src/nix/hash.cc @@ -106,7 +106,7 @@ static int compatNixHash(int argc, char** argv) { } else if (*arg == "--truncate") { truncate = true; } else if (*arg == "--type") { - string s = getArg(*arg, arg, end); + std::string s = getArg(*arg, arg, end); ht = parseHashType(s); if (ht == htUnknown) { throw UsageError(format("unknown hash type '%1%'") % s); diff --git a/third_party/nix/src/nix/main.cc b/third_party/nix/src/nix/main.cc index 11ba3f8410c4..59782388087a 100644 --- a/third_party/nix/src/nix/main.cc +++ b/third_party/nix/src/nix/main.cc @@ -129,7 +129,7 @@ void mainWrapped(int argc, char** argv) { initGC(); programPath = argv[0]; - string programName = baseNameOf(programPath); + std::string programName = baseNameOf(programPath); { auto legacy = (*RegisterLegacyCommand::commands)[programName]; diff --git a/third_party/nix/src/nix/repl.cc b/third_party/nix/src/nix/repl.cc index 5db9468fdc0a..e2e4de6fec1b 100644 --- a/third_party/nix/src/nix/repl.cc +++ b/third_party/nix/src/nix/repl.cc @@ -46,7 +46,7 @@ namespace nix { #define ESC_END "\033[0m" struct NixRepl { - string curDir; + std::string curDir; EvalState state; Bindings* autoArgs; @@ -63,19 +63,19 @@ struct NixRepl { NixRepl(const Strings& searchPath, const nix::ref<Store>& store); ~NixRepl(); void mainLoop(const std::vector<std::string>& files); - StringSet completePrefix(const string& prefix); - static bool getLine(string& input, const std::string& prompt); + StringSet completePrefix(const std::string& prefix); + static bool getLine(std::string& input, const std::string& prompt); Path getDerivationPath(Value& v); - bool processLine(string line); + bool processLine(std::string line); void loadFile(const Path& path); void initEnv(); void reloadFiles(); void addAttrsToScope(Value& attrs); void addVarToScope(const Symbol& name, Value& v); - Expr* parseString(const string& s); - void evalString(string s, Value& v); + Expr* parseString(const std::string& s); + void evalString(std::string s, Value& v); - using ValuesSeen = set<Value*>; + using ValuesSeen = std::set<Value*>; std::ostream& printValue(std::ostream& str, Value& v, unsigned int maxDepth); std::ostream& printValue(std::ostream& str, Value& v, unsigned int maxDepth, ValuesSeen& seen); @@ -122,11 +122,11 @@ void printHelp() { << " at least a file named default.nix.\n"; } -string removeWhitespace(string s) { +std::string removeWhitespace(std::string s) { s = absl::StripTrailingAsciiWhitespace(s); size_t n = s.find_first_not_of(" \n\r\t"); - if (n != string::npos) { - s = string(s, n); + if (n != std::string::npos) { + s = std::string(s, n); } return s; } @@ -224,7 +224,7 @@ void sigintHandler(int signo) { g_signal_received = signo; } } // namespace void NixRepl::mainLoop(const std::vector<std::string>& files) { - string error = ANSI_RED "error:" ANSI_NORMAL " "; + std::string error = ANSI_RED "error:" ANSI_NORMAL " "; std::cout << "Welcome to Nix version " << nixVersion << ". Type :? for help." << std::endl << std::endl; @@ -285,7 +285,7 @@ void NixRepl::mainLoop(const std::vector<std::string>& files) { } } -bool NixRepl::getLine(string& input, const std::string& prompt) { +bool NixRepl::getLine(std::string& input, const std::string& prompt) { struct sigaction act; struct sigaction old; sigset_t savedSignalMask; @@ -334,7 +334,7 @@ bool NixRepl::getLine(string& input, const std::string& prompt) { return true; } -StringSet NixRepl::completePrefix(const string& prefix) { +StringSet NixRepl::completePrefix(const std::string& prefix) { StringSet completions; size_t start = prefix.find_last_of(" \n\r\t(){}[]"); @@ -351,7 +351,7 @@ StringSet NixRepl::completePrefix(const string& prefix) { size_t slash; size_t dot; - if ((slash = cur.rfind('/')) != string::npos) { + if ((slash = cur.rfind('/')) != std::string::npos) { try { auto dir = std::string(cur, 0, slash); auto prefix2 = std::string(cur, slash + 1); @@ -362,11 +362,11 @@ StringSet NixRepl::completePrefix(const string& prefix) { } } catch (Error&) { } - } else if ((dot = cur.rfind('.')) == string::npos) { + } else if ((dot = cur.rfind('.')) == std::string::npos) { /* This is a variable name; look it up in the current scope. */ auto i = varNames.lower_bound(cur); while (i != varNames.end()) { - if (string(*i, 0, cur.size()) != cur) { + if (std::string(*i, 0, cur.size()) != cur) { break; } completions.insert(prev + *i); @@ -377,8 +377,8 @@ StringSet NixRepl::completePrefix(const string& prefix) { /* This is an expression that should evaluate to an attribute set. Evaluate it to get the names of the attributes. */ - string expr(cur, 0, dot); - string cur2 = string(cur, dot + 1); + std::string expr(cur, 0, dot); + std::string cur2 = std::string(cur, dot + 1); Expr* e = parseString(expr); Value v; @@ -386,8 +386,8 @@ StringSet NixRepl::completePrefix(const string& prefix) { state.forceAttrs(v); for (auto& i : *v.attrs) { - string name = i.second.name; - if (string(name, 0, cur2.size()) != cur2) { + std::string name = i.second.name; + if (std::string(name, 0, cur2.size()) != cur2) { continue; } completions.insert(prev + expr + "." + name); @@ -405,7 +405,7 @@ StringSet NixRepl::completePrefix(const string& prefix) { return completions; } -static int runProgram(const string& program, const Strings& args) { +static int runProgram(const std::string& program, const Strings& args) { Strings args2(args); args2.push_front(program); @@ -423,7 +423,7 @@ static int runProgram(const string& program, const Strings& args) { return pid.wait(); } -bool isVarName(const string& s) { +bool isVarName(const std::string& s) { if (s.empty()) { return false; } @@ -453,19 +453,19 @@ Path NixRepl::getDerivationPath(Value& v) { return drvPath; } -bool NixRepl::processLine(string line) { +bool NixRepl::processLine(std::string line) { if (line.empty()) { return true; } - string command; - string arg; + std::string command; + std::string arg; if (line[0] == ':') { size_t p = line.find_first_of(" \n\r\t"); - command = string(line, 0, p); - if (p != string::npos) { - arg = removeWhitespace(string(line, p)); + command = std::string(line, 0, p); + if (p != std::string::npos) { + arg = removeWhitespace(std::string(line, p)); } } else { arg = line; @@ -567,10 +567,10 @@ bool NixRepl::processLine(string line) { } else { size_t p = line.find('='); - string name; - if (p != string::npos && p < line.size() && line[p + 1] != '=' && - isVarName(name = removeWhitespace(string(line, 0, p)))) { - Expr* e = parseString(string(line, p + 1)); + std::string name; + if (p != std::string::npos && p < line.size() && line[p + 1] != '=' && + isVarName(name = removeWhitespace(std::string(line, 0, p)))) { + Expr* e = parseString(std::string(line, p + 1)); Value& v(*state.allocValue()); v.type = tThunk; v.thunk.env = env; @@ -640,15 +640,15 @@ void NixRepl::addVarToScope(const Symbol& name, Value& v) { } staticEnv.vars[name] = displ; env->values[displ++] = &v; - varNames.insert((string)name); + varNames.insert((std::string)name); } -Expr* NixRepl::parseString(const string& s) { +Expr* NixRepl::parseString(const std::string& s) { Expr* e = state.parseExprFromString(s, curDir, staticEnv); return e; } -void NixRepl::evalString(string s, Value& v) { +void NixRepl::evalString(std::string s, Value& v) { Expr* e = parseString(std::move(s)); e->eval(state, *env, v); state.forceValue(v); @@ -729,7 +729,7 @@ std::ostream& NixRepl::printValue(std::ostream& str, Value& v, else if (maxDepth > 0) { str << "{ "; - typedef std::map<string, Value*> Sorted; + typedef std::map<std::string, Value*> Sorted; Sorted sorted; for (auto& i : *v.attrs) { sorted[i.second.name] = i.second.value; diff --git a/third_party/nix/src/nix/why-depends.cc b/third_party/nix/src/nix/why-depends.cc index bbbfd1fe0182..9c5eaf737c03 100644 --- a/third_party/nix/src/nix/why-depends.cc +++ b/third_party/nix/src/nix/why-depends.cc @@ -133,16 +133,18 @@ struct CmdWhyDepends : SourceExprCommand { closure (i.e., that have a non-infinite distance to 'dependency'). Print every edge on a path between `package` and `dependency`. */ - std::function<void(Node&, const string&, const string&)> printNode; + std::function<void(Node&, const std::string&, const std::string&)> + printNode; - const string treeConn = "╠═══"; - const string treeLast = "╚═══"; - const string treeLine = "║ "; - const string treeNull = " "; + const std::string treeConn = "╠═══"; + const std::string treeLast = "╚═══"; + const std::string treeLine = "║ "; + const std::string treeNull = " "; struct BailOut {}; - printNode = [&](Node& node, const string& firstPad, const string& tailPad) { + printNode = [&](Node& node, const std::string& firstPad, + const std::string& tailPad) { assert(node.dist != inf); std::cout << fmt("%s%s%s%s" ANSI_NORMAL "\n", firstPad, node.visited ? "\e[38;5;244m" : "", |