diff options
author | eshemchik <eshemchik@yandex-team.ru> | 2022-02-10 16:50:53 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:53 +0300 |
commit | face8a85ff3525043b92e692a9891cd1c19519c4 (patch) | |
tree | b8d8fb33c214e745aed40b94ec90c00fa14a1d59 /library/cpp/archive/directory_models_archive_reader.cpp | |
parent | c30e2c009b4c8b03c837d199a610c5b0596d0233 (diff) | |
download | ydb-face8a85ff3525043b92e692a9891cd1c19519c4.tar.gz |
Restoring authorship annotation for <eshemchik@yandex-team.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 | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/library/cpp/archive/directory_models_archive_reader.cpp b/library/cpp/archive/directory_models_archive_reader.cpp index 6de9424c7c..6c85cecf67 100644 --- a/library/cpp/archive/directory_models_archive_reader.cpp +++ b/library/cpp/archive/directory_models_archive_reader.cpp @@ -1,37 +1,37 @@ -#include "directory_models_archive_reader.h" +#include "directory_models_archive_reader.h" #include "yarchive.h" - -#include <util/folder/dirut.h> -#include <util/folder/filelist.h> -#include <util/folder/path.h> -#include <util/memory/blob.h> -#include <util/stream/file.h> -#include <util/stream/input.h> -#include <util/stream/mem.h> - + +#include <util/folder/dirut.h> +#include <util/folder/filelist.h> +#include <util/folder/path.h> +#include <util/memory/blob.h> +#include <util/stream/file.h> +#include <util/stream/input.h> +#include <util/stream/mem.h> + TDirectoryModelsArchiveReader::TDirectoryModelsArchiveReader(const TString& path, bool lockMemory, bool ownBlobs) - : Path_(path) -{ - Y_ENSURE(IsDir(path), "directory not found on this path"); - + : Path_(path) +{ + Y_ENSURE(IsDir(path), "directory not found on this path"); + LoadFilesAndSubdirs("", lockMemory, ownBlobs); -} - -TDirectoryModelsArchiveReader::~TDirectoryModelsArchiveReader() {} - -size_t TDirectoryModelsArchiveReader::Count() const noexcept { - return Recs_.size(); -} - -TString TDirectoryModelsArchiveReader::KeyByIndex(size_t n) const { - Y_ENSURE(n < Count(), "incorrect index " << n); - return Recs_[n]; -} - -bool TDirectoryModelsArchiveReader::Has(const TStringBuf key) const { +} + +TDirectoryModelsArchiveReader::~TDirectoryModelsArchiveReader() {} + +size_t TDirectoryModelsArchiveReader::Count() const noexcept { + return Recs_.size(); +} + +TString TDirectoryModelsArchiveReader::KeyByIndex(size_t n) const { + Y_ENSURE(n < Count(), "incorrect index " << n); + return Recs_[n]; +} + +bool TDirectoryModelsArchiveReader::Has(const TStringBuf key) const { return BlobByKey_.contains(key) || PathByKey_.contains(key); -} - +} + namespace { struct TBlobOwningStream : public TMemoryInput { TBlob Blob; @@ -42,15 +42,15 @@ namespace { }; } -TAutoPtr<IInputStream> TDirectoryModelsArchiveReader::ObjectByKey(const TStringBuf key) const { +TAutoPtr<IInputStream> TDirectoryModelsArchiveReader::ObjectByKey(const TStringBuf key) const { return new TBlobOwningStream(BlobByKey(key)); -} - -TBlob TDirectoryModelsArchiveReader::ObjectBlobByKey(const TStringBuf key) const { - return BlobByKey(key); -} - -TBlob TDirectoryModelsArchiveReader::BlobByKey(const TStringBuf key) const { +} + +TBlob TDirectoryModelsArchiveReader::ObjectBlobByKey(const TStringBuf key) const { + return BlobByKey(key); +} + +TBlob TDirectoryModelsArchiveReader::BlobByKey(const TStringBuf key) const { Y_ENSURE(Has(key), "key " << key << " not found"); if (auto ptr = BlobByKey_.FindPtr(key); ptr) { return *ptr; @@ -59,34 +59,34 @@ TBlob TDirectoryModelsArchiveReader::BlobByKey(const TStringBuf key) const { return TBlob::FromFile(*ptr); } Y_UNREACHABLE(); -} - -bool TDirectoryModelsArchiveReader::Compressed() const { - return false; -} - -TString TDirectoryModelsArchiveReader::NormalizePath(TString path) const { - path = "/" + path; - for (size_t i = 0; i < path.size(); i++) { - if (path[i] == '\\') - path[i] = '/'; - } - return path; -} - +} + +bool TDirectoryModelsArchiveReader::Compressed() const { + return false; +} + +TString TDirectoryModelsArchiveReader::NormalizePath(TString path) const { + path = "/" + path; + for (size_t i = 0; i < path.size(); i++) { + if (path[i] == '\\') + path[i] = '/'; + } + return path; +} + 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)); + 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); TBlob fileBlob; - if (lockMemory) { + if (lockMemory) { fileBlob = TBlob::LockedFromFile(fullPath); - } else { + } else { fileBlob = TBlob::FromFile(fullPath); - } + } if (key.EndsWith(".archive")) { TArchiveReader reader(fileBlob); for (size_t i = 0, iEnd = reader.Count(); i < iEnd; ++i) { @@ -104,12 +104,12 @@ void TDirectoryModelsArchiveReader::LoadFilesAndSubdirs(const TString& subPath, } Recs_.push_back(normalizedPath); } - } - - TDirsList dirsList; - dirsList.Fill(JoinFsPaths(Path_, subPath)); - const char* dir; - while ((dir = dirsList.Next()) != nullptr) { + } + + TDirsList dirsList; + dirsList.Fill(JoinFsPaths(Path_, subPath)); + const char* dir; + while ((dir = dirsList.Next()) != nullptr) { LoadFilesAndSubdirs(JoinFsPaths(subPath, TString(dir)), lockMemory, ownBlobs); - } -} + } +} |