/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
cloud/filestore/apps/client/lib/find.cpp
97 строк
2 KB
Maxim Deb Natkh
[Filestore] allow passing root to the `filestore-client find` (#4744)
04 дек 2025, 22:02
Не верифицирован
04 дек 2025, 22:02
24eb612
Код
Авторство
О чём код?
#include "command.h" #include <cloud/filestore/public/api/protos/fs.pb.h> #include <cloud/storage/core/libs/common/format.h> #include <fnmatch.h> namespace NCloud::NFileStore::NClient { namespace { //////////////////////////////////////////////////////////////////////////////// bool MatchesGlob(const TString& pattern, const TString& name) { return pattern ? fnmatch(pattern.c_str(), name.c_str(), 0) == 0 : true; } //////////////////////////////////////////////////////////////////////////////// class TFindCommand final : public TFileStoreCommand { private: TString Glob; ui32 Depth = 0; ui64 StartRootNodeId = RootNodeId; public: TFindCommand() { Opts.AddLongOption("glob") .RequiredArgument("GLOB") .StoreResult(&Glob); Opts.AddLongOption("depth") .RequiredArgument("NUM") .DefaultValue(1) .StoreResult(&Depth); Opts.AddLongOption("root") .RequiredArgument("NUM") .DefaultValue(RootNodeId) .StoreResult(&StartRootNodeId); } void StatAll( ISession& session, const TString& fsId, TString prefix, ui64 parentId, ui32 depth) { --depth; auto response = ListAll(session, fsId, parentId, false, 0); // TODO: async for (ui32 i = 0; i < response.NodesSize(); ++i) { const auto& node = response.GetNodes(i); const auto& name = response.GetNames(i); if (MatchesGlob(Glob, name)) { Cout << prefix << "\t" << name << "\t" << node.GetId() << Endl; } if (node.GetType() == NProto::E_DIRECTORY_NODE && depth) { StatAll( session, fsId, prefix + name + "/", node.GetId(), depth); } } } bool Execute() override { auto sessionGuard = CreateSession(); auto& session = sessionGuard.AccessSession(); StatAll(session, FileSystemId, "/", StartRootNodeId, Depth); return true; } }; } // namespace //////////////////////////////////////////////////////////////////////////////// TCommandPtr NewFindCommand() { return std::make_shared<TFindCommand>(); } } // namespace NCloud::NFileStore::NClient