-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Filestore] add SetNodeAttr command to filestore client (#1469)
Issue: #1474
- Loading branch information
1 parent
b70b452
commit f1c822b
Showing
5 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include "command.h" | ||
|
||
#include <optional> | ||
|
||
#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 { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
class TSetNodeAttrCommand final: public TFileStoreCommand | ||
{ | ||
private: | ||
ui32 NodeId = 0; | ||
std::optional<ui32> ModeAttr; | ||
std::optional<ui32> UidAttr; | ||
std::optional<ui32> GidAttr; | ||
std::optional<ui64> SizeAttr; | ||
std::optional<ui64> ATimeAttr; | ||
std::optional<ui64> MTimeAttr; | ||
std::optional<ui64> CTimeAttr; | ||
|
||
public: | ||
TSetNodeAttrCommand() | ||
{ | ||
Opts.AddLongOption("node-id") | ||
.Required() | ||
.StoreResult(&NodeId); | ||
|
||
Opts.AddLongOption("mode") | ||
.Optional() | ||
.StoreResult(&ModeAttr); | ||
|
||
Opts.AddLongOption("uid") | ||
.Optional() | ||
.StoreResult(&UidAttr); | ||
|
||
Opts.AddLongOption("gid") | ||
.Optional() | ||
.StoreResult(&GidAttr); | ||
|
||
Opts.AddLongOption("size") | ||
.Optional() | ||
.StoreResult(&SizeAttr); | ||
|
||
Opts.AddLongOption("atime") | ||
.Optional() | ||
.StoreResult(&ATimeAttr); | ||
|
||
Opts.AddLongOption("mtime") | ||
.Optional() | ||
.StoreResult(&MTimeAttr); | ||
|
||
Opts.AddLongOption("ctime") | ||
.Optional() | ||
.StoreResult(&CTimeAttr); | ||
} | ||
|
||
bool Execute() override | ||
{ | ||
auto sessionGuard = CreateSession(); | ||
|
||
auto request = CreateRequest<NProto::TSetNodeAttrRequest>(); | ||
request->SetNodeId(NodeId); | ||
|
||
auto addFlag = [&request](NProto::TSetNodeAttrRequest::EFlags flag) | ||
{ | ||
request->SetFlags( | ||
request->GetFlags() | NCloud::NFileStore::ProtoFlag(flag)); | ||
}; | ||
|
||
if (ModeAttr) | ||
{ | ||
addFlag(NProto::TSetNodeAttrRequest::F_SET_ATTR_MODE); | ||
request->MutableUpdate()->SetMode(*ModeAttr); | ||
} | ||
|
||
if (UidAttr) { | ||
addFlag(NProto::TSetNodeAttrRequest::F_SET_ATTR_UID); | ||
request->MutableUpdate()->SetUid(*UidAttr); | ||
} | ||
|
||
if (GidAttr) { | ||
addFlag(NProto::TSetNodeAttrRequest::F_SET_ATTR_GID); | ||
request->MutableUpdate()->SetGid(*GidAttr); | ||
} | ||
|
||
if (SizeAttr) { | ||
addFlag(NProto::TSetNodeAttrRequest::F_SET_ATTR_SIZE); | ||
request->MutableUpdate()->SetSize(*SizeAttr); | ||
} | ||
|
||
if (ATimeAttr) { | ||
addFlag(NProto::TSetNodeAttrRequest::F_SET_ATTR_ATIME); | ||
request->MutableUpdate()->SetATime(*ATimeAttr); | ||
} | ||
|
||
if (MTimeAttr) { | ||
addFlag(NProto::TSetNodeAttrRequest::F_SET_ATTR_MTIME); | ||
request->MutableUpdate()->SetMTime(*MTimeAttr); | ||
} | ||
|
||
if (CTimeAttr) { | ||
addFlag(NProto::TSetNodeAttrRequest::F_SET_ATTR_CTIME); | ||
request->MutableUpdate()->SetCTime(*CTimeAttr); | ||
} | ||
|
||
auto response = WaitFor( | ||
Client->SetNodeAttr(PrepareCallContext(), std::move(request))); | ||
|
||
CheckResponse(response); | ||
return true; | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
TCommandPtr NewSetNodeAttrCommand() | ||
{ | ||
return std::make_shared<TSetNodeAttrCommand>(); | ||
} | ||
|
||
} // namespace NCloud::NFileStore::NClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters