mirror of
https://github.com/NixOS/nix.git
synced 2025-11-19 16:59:35 +01:00
treewide: Fix MinGW build
Several bugs to squash: - Apparently DELETE is an already used macro with Win32. We can avoid it by using Camel case instead (slightly hacky but also fits the naming convention better) - Gets rid of the raw usage of isatty. Added an isTTY impl to abstract over the raw API.
This commit is contained in:
parent
f8141a2c26
commit
8165419a0c
10 changed files with 44 additions and 25 deletions
|
|
@ -209,7 +209,7 @@ std::vector<nlohmann::json> Fetch::fetchUrls(const std::vector<Pointer> & pointe
|
|||
auto url = api.endpoint + "/objects/batch";
|
||||
const auto & authHeader = api.authHeader;
|
||||
FileTransferRequest request(parseURL(url));
|
||||
request.method = HttpMethod::POST;
|
||||
request.method = HttpMethod::Post;
|
||||
Headers headers;
|
||||
if (authHeader.has_value())
|
||||
headers.push_back({"Authorization", *authHeader});
|
||||
|
|
|
|||
|
|
@ -386,17 +386,17 @@ struct curlFileTransfer : public FileTransfer
|
|||
if (settings.downloadSpeed.get() > 0)
|
||||
curl_easy_setopt(req, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) (settings.downloadSpeed.get() * 1024));
|
||||
|
||||
if (request.method == HttpMethod::HEAD)
|
||||
if (request.method == HttpMethod::Head)
|
||||
curl_easy_setopt(req, CURLOPT_NOBODY, 1);
|
||||
|
||||
if (request.method == HttpMethod::DELETE)
|
||||
if (request.method == HttpMethod::Delete)
|
||||
curl_easy_setopt(req, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
|
||||
if (request.data) {
|
||||
if (request.method == HttpMethod::POST) {
|
||||
if (request.method == HttpMethod::Post) {
|
||||
curl_easy_setopt(req, CURLOPT_POST, 1L);
|
||||
curl_easy_setopt(req, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) request.data->sizeHint);
|
||||
} else if (request.method == HttpMethod::PUT) {
|
||||
} else if (request.method == HttpMethod::Put) {
|
||||
curl_easy_setopt(req, CURLOPT_UPLOAD, 1L);
|
||||
curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->sizeHint);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ bool HttpBinaryCacheStore::fileExists(const std::string & path)
|
|||
|
||||
try {
|
||||
FileTransferRequest request(makeRequest(path));
|
||||
request.method = HttpMethod::HEAD;
|
||||
request.method = HttpMethod::Head;
|
||||
getFileTransfer()->download(request);
|
||||
return true;
|
||||
} catch (FileTransferError & e) {
|
||||
|
|
@ -141,7 +141,7 @@ void HttpBinaryCacheStore::upload(
|
|||
std::optional<Headers> headers)
|
||||
{
|
||||
auto req = makeRequest(path);
|
||||
req.method = HttpMethod::PUT;
|
||||
req.method = HttpMethod::Put;
|
||||
|
||||
if (headers) {
|
||||
req.headers.reserve(req.headers.size() + headers->size());
|
||||
|
|
|
|||
|
|
@ -87,11 +87,11 @@ extern const unsigned int RETRY_TIME_MS_DEFAULT;
|
|||
* HTTP methods supported by FileTransfer.
|
||||
*/
|
||||
enum struct HttpMethod {
|
||||
GET,
|
||||
PUT,
|
||||
HEAD,
|
||||
POST,
|
||||
DELETE,
|
||||
Get,
|
||||
Put,
|
||||
Head,
|
||||
Post,
|
||||
Delete,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -110,7 +110,7 @@ struct FileTransferRequest
|
|||
VerbatimURL uri;
|
||||
Headers headers;
|
||||
std::string expectedETag;
|
||||
HttpMethod method = HttpMethod::GET;
|
||||
HttpMethod method = HttpMethod::Get;
|
||||
size_t tries = fileTransferSettings.tries;
|
||||
unsigned int baseRetryTimeMs = RETRY_TIME_MS_DEFAULT;
|
||||
ActivityId parentAct;
|
||||
|
|
@ -164,14 +164,14 @@ struct FileTransferRequest
|
|||
std::string verb() const
|
||||
{
|
||||
switch (method) {
|
||||
case HttpMethod::HEAD:
|
||||
case HttpMethod::GET:
|
||||
case HttpMethod::Head:
|
||||
case HttpMethod::Get:
|
||||
return "download";
|
||||
case HttpMethod::PUT:
|
||||
case HttpMethod::POST:
|
||||
case HttpMethod::Put:
|
||||
case HttpMethod::Post:
|
||||
assert(data);
|
||||
return "upload";
|
||||
case HttpMethod::DELETE:
|
||||
case HttpMethod::Delete:
|
||||
return "delet";
|
||||
}
|
||||
unreachable();
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ std::string S3BinaryCacheStore::createMultipartUpload(
|
|||
url.query["uploads"] = "";
|
||||
req.uri = VerbatimURL(url);
|
||||
|
||||
req.method = HttpMethod::POST;
|
||||
req.method = HttpMethod::Post;
|
||||
StringSource payload{std::string_view("")};
|
||||
req.data = {payload};
|
||||
req.mimeType = mimeType;
|
||||
|
|
@ -325,7 +325,7 @@ S3BinaryCacheStore::uploadPart(std::string_view key, std::string_view uploadId,
|
|||
}
|
||||
|
||||
auto req = makeRequest(key);
|
||||
req.method = HttpMethod::PUT;
|
||||
req.method = HttpMethod::Put;
|
||||
req.setupForS3();
|
||||
|
||||
auto url = req.uri.parsed();
|
||||
|
|
@ -355,7 +355,7 @@ void S3BinaryCacheStore::abortMultipartUpload(std::string_view key, std::string_
|
|||
auto url = req.uri.parsed();
|
||||
url.query["uploadId"] = uploadId;
|
||||
req.uri = VerbatimURL(url);
|
||||
req.method = HttpMethod::DELETE;
|
||||
req.method = HttpMethod::Delete;
|
||||
|
||||
getFileTransfer()->enqueueFileTransfer(req).get();
|
||||
} catch (...) {
|
||||
|
|
@ -372,7 +372,7 @@ void S3BinaryCacheStore::completeMultipartUpload(
|
|||
auto url = req.uri.parsed();
|
||||
url.query["uploadId"] = uploadId;
|
||||
req.uri = VerbatimURL(url);
|
||||
req.method = HttpMethod::POST;
|
||||
req.method = HttpMethod::Post;
|
||||
|
||||
std::string xml = "<CompleteMultipartUpload>";
|
||||
for (const auto & [idx, etag] : enumerate(partEtags)) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,15 @@
|
|||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include "nix/util/file-descriptor.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
/**
|
||||
* Determine whether \param fd is a terminal.
|
||||
*/
|
||||
bool isTTY(Descriptor fd);
|
||||
|
||||
/**
|
||||
* Determine whether ANSI escape sequences are appropriate for the
|
||||
* present output.
|
||||
|
|
|
|||
|
|
@ -64,6 +64,16 @@ inline std::pair<int, size_t> charWidthUTF8Helper(std::string_view s)
|
|||
|
||||
namespace nix {
|
||||
|
||||
bool isTTY(Descriptor fd)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return isatty(fd);
|
||||
#else
|
||||
DWORD mode;
|
||||
return GetConsoleMode(fd, &mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool isTTY()
|
||||
{
|
||||
static const bool tty = isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb"
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ struct CmdCatNar : StoreCommand, MixCat
|
|||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
AutoCloseFD fd = open(narPath.c_str(), O_RDONLY);
|
||||
AutoCloseFD fd = toDescriptor(open(narPath.c_str(), O_RDONLY));
|
||||
if (!fd)
|
||||
throw SysError("opening NAR file '%s'", narPath);
|
||||
auto source = FdSource{fd.get()};
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
#include "nix/cmd/command.hh"
|
||||
#include "nix/store/store-api.hh"
|
||||
#include "nix/util/archive.hh"
|
||||
#include "nix/util/terminal.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
static FdSink getNarSink()
|
||||
{
|
||||
auto fd = getStandardOutput();
|
||||
if (isatty(fd))
|
||||
if (isTTY(fd))
|
||||
throw UsageError("refusing to write NAR to a terminal");
|
||||
return FdSink(std::move(fd));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ struct CmdLsNar : Command, MixLs
|
|||
|
||||
void run() override
|
||||
{
|
||||
AutoCloseFD fd = open(narPath.c_str(), O_RDONLY);
|
||||
AutoCloseFD fd = toDescriptor(open(narPath.c_str(), O_RDONLY));
|
||||
if (!fd)
|
||||
throw SysError("opening NAR file '%s'", narPath);
|
||||
auto source = FdSource{fd.get()};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue