forked from lix-project/lix
DownloadError -> DataTransferError
This commit is contained in:
parent
213d124277
commit
c4c1ae0a00
|
@ -690,7 +690,7 @@ std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathEl
|
||||||
try {
|
try {
|
||||||
res = { true, store->toRealPath(fetchers::downloadTarball(
|
res = { true, store->toRealPath(fetchers::downloadTarball(
|
||||||
store, resolveUri(elem.second), "source", false).storePath) };
|
store, resolveUri(elem.second), "source", false).storePath) };
|
||||||
} catch (DownloadError & e) {
|
} catch (DataTransferError & e) {
|
||||||
printError(format("warning: Nix search path entry '%1%' cannot be downloaded, ignoring") % elem.second);
|
printError(format("warning: Nix search path entry '%1%' cannot be downloaded, ignoring") % elem.second);
|
||||||
res = { false, "" };
|
res = { false, "" };
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ struct curlDataTransfer : public DataTransfer
|
||||||
if (requestHeaders) curl_slist_free_all(requestHeaders);
|
if (requestHeaders) curl_slist_free_all(requestHeaders);
|
||||||
try {
|
try {
|
||||||
if (!done)
|
if (!done)
|
||||||
fail(DownloadError(Interrupted, format("download of '%s' was interrupted") % request.uri));
|
fail(DataTransferError(Interrupted, format("download of '%s' was interrupted") % request.uri));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ignoreException();
|
ignoreException();
|
||||||
}
|
}
|
||||||
|
@ -401,14 +401,14 @@ struct curlDataTransfer : public DataTransfer
|
||||||
|
|
||||||
auto exc =
|
auto exc =
|
||||||
code == CURLE_ABORTED_BY_CALLBACK && _isInterrupted
|
code == CURLE_ABORTED_BY_CALLBACK && _isInterrupted
|
||||||
? DownloadError(Interrupted, fmt("%s of '%s' was interrupted", request.verb(), request.uri))
|
? DataTransferError(Interrupted, fmt("%s of '%s' was interrupted", request.verb(), request.uri))
|
||||||
: httpStatus != 0
|
: httpStatus != 0
|
||||||
? DownloadError(err,
|
? DataTransferError(err,
|
||||||
fmt("unable to %s '%s': HTTP error %d",
|
fmt("unable to %s '%s': HTTP error %d",
|
||||||
request.verb(), request.uri, httpStatus)
|
request.verb(), request.uri, httpStatus)
|
||||||
+ (code == CURLE_OK ? "" : fmt(" (curl error: %s)", curl_easy_strerror(code)))
|
+ (code == CURLE_OK ? "" : fmt(" (curl error: %s)", curl_easy_strerror(code)))
|
||||||
)
|
)
|
||||||
: DownloadError(err,
|
: DataTransferError(err,
|
||||||
fmt("unable to %s '%s': %s (%d)",
|
fmt("unable to %s '%s': %s (%d)",
|
||||||
request.verb(), request.uri, curl_easy_strerror(code), code));
|
request.verb(), request.uri, curl_easy_strerror(code), code));
|
||||||
|
|
||||||
|
@ -662,7 +662,7 @@ struct curlDataTransfer : public DataTransfer
|
||||||
auto s3Res = s3Helper.getObject(bucketName, key);
|
auto s3Res = s3Helper.getObject(bucketName, key);
|
||||||
DataTransferResult res;
|
DataTransferResult res;
|
||||||
if (!s3Res.data)
|
if (!s3Res.data)
|
||||||
throw DownloadError(NotFound, fmt("S3 object '%s' does not exist", request.uri));
|
throw DataTransferError(NotFound, fmt("S3 object '%s' does not exist", request.uri));
|
||||||
res.data = s3Res.data;
|
res.data = s3Res.data;
|
||||||
callback(std::move(res));
|
callback(std::move(res));
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -72,7 +72,7 @@ struct DataTransfer
|
||||||
virtual ~DataTransfer() { }
|
virtual ~DataTransfer() { }
|
||||||
|
|
||||||
/* Enqueue a data transfer request, returning a future to the result of
|
/* Enqueue a data transfer request, returning a future to the result of
|
||||||
the download. The future may throw a DownloadError
|
the download. The future may throw a DataTransferError
|
||||||
exception. */
|
exception. */
|
||||||
virtual void enqueueDataTransfer(const DataTransferRequest & request,
|
virtual void enqueueDataTransfer(const DataTransferRequest & request,
|
||||||
Callback<DataTransferResult> callback) = 0;
|
Callback<DataTransferResult> callback) = 0;
|
||||||
|
@ -96,11 +96,11 @@ ref<DataTransfer> getDataTransfer();
|
||||||
/* Return a new DataTransfer object. */
|
/* Return a new DataTransfer object. */
|
||||||
ref<DataTransfer> makeDataTransfer();
|
ref<DataTransfer> makeDataTransfer();
|
||||||
|
|
||||||
class DownloadError : public Error
|
class DataTransferError : public Error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DataTransfer::Error error;
|
DataTransfer::Error error;
|
||||||
DownloadError(DataTransfer::Error error, const FormatOrString & fs)
|
DataTransferError(DataTransfer::Error error, const FormatOrString & fs)
|
||||||
: Error(fs), error(error)
|
: Error(fs), error(error)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
|
@ -89,7 +89,7 @@ protected:
|
||||||
request.head = true;
|
request.head = true;
|
||||||
getDataTransfer()->download(request);
|
getDataTransfer()->download(request);
|
||||||
return true;
|
return true;
|
||||||
} catch (DownloadError & e) {
|
} catch (DataTransferError & e) {
|
||||||
/* S3 buckets return 403 if a file doesn't exist and the
|
/* S3 buckets return 403 if a file doesn't exist and the
|
||||||
bucket is unlistable, so treat 403 as 404. */
|
bucket is unlistable, so treat 403 as 404. */
|
||||||
if (e.error == DataTransfer::NotFound || e.error == DataTransfer::Forbidden)
|
if (e.error == DataTransfer::NotFound || e.error == DataTransfer::Forbidden)
|
||||||
|
@ -108,7 +108,7 @@ protected:
|
||||||
req.mimeType = mimeType;
|
req.mimeType = mimeType;
|
||||||
try {
|
try {
|
||||||
getDataTransfer()->download(req);
|
getDataTransfer()->download(req);
|
||||||
} catch (DownloadError & e) {
|
} catch (DataTransferError & e) {
|
||||||
throw UploadToHTTP("while uploading to HTTP binary cache at '%s': %s", cacheUri, e.msg());
|
throw UploadToHTTP("while uploading to HTTP binary cache at '%s': %s", cacheUri, e.msg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ protected:
|
||||||
auto request(makeRequest(path));
|
auto request(makeRequest(path));
|
||||||
try {
|
try {
|
||||||
getDataTransfer()->download(std::move(request), sink);
|
getDataTransfer()->download(std::move(request), sink);
|
||||||
} catch (DownloadError & e) {
|
} catch (DataTransferError & e) {
|
||||||
if (e.error == DataTransfer::NotFound || e.error == DataTransfer::Forbidden)
|
if (e.error == DataTransfer::NotFound || e.error == DataTransfer::Forbidden)
|
||||||
throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri());
|
throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri());
|
||||||
maybeDisable();
|
maybeDisable();
|
||||||
|
@ -146,7 +146,7 @@ protected:
|
||||||
{[callbackPtr, this](std::future<DataTransferResult> result) {
|
{[callbackPtr, this](std::future<DataTransferResult> result) {
|
||||||
try {
|
try {
|
||||||
(*callbackPtr)(result.get().data);
|
(*callbackPtr)(result.get().data);
|
||||||
} catch (DownloadError & e) {
|
} catch (DataTransferError & e) {
|
||||||
if (e.error == DataTransfer::NotFound || e.error == DataTransfer::Forbidden)
|
if (e.error == DataTransfer::NotFound || e.error == DataTransfer::Forbidden)
|
||||||
return (*callbackPtr)(std::shared_ptr<std::string>());
|
return (*callbackPtr)(std::shared_ptr<std::string>());
|
||||||
maybeDisable();
|
maybeDisable();
|
||||||
|
|
|
@ -113,7 +113,7 @@ static void update(const StringSet & channelNames)
|
||||||
// Download the channel tarball.
|
// Download the channel tarball.
|
||||||
try {
|
try {
|
||||||
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.xz", "nixexprs.tar.xz", false).storePath);
|
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.xz", "nixexprs.tar.xz", false).storePath);
|
||||||
} catch (DownloadError & e) {
|
} catch (DataTransferError & e) {
|
||||||
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2", false).storePath);
|
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2", false).storePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue