forked from OpenGamers/abaddon
fix cache writing to cwd
This commit is contained in:
parent
7c31190adc
commit
c9162544f6
@ -9,6 +9,10 @@ Cache::Cache() {
|
||||
}
|
||||
|
||||
Cache::~Cache() {
|
||||
m_canceled = true;
|
||||
for (auto &future : m_futures)
|
||||
if (future.valid()) future.get();
|
||||
|
||||
std::error_code err;
|
||||
if (!std::filesystem::remove_all(m_tmp_path, err))
|
||||
fprintf(stderr, "error removing tmp dir\n");
|
||||
@ -45,9 +49,12 @@ void Cache::GetFileFromURL(std::string url, callback_type cb) {
|
||||
} else {
|
||||
m_callbacks[url].push_back(cb);
|
||||
auto future = std::async(std::launch::async, [this, url]() {
|
||||
if (m_canceled) return;
|
||||
m_semaphore->wait();
|
||||
if (m_canceled) return;
|
||||
const auto &r = cpr::Get(cpr::Url { url });
|
||||
m_semaphore->notify();
|
||||
if (m_canceled) return;
|
||||
OnResponse(r);
|
||||
});
|
||||
m_futures.push_back(std::move(future));
|
||||
|
@ -29,4 +29,6 @@ private:
|
||||
std::unordered_map<std::string, std::vector<callback_type>> m_callbacks;
|
||||
std::vector<std::future<void>> m_futures;
|
||||
std::filesystem::path m_tmp_path;
|
||||
|
||||
bool m_canceled = false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user