diff --git a/cloud/filestore/apps/client/lib/factory.cpp b/cloud/filestore/apps/client/lib/factory.cpp index 11bb85e9f6..84558562b4 100644 --- a/cloud/filestore/apps/client/lib/factory.cpp +++ b/cloud/filestore/apps/client/lib/factory.cpp @@ -31,6 +31,7 @@ TCommandPtr NewWriteCommand(); TCommandPtr NewExecuteActionCommand(); TCommandPtr NewCreateSessionCommand(); TCommandPtr NewResetSessionCommand(); +TCommandPtr NewStatCommand(); //////////////////////////////////////////////////////////////////////////////// @@ -60,6 +61,7 @@ static const TMap Commands = { { "executeaction", NewExecuteActionCommand }, { "createsession", NewCreateSessionCommand }, { "resetsession", NewResetSessionCommand }, + { "stat", NewStatCommand }, }; //////////////////////////////////////////////////////////////////////////////// diff --git a/cloud/filestore/apps/client/lib/stat.cpp b/cloud/filestore/apps/client/lib/stat.cpp new file mode 100644 index 0000000000..49f3cde687 --- /dev/null +++ b/cloud/filestore/apps/client/lib/stat.cpp @@ -0,0 +1,74 @@ +#include "command.h" + +#include + +#include +#include +#include + +namespace NCloud::NFileStore::NClient { + +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +void PrintNodeAttributes(IOutputStream& out, const NProto::TNodeAttr& nodeAttr) +{ + out << "Node Id: " << nodeAttr.GetId() << Endl; + out << "Node Type: " << nodeAttr.GetType() << Endl; + out << "Mode: " << nodeAttr.GetMode() << Endl; + out << "Uid: " << nodeAttr.GetUid() << Endl; + out << "Gid: " << nodeAttr.GetGid() << Endl; + out << "Access: " << TInstant::FromValue(nodeAttr.GetATime()) << Endl; + out << "Modify: " << TInstant::FromValue(nodeAttr.GetMTime()) << Endl; + out << "Change: " << TInstant::FromValue(nodeAttr.GetCTime()) << Endl; + out << "File Size: " << nodeAttr.GetSize() << Endl; + out << "Links: " << nodeAttr.GetLinks() << Endl; +} + +//////////////////////////////////////////////////////////////////////////////// + +class TStatCommand final: public TFileStoreCommand +{ +private: + TString Path; + +public: + TStatCommand() + { + Opts.AddLongOption("path") + .Required() + .RequiredArgument("PATH") + .StoreResult(&Path); + } + + bool Execute() override + { + CreateSession(); + + const auto resolved = ResolvePath(Path, false); + Y_ENSURE(!resolved.empty(), "resolved path is empty"); + + auto request = CreateRequest(); + request->SetNodeId(resolved.back().Node.GetId()); + auto response = WaitFor( + Client->GetNodeAttr(PrepareCallContext(), std::move(request))); + + CheckResponse(response); + + PrintNodeAttributes(Cout, response.GetNode()); + + return true; + } +}; + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +TCommandPtr NewStatCommand() +{ + return std::make_shared(); +} + +} // namespace NCloud::NFileStore::NClient diff --git a/cloud/filestore/apps/client/lib/ya.make b/cloud/filestore/apps/client/lib/ya.make index 805771bfe0..0f090f494f 100644 --- a/cloud/filestore/apps/client/lib/ya.make +++ b/cloud/filestore/apps/client/lib/ya.make @@ -23,6 +23,7 @@ SRCS( resize.cpp rm.cpp start_endpoint.cpp + stat.cpp stop_endpoint.cpp text_table.cpp touch.cpp