Skip to content

Commit

Permalink
[Filestore] Add stat command to filestore client
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmyagkov committed Jun 19, 2024
1 parent e90acaf commit 8b42b90
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cloud/filestore/apps/client/lib/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TCommandPtr NewWriteCommand();
TCommandPtr NewExecuteActionCommand();
TCommandPtr NewCreateSessionCommand();
TCommandPtr NewResetSessionCommand();
TCommandPtr NewStatCommand();

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -60,6 +61,7 @@ static const TMap<TString, TFactoryFunc> Commands = {
{ "executeaction", NewExecuteActionCommand },
{ "createsession", NewCreateSessionCommand },
{ "resetsession", NewResetSessionCommand },
{ "stat", NewStatCommand },
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
74 changes: 74 additions & 0 deletions cloud/filestore/apps/client/lib/stat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "command.h"

#include <cloud/filestore/public/api/protos/fs.pb.h>

#include <util/datetime/base.h>
#include <util/stream/file.h>
#include <util/system/sysstat.h>

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<NProto::TGetNodeAttrRequest>();
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<TStatCommand>();
}

} // namespace NCloud::NFileStore::NClient
1 change: 1 addition & 0 deletions cloud/filestore/apps/client/lib/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SRCS(
resize.cpp
rm.cpp
start_endpoint.cpp
stat.cpp
stop_endpoint.cpp
text_table.cpp
touch.cpp
Expand Down

0 comments on commit 8b42b90

Please sign in to comment.