Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libfetchers/git-lfs-fetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/filetransfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
Expand Down
22 changes: 11 additions & 11 deletions src/libstore/include/nix/store/filetransfer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/libstore/s3-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 (...) {
Expand All @@ -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)) {
Expand Down
8 changes: 8 additions & 0 deletions src/libutil/include/nix/util/terminal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/libutil/terminal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/nix/cat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()};
Expand Down
3 changes: 2 additions & 1 deletion src/nix/dump-path.cc
Original file line number Diff line number Diff line change
@@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/nix/ls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()};
Expand Down
Loading