1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Bypass media transfer in single player

This commit is contained in:
sfan5 2024-01-20 16:26:05 +01:00
parent 16aaef097a
commit 93381014a0
7 changed files with 81 additions and 25 deletions

View file

@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/serialize.h"
#include "util/sha1.h"
#include "util/string.h"
#include <sstream>
static std::string getMediaCacheDir()
{
@ -41,7 +42,16 @@ bool clientMediaUpdateCache(const std::string &raw_hash, const std::string &file
std::string sha1_hex = hex_encode(raw_hash);
if (!media_cache.exists(sha1_hex))
return media_cache.update(sha1_hex, filedata);
return true;
return false;
}
bool clientMediaUpdateCacheCopy(const std::string &raw_hash, const std::string &path)
{
FileCache media_cache(getMediaCacheDir());
std::string sha1_hex = hex_encode(raw_hash);
if (!media_cache.exists(sha1_hex))
return media_cache.updateCopyFile(sha1_hex, path);
return false;
}
/*
@ -189,10 +199,6 @@ void ClientMediaDownloader::initialStep(Client *client)
assert(m_uncached_received_count == 0);
// Create the media cache dir if we are likely to write to it
if (m_uncached_count != 0)
createCacheDirs();
// If we found all files in the cache, report this fact to the server.
// If the server reported no remote servers, immediately start
// conventional transfers. Note: if cURL support is not compiled in,
@ -511,18 +517,6 @@ IClientMediaDownloader::IClientMediaDownloader():
{
}
void IClientMediaDownloader::createCacheDirs()
{
if (!m_write_to_cache)
return;
std::string path = getMediaCacheDir();
if (!fs::CreateAllDirs(path)) {
errorstream << "Client: Could not create media cache directory: "
<< path << std::endl;
}
}
bool IClientMediaDownloader::tryLoadFromCache(const std::string &name,
const std::string &sha1, Client *client)
{
@ -726,8 +720,6 @@ void SingleMediaDownloader::initialStep(Client *client)
if (isDone())
return;
createCacheDirs();
// If the server reported no remote servers, immediately fall back to
// conventional transfer.
if (!USE_CURL || m_remotes.empty()) {