From df552ff53e68dff8ca360adbdbea214ece1d08ee Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 25 Feb 2022 16:00:00 +0100 Subject: Remove std::string alias (for real this time) Also use std::string_view in a few more places. --- src/libutil/archive.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/libutil/archive.cc') diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc index fdee643b1..eda004756 100644 --- a/src/libutil/archive.cc +++ b/src/libutil/archive.cc @@ -37,7 +37,7 @@ static GlobalConfig::Register rArchiveSettings(&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 &) { return true; }; @@ -84,12 +84,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 unhacked; + std::map 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) { debug(format("removing case hack suffix from '%1%'") % (path + "/" + i.name)); name.erase(pos); } @@ -124,13 +124,13 @@ void dumpPath(const Path & path, Sink & sink, PathFilter & filter) } -void dumpString(const std::string & s, Sink & sink) +void dumpString(std::string_view s, Sink & sink) { sink << narVersionMagic1 << "(" << "type" << "regular" << "contents" << s << ")"; } -static SerialisationError badArchive(string s) +static SerialisationError badArchive(const std::string & s) { return SerialisationError("bad archive: " + s); } @@ -171,7 +171,7 @@ 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; } @@ -180,7 +180,7 @@ struct CaseInsensitiveCompare static void parse(ParseSink & sink, Source & source, const Path & path) { - string s; + std::string s; s = readString(source); if (s != "(") throw badArchive("expected open tag"); @@ -201,7 +201,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path) else if (s == "type") { if (type != tpUnknown) throw badArchive("multiple type fields"); - string t = readString(source); + std::string t = readString(source); if (t == "regular") { type = tpRegular; @@ -232,7 +232,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path) } else if (s == "entry" && type == tpDirectory) { - string name, prevName; + std::string name, prevName; s = readString(source); if (s != "(") throw badArchive("expected open tag"); @@ -246,7 +246,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path) break; } else if (s == "name") { name = readString(source); - if (name.empty() || name == "." || name == ".." || name.find('/') != string::npos || name.find((char) 0) != string::npos) + if (name.empty() || name == "." || name == ".." || name.find('/') != std::string::npos || name.find((char) 0) != std::string::npos) throw Error("NAR contains invalid file name '%1%'", name); if (name <= prevName) throw Error("NAR directory is not sorted"); @@ -269,7 +269,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); } @@ -281,7 +281,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) { @@ -345,7 +345,7 @@ struct RestoreSink : ParseSink writeFull(fd.get(), data); } - 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); -- cgit v1.2.3