aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-10-12 16:34:38 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-10-12 16:34:38 +0200
commit3a778ea8a05d7cb0e0670e3ac323f744fd136079 (patch)
tree881c3645a42be60a0ec2900e48a95cda3dde0225 /src/libstore
parent102d3d71c0c10d7b89d60981866404d656891f66 (diff)
parent0872659002d17dc7941b94075b3b9a54169d173f (diff)
Merge branch 'nix-repl-download-interruption' of https://github.com/Ma27/nix
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/filetransfer.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc
index 2cf35ec83..758862e60 100644
--- a/src/libstore/filetransfer.cc
+++ b/src/libstore/filetransfer.cc
@@ -716,15 +716,32 @@ struct curlFileTransfer : public FileTransfer
}
};
+ref<curlFileTransfer> makeCurlFileTransfer()
+{
+ return make_ref<curlFileTransfer>();
+}
+
ref<FileTransfer> getFileTransfer()
{
- static ref<FileTransfer> fileTransfer = makeFileTransfer();
+ static ref<curlFileTransfer> fileTransfer = makeCurlFileTransfer();
+
+ // this has to be done in its own scope to make sure that the lock is released
+ // before creating a new fileTransfer instance.
+ auto needsRecreation = [&]() -> bool {
+ auto state = fileTransfer->state_.lock();
+ return state->quit;
+ };
+
+ if (needsRecreation()) {
+ fileTransfer = makeCurlFileTransfer();
+ }
+
return fileTransfer;
}
ref<FileTransfer> makeFileTransfer()
{
- return make_ref<curlFileTransfer>();
+ return makeCurlFileTransfer();
}
std::future<FileTransferResult> FileTransfer::enqueueFileTransfer(const FileTransferRequest & request)