COMMON: Allow memcaching archive to bypass caching part and return a stream

It's useful for patchers if they can easily create a stream in some cases but
not others.
This commit is contained in:
Vladimir Serbinenko 2023-03-11 23:44:48 +01:00 committed by Eugene Sandulenko
parent c33ce058f8
commit 6476e55aab
2 changed files with 16 additions and 4 deletions

View file

@ -107,7 +107,10 @@ SeekableReadStream *MemcachingCaseInsensitiveArchive::createReadStreamForMember(
String translated = translatePath(path); String translated = translatePath(path);
bool isNew = false; bool isNew = false;
if (!_cache.contains(translated)) { if (!_cache.contains(translated)) {
_cache[translated] = readContentsForPath(translated); SharedArchiveContents readResult = readContentsForPath(translated);
if (readResult._bypass)
return readResult._bypass;
_cache[translated] = readResult;
isNew = true; isNew = true;
} }
@ -121,7 +124,10 @@ SeekableReadStream *MemcachingCaseInsensitiveArchive::createReadStreamForMember(
// Check whether the entry is still valid as WeakPtr might have expired. // Check whether the entry is still valid as WeakPtr might have expired.
if (!entry->makeStrong()) { if (!entry->makeStrong()) {
// If it's expired, recreate the entry. // If it's expired, recreate the entry.
_cache[translated] = readContentsForPath(translated); SharedArchiveContents readResult = readContentsForPath(translated);
if (readResult._bypass)
return readResult._bypass;
_cache[translated] = readResult;
entry = &_cache[translated]; entry = &_cache[translated];
isNew = true; isNew = true;
} }

View file

@ -169,10 +169,15 @@ class SharedArchiveContents {
public: public:
SharedArchiveContents(byte *contents, uint32 contentSize) : SharedArchiveContents(byte *contents, uint32 contentSize) :
_strongRef(contents, ArrayDeleter<byte>()), _weakRef(_strongRef), _strongRef(contents, ArrayDeleter<byte>()), _weakRef(_strongRef),
_contentSize(contentSize), _missingFile(false) {} _contentSize(contentSize), _missingFile(false), _bypass(nullptr) {}
SharedArchiveContents() : _strongRef(nullptr), _weakRef(nullptr), _contentSize(0), _missingFile(true) {} SharedArchiveContents() : _strongRef(nullptr), _weakRef(nullptr), _contentSize(0), _missingFile(true), _bypass(nullptr) {}
static SharedArchiveContents bypass(SeekableReadStream *stream) {
return SharedArchiveContents(stream);
}
private: private:
SharedArchiveContents(SeekableReadStream *stream) : _strongRef(nullptr), _weakRef(nullptr), _contentSize(0), _missingFile(false), _bypass(stream) {}
bool isFileMissing() const { return _missingFile; } bool isFileMissing() const { return _missingFile; }
SharedPtr<byte> getContents() const { return _strongRef; } SharedPtr<byte> getContents() const { return _strongRef; }
uint32 getSize() const { return _contentSize; } uint32 getSize() const { return _contentSize; }
@ -197,6 +202,7 @@ private:
WeakPtr<byte> _weakRef; WeakPtr<byte> _weakRef;
uint32 _contentSize; uint32 _contentSize;
bool _missingFile; bool _missingFile;
SeekableReadStream *_bypass;
friend class MemcachingCaseInsensitiveArchive; friend class MemcachingCaseInsensitiveArchive;
}; };