MADS: Switch MpsInstaller archive to MemcachingCaseInsensitiveArchive

This commit is contained in:
Vladimir Serbinenko 2022-11-30 01:39:00 +01:00
parent 2521169a7b
commit 489d83c76d
2 changed files with 11 additions and 23 deletions

View file

@ -63,13 +63,8 @@ MpsInstaller* MpsInstaller::open(const Common::Path& baseName) {
return new MpsInstaller(_files, baseName);
}
// Use of \\ as path separator is a guess. Never seen an archive with subfolders
static Common::String translateName(const Common::Path &path) {
return Common::normalizePath(path.toString('\\'), '\\');
}
bool MpsInstaller::hasFile(const Common::Path &path) const {
return _files.contains(translateName(path));
return _files.contains(translatePath(path));
}
int MpsInstaller::listMembers(Common::ArchiveMemberList &list) const {
@ -81,26 +76,21 @@ int MpsInstaller::listMembers(Common::ArchiveMemberList &list) const {
}
const Common::ArchiveMemberPtr MpsInstaller::getMember(const Common::Path &path) const {
Common::String translated = translateName(path);
Common::String translated = translatePath(path);
if (!_files.contains(translated))
return nullptr;
return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(_files.getVal(translated)._fileName, this));
}
// TODO: Make streams stay valid after destruction of archive
Common::SeekableReadStream *MpsInstaller::createReadStreamForMember(const Common::Path &path) const {
Common::String translated = translateName(path);
Common::SharedArchiveContents MpsInstaller::readContentsForPath(const Common::String& translated) const {
if (!_files.contains(translated))
return nullptr;
return Common::SharedArchiveContents();
FileDescriptor desc = _files.getVal(translated);
if (_cache.contains(desc._fileName)) {
return new Common::MemoryReadStream(_cache[desc._fileName].get(), desc._uncompressedSize, DisposeAfterUse::NO);
}
if (desc._compressionAlgo != 0 && desc._compressionAlgo != 1) {
debug ("Unsupported compression algorithm %d for %s", desc._compressionAlgo, desc._fileName.c_str());
return nullptr;
return Common::SharedArchiveContents();
}
@ -115,14 +105,14 @@ Common::SeekableReadStream *MpsInstaller::createReadStreamForMember(const Common
if (!fvol.open(volumePath)) {
error("Failed to open volume %s.%03d", volumePath.toString().c_str(), vol);
delete[] compressedBuf;
return nullptr;
return Common::SharedArchiveContents();
}
fvol.seek(off);
int32 actual = fvol.read(outptr, rem);
if (actual <= 0) {
warning("Read failure in volume %s.%03d", volumePath.toString().c_str(), vol);
delete[] compressedBuf;
return nullptr;
return Common::SharedArchiveContents();
}
rem -= actual;
@ -148,7 +138,7 @@ Common::SeekableReadStream *MpsInstaller::createReadStreamForMember(const Common
delete[] compressedBuf;
delete[] uncompressedBuf;
error("Unable to decompress %s", desc._fileName.c_str());
return nullptr;
return Common::SharedArchiveContents();
}
delete[] compressedBuf;
compressedBuf = nullptr;
@ -156,8 +146,7 @@ Common::SeekableReadStream *MpsInstaller::createReadStreamForMember(const Common
break;
}
_cache[desc._fileName].reset(uncompressedBuf);
// TODO: Make it configurable to read directly from disk, at least in the uncompressed case
return new Common::MemoryReadStream(uncompressedBuf, desc._uncompressedSize, DisposeAfterUse::NO);
return Common::SharedArchiveContents(uncompressedBuf, desc._uncompressedSize);
}
}

View file

@ -30,12 +30,12 @@
namespace MADS {
class MpsInstaller : public Common::Archive {
class MpsInstaller : public Common::MemcachingCaseInsensitiveArchive {
public:
bool hasFile(const Common::Path &path) const override;
int listMembers(Common::ArchiveMemberList&) const override;
const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
Common::SharedArchiveContents readContentsForPath(const Common::String& translatedPath) const override;
static MpsInstaller* open(const Common::Path& baseName);
@ -79,7 +79,6 @@ private:
const Common::Path& baseName) : _files(files), _baseName(baseName) {}
FileMap _files;
mutable Common::HashMap<Common::String, Common::ScopedPtr<byte, Common::ArrayDeleter<byte>>, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _cache;
Common::Path _baseName;
};
}