diff options
-rw-r--r-- | src/libstore/binary-cache-store.cc | 8 | ||||
-rw-r--r-- | src/libstore/binary-cache-store.hh | 4 | ||||
-rw-r--r-- | src/libstore/http-binary-cache-store.cc | 4 | ||||
-rw-r--r-- | src/libstore/local-binary-cache-store.cc | 8 | ||||
-rw-r--r-- | src/libstore/s3-binary-cache-store.cc | 14 |
5 files changed, 25 insertions, 13 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 804e3f6aa..d8e68fd58 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -97,7 +97,7 @@ void BinaryCacheStore::init() auto cacheInfo = getFile(cacheInfoFile); if (!cacheInfo) { - upsertFile(cacheInfoFile, "StoreDir: " + storeDir + "\n"); + upsertFile(cacheInfoFile, "StoreDir: " + storeDir + "\n", "text/x-nix-cache-info"); } else { for (auto & line : tokenizeString<Strings>(*cacheInfo, "\n")) { size_t colon = line.find(':'); @@ -224,7 +224,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str } } - upsertFile(storePathToHash(info.path) + ".ls.xz", *compress("xz", jsonOut.str())); + upsertFile(storePathToHash(info.path) + ".ls.xz", *compress("xz", jsonOut.str()), "application/x-nix-nar-listing"); } else { @@ -254,7 +254,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str ""); if (repair || !fileExists(narInfo->url)) { stats.narWrite++; - upsertFile(narInfo->url, *narCompressed); + upsertFile(narInfo->url, *narCompressed, "application/x-nix-nar"); } else stats.narWriteAverted++; @@ -265,7 +265,7 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, const ref<std::str /* Atomically write the NAR info file.*/ if (secretKey) narInfo->sign(*secretKey); - upsertFile(narInfoFile, narInfo->to_string()); + upsertFile(narInfoFile, narInfo->to_string(), "text/x-nix-narinfo"); auto hashPart = storePathToHash(narInfo->path); diff --git a/src/libstore/binary-cache-store.hh b/src/libstore/binary-cache-store.hh index 1c287056c..d42b1abd2 100644 --- a/src/libstore/binary-cache-store.hh +++ b/src/libstore/binary-cache-store.hh @@ -31,7 +31,9 @@ public: virtual bool fileExists(const std::string & path) = 0; - virtual void upsertFile(const std::string & path, const std::string & data) = 0; + virtual void upsertFile(const std::string & path, + const std::string & data, + const std::string & mimeType) = 0; /* Return the contents of the specified file, or null if it doesn't exist. */ diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc index 9d31f77c9..37a7d6ace 100644 --- a/src/libstore/http-binary-cache-store.cc +++ b/src/libstore/http-binary-cache-store.cc @@ -64,7 +64,9 @@ protected: } } - void upsertFile(const std::string & path, const std::string & data) override + void upsertFile(const std::string & path, + const std::string & data, + const std::string & mimeType) override { throw UploadToHTTP("uploading to an HTTP binary cache is not supported"); } diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc index 0f377989b..aff22f9fc 100644 --- a/src/libstore/local-binary-cache-store.cc +++ b/src/libstore/local-binary-cache-store.cc @@ -30,7 +30,9 @@ protected: bool fileExists(const std::string & path) override; - void upsertFile(const std::string & path, const std::string & data) override; + void upsertFile(const std::string & path, + const std::string & data, + const std::string & mimeType) override; void getFile(const std::string & path, std::function<void(std::shared_ptr<std::string>)> success, @@ -83,7 +85,9 @@ bool LocalBinaryCacheStore::fileExists(const std::string & path) return pathExists(binaryCacheDir + "/" + path); } -void LocalBinaryCacheStore::upsertFile(const std::string & path, const std::string & data) +void LocalBinaryCacheStore::upsertFile(const std::string & path, + const std::string & data, + const std::string & mimeType) { atomicWrite(binaryCacheDir + "/" + path, data); } diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc index 1d44e6832..5ecf3996d 100644 --- a/src/libstore/s3-binary-cache-store.cc +++ b/src/libstore/s3-binary-cache-store.cc @@ -148,7 +148,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore : S3BinaryCacheStore(params) , bucketName(bucketName) , s3Helper(get(params, "aws-region", Aws::Region::US_EAST_1)) - , textCompression(get(params, "text-compression", "gzip")) + , textCompression(get(params, "text-compression", "")) , logCompression(get(params, "log-compression", textCompression)) { diskCache = getNarInfoDiskCache(); @@ -229,6 +229,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore } void uploadFile(const std::string & path, const std::string & data, + const std::string & mimeType, const std::string & contentEncoding) { auto request = @@ -236,6 +237,8 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore .WithBucket(bucketName) .WithKey(path); + request.SetContentType(mimeType); + if (contentEncoding != "") request.SetContentEncoding(contentEncoding); @@ -261,14 +264,15 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore stats.putTimeMs += duration; } - void upsertFile(const std::string & path, const std::string & data) override + void upsertFile(const std::string & path, const std::string & data, + const std::string & mimeType) override { if (path.find(".narinfo") != std::string::npos) - uploadFile(path, *compress(textCompression, data), textCompression); + uploadFile(path, *compress(textCompression, data), mimeType, textCompression); else if (path.find("/log") != std::string::npos) - uploadFile(path, *compress(logCompression, data), logCompression); + uploadFile(path, *compress(logCompression, data), mimeType, logCompression); else - uploadFile(path, data, ""); + uploadFile(path, data, mimeType, ""); } void getFile(const std::string & path, |