Skip to content

Commit 16f0279

Browse files
authored
Merge pull request #14587 from NixOS/fix-mingw
treewide: Fix MinGW build
2 parents 7721fa6 + 8165419 commit 16f0279

File tree

10 files changed

+44
-25
lines changed

10 files changed

+44
-25
lines changed

src/libfetchers/git-lfs-fetch.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ std::vector<nlohmann::json> Fetch::fetchUrls(const std::vector<Pointer> & pointe
209209
auto url = api.endpoint + "/objects/batch";
210210
const auto & authHeader = api.authHeader;
211211
FileTransferRequest request(parseURL(url));
212-
request.method = HttpMethod::POST;
212+
request.method = HttpMethod::Post;
213213
Headers headers;
214214
if (authHeader.has_value())
215215
headers.push_back({"Authorization", *authHeader});

src/libstore/filetransfer.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,17 @@ struct curlFileTransfer : public FileTransfer
386386
if (settings.downloadSpeed.get() > 0)
387387
curl_easy_setopt(req, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) (settings.downloadSpeed.get() * 1024));
388388

389-
if (request.method == HttpMethod::HEAD)
389+
if (request.method == HttpMethod::Head)
390390
curl_easy_setopt(req, CURLOPT_NOBODY, 1);
391391

392-
if (request.method == HttpMethod::DELETE)
392+
if (request.method == HttpMethod::Delete)
393393
curl_easy_setopt(req, CURLOPT_CUSTOMREQUEST, "DELETE");
394394

