mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-12 19:18:20 +00:00
Remove failed downloaded files immediately
Especially skins were only deleted after they were requested again
This commit is contained in:
parent
9e23623fa1
commit
56b152e962
|
@ -2845,13 +2845,11 @@ void CClient::Update()
|
||||||
else if(m_pMapdownloadTask->State() == HTTP_ERROR)
|
else if(m_pMapdownloadTask->State() == HTTP_ERROR)
|
||||||
{
|
{
|
||||||
dbg_msg("webdl", "http failed, falling back to gameserver");
|
dbg_msg("webdl", "http failed, falling back to gameserver");
|
||||||
Storage()->RemoveFile(m_pMapdownloadTask->Dest(), IStorage::TYPE_SAVE);
|
|
||||||
ResetMapDownload();
|
ResetMapDownload();
|
||||||
SendMapRequest();
|
SendMapRequest();
|
||||||
}
|
}
|
||||||
else if(m_pMapdownloadTask->State() == HTTP_ABORTED)
|
else if(m_pMapdownloadTask->State() == HTTP_ABORTED)
|
||||||
{
|
{
|
||||||
Storage()->RemoveFile(m_pMapdownloadTask->Dest(), IStorage::TYPE_SAVE);
|
|
||||||
m_pMapdownloadTask = NULL;
|
m_pMapdownloadTask = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,23 +252,22 @@ CGetFile::CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int
|
||||||
m_StorageType(StorageType)
|
m_StorageType(StorageType)
|
||||||
{
|
{
|
||||||
str_copy(m_aDest, pDest, sizeof(m_aDest));
|
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()
|
bool CGetFile::BeforeInit()
|
||||||
{
|
{
|
||||||
char aPath[512];
|
if(fs_makedir_rec_for(m_aDestFull) < 0)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_File = io_open(aPath, IOFLAG_WRITE);
|
m_File = io_open(m_aDestFull, IOFLAG_WRITE);
|
||||||
if(!m_File)
|
if(!m_File)
|
||||||
{
|
{
|
||||||
dbg_msg("http", "i/o error, cannot open file: %s", m_aDest);
|
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;
|
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)
|
CPostJson::CPostJson(const char *pUrl, CTimeout Timeout, const char *pJson)
|
||||||
: CRequest(pUrl, Timeout)
|
: CRequest(pUrl, Timeout)
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,10 +87,12 @@ class CGetFile : public CRequest
|
||||||
virtual size_t OnData(char *pData, size_t DataSize);
|
virtual size_t OnData(char *pData, size_t DataSize);
|
||||||
virtual bool BeforeInit();
|
virtual bool BeforeInit();
|
||||||
virtual bool BeforeCompletion();
|
virtual bool BeforeCompletion();
|
||||||
|
virtual void OnCompletion();
|
||||||
|
|
||||||
IStorage *m_pStorage;
|
IStorage *m_pStorage;
|
||||||
|
|
||||||
char m_aDest[256];
|
char m_aDest[MAX_PATH_LENGTH];
|
||||||
|
char m_aDestFull[MAX_PATH_LENGTH];
|
||||||
int m_StorageType;
|
int m_StorageType;
|
||||||
IOHANDLE m_File;
|
IOHANDLE m_File;
|
||||||
|
|
||||||
|
|
|
@ -274,7 +274,14 @@ public:
|
||||||
|
|
||||||
virtual const char *GetPath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize)
|
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;
|
return pBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +412,7 @@ public:
|
||||||
|
|
||||||
virtual bool RemoveFile(const char *pFilename, int Type)
|
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;
|
return false;
|
||||||
|
|
||||||
char aBuffer[MAX_PATH_LENGTH];
|
char aBuffer[MAX_PATH_LENGTH];
|
||||||
|
|
|
@ -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))
|
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;
|
d.front().m_pTask = nullptr;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue