Skip to content

Commit

Permalink
url_downlaoder: Remove QNetworkDiskCache caching
Browse files Browse the repository at this point in the history
The Qt network caching doesn't work for our needs since it doesn't necessarily
get teh latest file from the server nad using "AlwaysNetwork" defeats the purpose
of caching.

In the future, custom caching will be introduced that fits Multipass's needs.

Fixes #825
  • Loading branch information
Chris Townsend committed Jun 10, 2019
1 parent a259101 commit 8013d77
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/network/url_downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,11 @@ namespace
{
constexpr auto category = "url downloader";

auto make_network_manager(const mp::Path& cache_dir_path)
// TODO: We will be using our own caching in the future due to the issue
// seen in https://github.com/CanonicalLtd/multipass/issues/825
auto make_network_manager(const mp::Path& /* cache_dir_path */)
{
auto manager = std::make_unique<QNetworkAccessManager>();

if (!cache_dir_path.isEmpty())
{
auto network_cache = new QNetworkDiskCache;
network_cache->setCacheDirectory(cache_dir_path);

// Manager now owns network_cache and so it will delete it in its dtor
manager->setCache(network_cache);
}

return manager;
return std::make_unique<QNetworkAccessManager>();
}

template <typename ProgressAction, typename DownloadAction, typename ErrorAction, typename Time>
Expand Down Expand Up @@ -101,6 +92,22 @@ mp::URLDownloader::URLDownloader(std::chrono::milliseconds timeout) : URLDownloa
mp::URLDownloader::URLDownloader(const mp::Path& cache_dir, std::chrono::milliseconds timeout)
: cache_dir_path{QDir(cache_dir).filePath("network-cache")}, timeout{timeout}
{

if (!cache_dir_path.isEmpty())
{
// Clean up old QNetworkDiskCache dirs
QDir data_dir{QDir(cache_dir_path).filePath("data8")};
if (data_dir.exists())
{
data_dir.removeRecursively();
}

QDir prepared_dir{QDir(cache_dir_path).filePath("prepared")};
if (prepared_dir.exists())
{
prepared_dir.removeRecursively();
}
}
}

void mp::URLDownloader::download_to(const QUrl& url, const QString& file_name, int64_t size, const int download_type,
Expand Down

0 comments on commit 8013d77

Please sign in to comment.