395395
if (request.data) {
396-
if (request.method == HttpMethod::POST) {
396+
if (request.method == HttpMethod::Post) {
397397
curl_easy_setopt(req, CURLOPT_POST, 1L);
398398
curl_easy_setopt(req, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) request.data->sizeHint);
399-
} else if (request.method == HttpMethod::PUT) {
399+
} else if (request.method == HttpMethod::Put) {
400400
curl_easy_setopt(req, CURLOPT_UPLOAD, 1L);
401401
curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->sizeHint);
402402
} else {

src/libstore/http-binary-cache-store.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ bool HttpBinaryCacheStore::fileExists(const std::string & path)
120120

121121
try {
122122
FileTransferRequest request(makeRequest(path));
123-
request.method = HttpMethod::HEAD;
123+
request.method = HttpMethod::Head;
124124
getFileTransfer()->download(request);
125125
return true;
126126
} catch (FileTransferError & e) {
@@ -141,7 +141,7 @@ void HttpBinaryCacheStore::upload(
141141
std::optional<Headers> headers)
142142
{
143143
auto req = makeRequest(path);
144-
req.method = HttpMethod::PUT;
144+
req.method = HttpMethod::Put;
145145

146146
if (headers) {
147147
req.headers.reserve(req.headers.size() + headers->size());

src/libstore/include/nix/store/filetransfer.hh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ extern const unsigned int RETRY_TIME_MS_DEFAULT;
8787
* HTTP methods supported by FileTransfer.
8888
*/
8989
enum struct HttpMethod {
90-
GET,
91-
PUT,
92-
HEAD,
93-
POST,
94-
DELETE,
90+
Get,
91+
Put,
92+
Head,
93+
Post,
94+
Delete,
9595
};
9696

9797
/**
@@ -110,7 +110,7 @@ struct FileTransferRequest
110110
VerbatimURL uri;
111111
Headers headers;
112112
std::string expectedETag;
113-
HttpMethod method = HttpMethod::GET;
113+
HttpMethod method = HttpMethod::Get;
114114
size_t tries = fileTransferSettings.tries;
115115
unsigned int baseRetryTimeMs = RETRY_TIME_MS_DEFAULT;
116116
ActivityId parentAct;
@@ -164,14 +164,14 @@ struct FileTransferRequest
164164
std::string verb() const
165165
{
166166
switch (method) {
167-
case HttpMethod::HEAD:
168-
case HttpMethod::GET:
167+
case HttpMethod::Head:
168+
case HttpMethod::Get:
169169
return "download";
170-
case HttpMethod::PUT:
171-
case HttpMethod::POST:
170+
case HttpMethod::Put:
171+
case HttpMethod::Post:
172172
assert(data);
173173
return "upload";
174-
case HttpMethod::DELETE:
174+
case HttpMethod::Delete:
175175
return "delet";
176176
}
177177
unreachable();

src/libstore/s3-binary-cache-store.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ std::string S3BinaryCacheStore::createMultipartUpload(
295295
url.query["uploads"] = "";
296296
req.uri = VerbatimURL(url);
297297

298-
req.method = HttpMethod::POST;
298+
req.method = HttpMethod::Post;
299299
StringSource payload{std::string_view("")};
300300
req.data = {payload};
301301
req.mimeType = mimeType;
@@ -325,7 +325,7 @@ S3BinaryCacheStore::uploadPart(std::string_view key, std::string_view uploadId,
325325
}
326326

327327
auto req = makeRequest(key);
328-
req.method = HttpMethod::PUT;
328+
req.method = HttpMethod::Put;
329329
req.setupForS3();
330330

331331
auto url = req.uri.parsed();
@@ -355,7 +355,7 @@ void S3BinaryCacheStore::abortMultipartUpload(std::string_view key, std::string_
355355
auto url = req.uri.parsed();
356356
url.query["uploadId"] = uploadId;
357357
req.uri = VerbatimURL(url);
358-
req.method = HttpMethod::DELETE;
358+
req.method = HttpMethod::Delete;
359359

360360
getFileTransfer()->enqueueFileTransfer(req).get();
361361
} catch (...) {
@@ -372,7 +372,7 @@ void S3BinaryCacheStore::completeMultipartUpload(
372372
auto url = req.uri.parsed();
373373
url.query["uploadId"] = uploadId;
374374
req.uri = VerbatimURL(url);
375-
req.method = HttpMethod::POST;
375+
req.method = HttpMethod::Post;
376376

377377
std::string xml = "<CompleteMultipartUpload>";
378378
for (const auto & [idx, etag] : enumerate(partEtags)) {

src/libutil/include/nix/util/terminal.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
#include <limits>
55
#include <string>
66

7+
#include "nix/util/file-descriptor.hh"
8+
79
namespace nix {
10+
11+
/**
12+
* Determine whether \param fd is a terminal.
13+
*/
14+
bool isTTY(Descriptor fd);
15+
816
/**
917
* Determine whether ANSI escape sequences are appropriate for the
1018
* present output.

src/libutil/terminal.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ inline std::pair<int, size_t> charWidthUTF8Helper(std::string_view s)
6464

6565
namespace nix {
6666

67+
bool isTTY(Descriptor fd)
68+
{
69+
#ifndef _WIN32
70+
return isatty(fd);
71+
#else
72+
DWORD mode;
73+
return GetConsoleMode(fd, &mode);
74+
#endif
75+
}
76+
6777
bool isTTY()
6878
{
6979
static const bool tty = isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb"

src/nix/cat.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct CmdCatNar : StoreCommand, MixCat
7575

7676
void run(ref<Store> store) override
7777
{
78-
AutoCloseFD fd = open(narPath.c_str(), O_RDONLY);
78+
AutoCloseFD fd = toDescriptor(open(narPath.c_str(), O_RDONLY));
7979
if (!fd)
8080
throw SysError("opening NAR file '%s'", narPath);
8181
auto source = FdSource{fd.get()};

src/nix/dump-path.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include "nix/cmd/command.hh"
22
#include "nix/store/store-api.hh"
33
#include "nix/util/archive.hh"
4+
#include "nix/util/terminal.hh"
45

56
using namespace nix;
67

78
static FdSink getNarSink()
89
{
910
auto fd = getStandardOutput();
10-
if (isatty(fd))
11+
if (isTTY(fd))
1112
throw UsageError("refusing to write NAR to a terminal");
1213
return FdSink(std::move(fd));
1314
}

src/nix/ls.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct CmdLsNar : Command, MixLs
145145

146146
void run() override
147147
{
148-
AutoCloseFD fd = open(narPath.c_str(), O_RDONLY);
148+
AutoCloseFD fd = toDescriptor(open(narPath.c_str(), O_RDONLY));
149149
if (!fd)
150150
throw SysError("opening NAR file '%s'", narPath);
151151
auto source = FdSource{fd.get()};

0 commit comments

Comments
 (0)