Skip to content

Commit

Permalink
[new downloader] Fix error processing when device storage is full
Browse files Browse the repository at this point in the history
  • Loading branch information
syershov committed Mar 23, 2016
1 parent 8c49302 commit ce1d37a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
23 changes: 1 addition & 22 deletions platform/http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,22 +396,6 @@ HttpRequest * HttpRequest::PostJson(string const & url, string const & postData,
return new MemoryHttpRequest(url, postData, onFinish, onProgress);
}

namespace
{
class ErrorHttpRequest : public HttpRequest
{
string m_filePath;
public:
ErrorHttpRequest(string const & filePath)
: HttpRequest(CallbackT(), CallbackT()), m_filePath(filePath)
{
m_status = EFailed;
}

virtual string const & Data() const { return m_filePath; }
};
}

HttpRequest * HttpRequest::GetFile(vector<string> const & urls,
string const & filePath, int64_t fileSize,
CallbackT const & onFinish, CallbackT const & onProgress,
Expand All @@ -425,13 +409,8 @@ HttpRequest * HttpRequest::GetFile(vector<string> const & urls,
{
// Can't create or open file for writing.
LOG(LWARNING, ("Can't create file", filePath, "with size", fileSize, e.Msg()));

// Mark the end of download with error.
ErrorHttpRequest error(filePath);
onFinish(error);

return 0;
}
return nullptr;
}

} // namespace downloader
23 changes: 23 additions & 0 deletions storage/http_map_files_downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
#include "std/bind.hpp"
#include "base/string_utils.hpp"

namespace
{
class ErrorHttpRequest : public downloader::HttpRequest
{
string m_filePath;
public:
ErrorHttpRequest(string const & filePath)
: HttpRequest(CallbackT(), CallbackT()), m_filePath(filePath)
{
m_status = EFailed;
}

virtual string const & Data() const { return m_filePath; }
};
} // anonymous namespace

namespace storage
{
HttpMapFilesDownloader::~HttpMapFilesDownloader()
Expand All @@ -33,6 +49,13 @@ void HttpMapFilesDownloader::DownloadMapFile(vector<string> const & urls, string
m_request.reset(downloader::HttpRequest::GetFile(
urls, path, size, bind(&HttpMapFilesDownloader::OnMapFileDownloaded, this, onDownloaded, _1),
bind(&HttpMapFilesDownloader::OnMapFileDownloadingProgress, this, onProgress, _1)));

if (!m_request)
{
// Mark the end of download with error.
ErrorHttpRequest error(path);
OnMapFileDownloaded(onDownloaded, error);
}
}

MapFilesDownloader::TProgress HttpMapFilesDownloader::GetDownloadingProgress()
Expand Down

0 comments on commit ce1d37a

Please sign in to comment.