refactor(3p/nix/libutil): Replace hasPrefix/Suffix with Abseil
Uses the equivalent absl::StartsWith and absl::EndsWith functions instead.
This commit is contained in:
parent
8cf1322a6f
commit
b99b368d17
21 changed files with 69 additions and 57 deletions
|
@ -1,5 +1,6 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
#include <fcntl.h>
|
||||
#include <glog/logging.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -56,10 +57,10 @@ static void createLinks(const Path& srcDir, const Path& dstDir, int priority) {
|
|||
* Python package brings its own
|
||||
* `$out/lib/pythonX.Y/site-packages/easy-install.pth'.)
|
||||
*/
|
||||
if (hasSuffix(srcFile, "/propagated-build-inputs") ||
|
||||
hasSuffix(srcFile, "/nix-support") ||
|
||||
hasSuffix(srcFile, "/perllocal.pod") ||
|
||||
hasSuffix(srcFile, "/info/dir") || hasSuffix(srcFile, "/log"))
|
||||
if (absl::EndsWith(srcFile, "/propagated-build-inputs") ||
|
||||
absl::EndsWith(srcFile, "/nix-support") ||
|
||||
absl::EndsWith(srcFile, "/perllocal.pod") ||
|
||||
absl::EndsWith(srcFile, "/info/dir") || absl::EndsWith(srcFile, "/log"))
|
||||
continue;
|
||||
|
||||
else if (S_ISDIR(srcSt.st_mode)) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <absl/strings/match.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "archive.hh"
|
||||
|
@ -41,7 +42,7 @@ void builtinFetchurl(const BasicDerivation& drv, const std::string& netrcData) {
|
|||
request.decompress = false;
|
||||
|
||||
auto decompressor = makeDecompressionSink(
|
||||
unpack && hasSuffix(mainUrl, ".xz") ? "xz" : "none", sink);
|
||||
unpack && absl::EndsWith(mainUrl, ".xz") ? "xz" : "none", sink);
|
||||
downloader->download(std::move(request), *decompressor);
|
||||
decompressor->finish();
|
||||
});
|
||||
|
@ -61,7 +62,7 @@ void builtinFetchurl(const BasicDerivation& drv, const std::string& netrcData) {
|
|||
/* Try the hashed mirrors first. */
|
||||
if (getAttr("outputHashMode") == "flat")
|
||||
for (auto hashedMirror : settings.hashedMirrors.get()) try {
|
||||
if (!hasSuffix(hashedMirror, "/")) {
|
||||
if (!absl::EndsWith(hashedMirror, "/")) {
|
||||
hashedMirror += '/';
|
||||
}
|
||||
auto ht = parseHashType(getAttr("outputHashAlgo"));
|
||||
|
|
4
third_party/nix/src/libstore/derivations.cc
vendored
4
third_party/nix/src/libstore/derivations.cc
vendored
|
@ -1,5 +1,7 @@
|
|||
#include "derivations.hh"
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
|
||||
#include "fs-accessor.hh"
|
||||
#include "globals.hh"
|
||||
#include "istringstream_nocopy.hh"
|
||||
|
@ -299,7 +301,7 @@ std::string Derivation::unparse() const {
|
|||
}
|
||||
|
||||
bool isDerivation(const std::string& fileName) {
|
||||
return hasSuffix(fileName, drvExtension);
|
||||
return absl::EndsWith(fileName, drvExtension);
|
||||
}
|
||||
|
||||
bool BasicDerivation::isFixedOutput() const {
|
||||
|
|
7
third_party/nix/src/libstore/download.cc
vendored
7
third_party/nix/src/libstore/download.cc
vendored
|
@ -1,6 +1,7 @@
|
|||
#include "download.hh"
|
||||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/numbers.h>
|
||||
|
||||
#include "archive.hh"
|
||||
|
@ -653,8 +654,8 @@ struct CurlDownloader : public Downloader {
|
|||
}
|
||||
|
||||
void enqueueItem(const std::shared_ptr<DownloadItem>& item) {
|
||||
if (item->request.data && !hasPrefix(item->request.uri, "http://") &&
|
||||
!hasPrefix(item->request.uri, "https://")) {
|
||||
if (item->request.data && !absl::StartsWith(item->request.uri, "http://") &&
|
||||
!absl::StartsWith(item->request.uri, "https://")) {
|
||||
throw nix::Error("uploading to '%s' is not supported", item->request.uri);
|
||||
}
|
||||
|
||||
|
@ -690,7 +691,7 @@ struct CurlDownloader : public Downloader {
|
|||
void enqueueDownload(const DownloadRequest& request,
|
||||
Callback<DownloadResult> callback) override {
|
||||
/* Ugly hack to support s3:// URIs. */
|
||||
if (hasPrefix(request.uri, "s3://")) {
|
||||
if (absl::StartsWith(request.uri, "s3://")) {
|
||||
// FIXME: do this on a worker thread
|
||||
try {
|
||||
#ifdef ENABLE_S3
|
||||
|
|
3
third_party/nix/src/libstore/gc.cc
vendored
3
third_party/nix/src/libstore/gc.cc
vendored
|
@ -6,6 +6,7 @@
|
|||
#include <random>
|
||||
#include <regex>
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
@ -512,7 +513,7 @@ struct LocalStore::GCState {
|
|||
|
||||
bool LocalStore::isActiveTempFile(const GCState& state, const Path& path,
|
||||
const std::string& suffix) {
|
||||
return hasSuffix(path, suffix) &&
|
||||
return absl::EndsWith(path, suffix) &&
|
||||
state.tempRoots.find(std::string(
|
||||
path, 0, path.size() - suffix.size())) != state.tempRoots.end();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <utility>
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
|
||||
#include "binary-cache-store.hh"
|
||||
#include "globals.hh"
|
||||
#include "nar-info-disk-cache.hh"
|
||||
|
@ -39,7 +41,7 @@ class LocalBinaryCacheStore : public BinaryCacheStore {
|
|||
PathSet paths;
|
||||
|
||||
for (auto& entry : readDirectory(binaryCacheDir)) {
|
||||
if (entry.name.size() != 40 || !hasSuffix(entry.name, ".narinfo")) {
|
||||
if (entry.name.size() != 40 || !absl::EndsWith(entry.name, ".narinfo")) {
|
||||
continue;
|
||||
}
|
||||
paths.insert(storeDir + "/" +
|
||||
|
|
8
third_party/nix/src/libstore/machines.cc
vendored
8
third_party/nix/src/libstore/machines.cc
vendored
|
@ -3,6 +3,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
|
@ -21,9 +22,10 @@ Machine::Machine(decltype(storeUri)& storeUri,
|
|||
// Backwards compatibility: if the URI is a hostname,
|
||||
// prepend ssh://.
|
||||
storeUri.find("://") != std::string::npos ||
|
||||
hasPrefix(storeUri, "local") ||
|
||||
hasPrefix(storeUri, "remote") ||
|
||||
hasPrefix(storeUri, "auto") || hasPrefix(storeUri, "/")
|
||||
absl::StartsWith(storeUri, "local") ||
|
||||
absl::StartsWith(storeUri, "remote") ||
|
||||
absl::StartsWith(storeUri, "auto") ||
|
||||
absl::StartsWith(storeUri, "/")
|
||||
? storeUri
|
||||
: "ssh://" + storeUri),
|
||||
systemTypes(systemTypes),
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "s3-binary-cache-store.hh"
|
||||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/match.h>
|
||||
#include <aws/core/Aws.h>
|
||||
#include <aws/core/VersionConfig.h>
|
||||
#include <aws/core/auth/AWSCredentialsProvider.h>
|
||||
|
@ -347,12 +348,12 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore {
|
|||
|
||||
void upsertFile(const std::string& path, const std::string& data,
|
||||
const std::string& mimeType) override {
|
||||
if (narinfoCompression != "" && hasSuffix(path, ".narinfo"))
|
||||
if (narinfoCompression != "" && absl::EndsWith(path, ".narinfo"))
|
||||
uploadFile(path, *compress(narinfoCompression, data), mimeType,
|
||||
narinfoCompression);
|
||||
else if (lsCompression != "" && hasSuffix(path, ".ls"))
|
||||
else if (lsCompression != "" && absl::EndsWith(path, ".ls"))
|
||||
uploadFile(path, *compress(lsCompression, data), mimeType, lsCompression);
|
||||
else if (logCompression != "" && hasPrefix(path, "log/"))
|
||||
else if (logCompression != "" && absl::StartsWith(path, "log/"))
|
||||
uploadFile(path, *compress(logCompression, data), mimeType,
|
||||
logCompression);
|
||||
else
|
||||
|
@ -400,7 +401,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore {
|
|||
|
||||
for (auto object : contents) {
|
||||
auto& key = object.GetKey();
|
||||
if (key.size() != 40 || !hasSuffix(key, ".narinfo")) {
|
||||
if (key.size() != 40 || !absl::EndsWith(key, ".narinfo")) {
|
||||
continue;
|
||||
}
|
||||
paths.insert(storeDir + "/" + key.substr(0, key.size() - 8));
|
||||
|
|
4
third_party/nix/src/libstore/ssh.cc
vendored
4
third_party/nix/src/libstore/ssh.cc
vendored
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
|
||||
namespace nix {
|
||||
|
||||
SSHMaster::SSHMaster(const std::string& host, std::string keyFile,
|
||||
|
@ -12,7 +14,7 @@ SSHMaster::SSHMaster(const std::string& host, std::string keyFile,
|
|||
useMaster(useMaster && !fakeSSH),
|
||||
compress(compress),
|
||||
logFD(logFD) {
|
||||
if (host.empty() || hasPrefix(host, "-")) {
|
||||
if (host.empty() || absl::StartsWith(host, "-")) {
|
||||
throw Error("invalid SSH host name '%s'", host);
|
||||
}
|
||||
}
|
||||
|
|
9
third_party/nix/src/libstore/store-api.cc
vendored
9
third_party/nix/src/libstore/store-api.cc
vendored
|
@ -3,6 +3,7 @@
|
|||
#include <future>
|
||||
#include <utility>
|
||||
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/numbers.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
|
@ -771,7 +772,7 @@ bool ValidPathInfo::isContentAddressed(const Store& store) const {
|
|||
<< "' claims to be content-addressed but isn't";
|
||||
};
|
||||
|
||||
if (hasPrefix(ca, "text:")) {
|
||||
if (absl::StartsWith(ca, "text:")) {
|
||||
Hash hash(std::string(ca, 5));
|
||||
if (store.makeTextPath(storePathToName(path), hash, references) == path) {
|
||||
return true;
|
||||
|
@ -780,7 +781,7 @@ bool ValidPathInfo::isContentAddressed(const Store& store) const {
|
|||
|
||||
}
|
||||
|
||||
else if (hasPrefix(ca, "fixed:")) {
|
||||
else if (absl::StartsWith(ca, "fixed:")) {
|
||||
bool recursive = ca.compare(6, 2, "r:") == 0;
|
||||
Hash hash(std::string(ca, recursive ? 8 : 6));
|
||||
if (references.empty() &&
|
||||
|
@ -906,7 +907,7 @@ StoreType getStoreType(const std::string& uri, const std::string& stateDir) {
|
|||
if (uri == "daemon") {
|
||||
return tDaemon;
|
||||
}
|
||||
if (uri == "local" || hasPrefix(uri, "/")) {
|
||||
if (uri == "local" || absl::StartsWith(uri, "/")) {
|
||||
return tLocal;
|
||||
} else if (uri.empty() || uri == "auto") {
|
||||
if (access(stateDir.c_str(), R_OK | W_OK) == 0) {
|
||||
|
@ -930,7 +931,7 @@ static RegisterStoreImplementation regStore([](const std::string& uri,
|
|||
return std::shared_ptr<Store>(std::make_shared<UDSRemoteStore>(params));
|
||||
case tLocal: {
|
||||
Store::Params params2 = params;
|
||||
if (hasPrefix(uri, "/")) {
|
||||
if (absl::StartsWith(uri, "/")) {
|
||||
params2["root"] = uri;
|
||||
}
|
||||
return std::shared_ptr<Store>(std::make_shared<LocalStore>(params2));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue