diff options
author | Ilnur Khuziev <ilnur.khuziev@yandex.ru> | 2022-02-10 16:46:13 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:13 +0300 |
commit | 736dcd8ca259457a136f2f9f9168c44643914323 (patch) | |
tree | ddd46a036d68bfa83aa11b892f31243ea6b068a1 /library/cpp/archive/directory_models_archive_reader.cpp | |
parent | 9bf2fa2b060c9881d3135c2208c624a1dd546ecc (diff) | |
download | ydb-736dcd8ca259457a136f2f9f9168c44643914323.tar.gz |
Restoring authorship annotation for Ilnur Khuziev <ilnur.khuziev@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/archive/directory_models_archive_reader.cpp')
-rw-r--r-- | library/cpp/archive/directory_models_archive_reader.cpp | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/library/cpp/archive/directory_models_archive_reader.cpp b/library/cpp/archive/directory_models_archive_reader.cpp index 6de9424c7c..392c99b511 100644 --- a/library/cpp/archive/directory_models_archive_reader.cpp +++ b/library/cpp/archive/directory_models_archive_reader.cpp @@ -9,12 +9,12 @@ #include <util/stream/input.h> #include <util/stream/mem.h> -TDirectoryModelsArchiveReader::TDirectoryModelsArchiveReader(const TString& path, bool lockMemory, bool ownBlobs) +TDirectoryModelsArchiveReader::TDirectoryModelsArchiveReader(const TString& path, bool lockMemory, bool ownBlobs) : Path_(path) { Y_ENSURE(IsDir(path), "directory not found on this path"); - LoadFilesAndSubdirs("", lockMemory, ownBlobs); + LoadFilesAndSubdirs("", lockMemory, ownBlobs); } TDirectoryModelsArchiveReader::~TDirectoryModelsArchiveReader() {} @@ -29,21 +29,21 @@ TString TDirectoryModelsArchiveReader::KeyByIndex(size_t n) const { } bool TDirectoryModelsArchiveReader::Has(const TStringBuf key) const { - return BlobByKey_.contains(key) || PathByKey_.contains(key); -} - -namespace { - struct TBlobOwningStream : public TMemoryInput { - TBlob Blob; - TBlobOwningStream(TBlob blob) - : TMemoryInput(blob.Data(), blob.Length()) - , Blob(blob) - {} - }; + return BlobByKey_.contains(key) || PathByKey_.contains(key); } +namespace { + struct TBlobOwningStream : public TMemoryInput { + TBlob Blob; + TBlobOwningStream(TBlob blob) + : TMemoryInput(blob.Data(), blob.Length()) + , Blob(blob) + {} + }; +} + TAutoPtr<IInputStream> TDirectoryModelsArchiveReader::ObjectByKey(const TStringBuf key) const { - return new TBlobOwningStream(BlobByKey(key)); + return new TBlobOwningStream(BlobByKey(key)); } TBlob TDirectoryModelsArchiveReader::ObjectBlobByKey(const TStringBuf key) const { @@ -51,14 +51,14 @@ TBlob TDirectoryModelsArchiveReader::ObjectBlobByKey(const TStringBuf key) const } TBlob TDirectoryModelsArchiveReader::BlobByKey(const TStringBuf key) const { - Y_ENSURE(Has(key), "key " << key << " not found"); - if (auto ptr = BlobByKey_.FindPtr(key); ptr) { - return *ptr; - } - if (auto ptr = PathByKey_.FindPtr(key); ptr) { - return TBlob::FromFile(*ptr); - } - Y_UNREACHABLE(); + Y_ENSURE(Has(key), "key " << key << " not found"); + if (auto ptr = BlobByKey_.FindPtr(key); ptr) { + return *ptr; + } + if (auto ptr = PathByKey_.FindPtr(key); ptr) { + return TBlob::FromFile(*ptr); + } + Y_UNREACHABLE(); } bool TDirectoryModelsArchiveReader::Compressed() const { @@ -74,18 +74,18 @@ TString TDirectoryModelsArchiveReader::NormalizePath(TString path) const { return path; } -void TDirectoryModelsArchiveReader::LoadFilesAndSubdirs(const TString& subPath, bool lockMemory, bool ownBlobs) { +void TDirectoryModelsArchiveReader::LoadFilesAndSubdirs(const TString& subPath, bool lockMemory, bool ownBlobs) { TFileList fileList; fileList.Fill(JoinFsPaths(Path_, subPath)); const char* file; while ((file = fileList.Next()) != nullptr) { TString key = JoinFsPaths(subPath, TString(file)); - TString fullPath = JoinFsPaths(Path_, key); + TString fullPath = JoinFsPaths(Path_, key); TBlob fileBlob; if (lockMemory) { - fileBlob = TBlob::LockedFromFile(fullPath); + fileBlob = TBlob::LockedFromFile(fullPath); } else { - fileBlob = TBlob::FromFile(fullPath); + fileBlob = TBlob::FromFile(fullPath); } if (key.EndsWith(".archive")) { TArchiveReader reader(fileBlob); @@ -97,11 +97,11 @@ void TDirectoryModelsArchiveReader::LoadFilesAndSubdirs(const TString& subPath, } } else { const TString normalizedPath = NormalizePath(key); - if (lockMemory || ownBlobs) { - BlobByKey_.emplace(normalizedPath, fileBlob); - } else { - PathByKey_.emplace(normalizedPath, RealPath(fullPath)); - } + if (lockMemory || ownBlobs) { + BlobByKey_.emplace(normalizedPath, fileBlob); + } else { + PathByKey_.emplace(normalizedPath, RealPath(fullPath)); + } Recs_.push_back(normalizedPath); } } @@ -110,6 +110,6 @@ void TDirectoryModelsArchiveReader::LoadFilesAndSubdirs(const TString& subPath, dirsList.Fill(JoinFsPaths(Path_, subPath)); const char* dir; while ((dir = dirsList.Next()) != nullptr) { - LoadFilesAndSubdirs(JoinFsPaths(subPath, TString(dir)), lockMemory, ownBlobs); + LoadFilesAndSubdirs(JoinFsPaths(subPath, TString(dir)), lockMemory, ownBlobs); } } |