Remove failed downloaded files immediately

Especially skins were only deleted after they were requested again
This commit is contained in:
def 2020-09-22 00:51:10 +02:00
parent 9e23623fa1
commit 56b152e962
5 changed files with 28 additions and 15 deletions

View file

@ -2845,13 +2845,11 @@ void CClient::Update()
else if(m_pMapdownloadTask->State() == HTTP_ERROR)
{
dbg_msg("webdl", "http failed, falling back to gameserver");
Storage()->RemoveFile(m_pMapdownloadTask->Dest(), IStorage::TYPE_SAVE);
ResetMapDownload();
SendMapRequest();
}
else if(m_pMapdownloadTask->State() == HTTP_ABORTED)
{
Storage()->RemoveFile(m_pMapdownloadTask->Dest(), IStorage::TYPE_SAVE);
m_pMapdownloadTask = NULL;
}
}

View file

@ -252,23 +252,22 @@ CGetFile::CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int
m_StorageType(StorageType)
{
str_copy(m_aDest, pDest, sizeof(m_aDest));
if(m_StorageType == -2)
m_pStorage->GetBinaryPath(m_aDest, m_aDestFull, sizeof(m_aDestFull));
else
m_pStorage->GetCompletePath(m_StorageType, m_aDest, m_aDestFull, sizeof(m_aDestFull));
}
bool CGetFile::BeforeInit()
{
char aPath[512];
if(m_StorageType == -2)
m_pStorage->GetBinaryPath(m_aDest, aPath, sizeof(aPath));
else
m_pStorage->GetCompletePath(m_StorageType, m_aDest, aPath, sizeof(aPath));
if(fs_makedir_rec_for(aPath) < 0)
if(fs_makedir_rec_for(m_aDestFull) < 0)
{
dbg_msg("http", "i/o error, cannot create folder for: %s", aPath);
dbg_msg("http", "i/o error, cannot create folder for: %s", m_aDestFull);
return false;
}
m_File = io_open(aPath, IOFLAG_WRITE);
m_File = io_open(m_aDestFull, IOFLAG_WRITE);
if(!m_File)
{
dbg_msg("http", "i/o error, cannot open file: %s", m_aDest);
@ -287,6 +286,14 @@ bool CGetFile::BeforeCompletion()
return io_close(m_File) == 0;
}
void CGetFile::OnCompletion()
{
if(State() == HTTP_ERROR || State() == HTTP_ABORTED)
{
m_pStorage->RemoveFile(m_aDestFull, IStorage::TYPE_ABSOLUTE);
}
}
CPostJson::CPostJson(const char *pUrl, CTimeout Timeout, const char *pJson)
: CRequest(pUrl, Timeout)
{

View file

@ -87,10 +87,12 @@ class CGetFile : public CRequest
virtual size_t OnData(char *pData, size_t DataSize);
virtual bool BeforeInit();
virtual bool BeforeCompletion();
virtual void OnCompletion();
IStorage *m_pStorage;
char m_aDest[256];
char m_aDest[MAX_PATH_LENGTH];
char m_aDestFull[MAX_PATH_LENGTH];
int m_StorageType;
IOHANDLE m_File;

View file

@ -274,7 +274,14 @@ public:
virtual const char *GetPath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize)
{
str_format(pBuffer, BufferSize, "%s%s%s", m_aaStoragePaths[Type], !m_aaStoragePaths[Type][0] ? "" : "/", pDir);
if(Type == TYPE_ABSOLUTE)
{
str_copy(pBuffer, pDir, BufferSize);
}
else
{
str_format(pBuffer, BufferSize, "%s%s%s", m_aaStoragePaths[Type], !m_aaStoragePaths[Type][0] ? "" : "/", pDir);
}
return pBuffer;
}
@ -405,7 +412,7 @@ public:
virtual bool RemoveFile(const char *pFilename, int Type)
{
if(Type < 0 || Type >= m_NumPaths)
if(Type < TYPE_ABSOLUTE || Type == TYPE_ALL || Type >= m_NumPaths)
return false;
char aBuffer[MAX_PATH_LENGTH];

View file

@ -251,7 +251,6 @@ int CSkins::FindImpl(const char *pName)
}
if(d.front().m_pTask && (d.front().m_pTask->State() == HTTP_ERROR || d.front().m_pTask->State() == HTTP_ABORTED))
{
Storage()->RemoveFile(d.front().m_aPath, IStorage::TYPE_SAVE);
d.front().m_pTask = nullptr;
}
return -1;