Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
levy5307 committed Dec 16, 2020
1 parent 52bfa45 commit f41964d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
6 changes: 4 additions & 2 deletions include/dsn/utility/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class flag_tagger
// Loads all the flags from configuration.
extern void flags_initialize();

extern error_s update_flag(const char *name, const char *val);
// update the specified flag to val
extern error_s update_flag(const std::string &name, const std::string &val);

extern error_with<bool> has_tag(const char *name, const flag_tag &tag);
// determine if the tag is exist for the specified flag
extern bool has_tag(const std::string &name, const flag_tag &tag);
} // namespace dsn
2 changes: 1 addition & 1 deletion src/http/config_http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void update_config(const http_request &req, http_response &resp)
}

auto iter = req.query_args.begin();
auto res = update_flag(iter->first.c_str(), iter->second.c_str());
auto res = update_flag(iter->first, iter->second);

utils::table_printer tp;
tp.add_row_name_and_data("update_status", res.description());
Expand Down
12 changes: 6 additions & 6 deletions src/utils/flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class flag_data
{
}

error_s update(const char *val)
error_s update(const std::string &val)
{
if (!has_tag(flag_tag::FT_MUTABLE)) {
return error_s::make(ERR_NO_PERMISSION, fmt::format("{} is not mutable", _name));
Expand Down Expand Up @@ -117,7 +117,7 @@ class flag_registry : public utils::singleton<flag_registry>
public:
void add_flag(const char *name, flag_data flag) { _flags.emplace(name, flag); }

error_s update_flag(const char *name, const char *val)
error_s update_flag(const std::string &name, const std::string &val)
{
auto it = _flags.find(name);
if (it == _flags.end()) {
Expand Down Expand Up @@ -151,11 +151,11 @@ class flag_registry : public utils::singleton<flag_registry>
it->second.add_tag(tag);
}

error_with<bool> has_tag(const char *name, const flag_tag &tag) const
bool has_tag(const std::string &name, const flag_tag &tag) const
{
auto it = _flags.find(name);
if (it == _flags.end()) {
return error_s::make(ERR_OBJECT_NOT_FOUND, fmt::format("{} is not found", name));
return false;
}
return it->second.has_tag(tag);
}
Expand Down Expand Up @@ -195,12 +195,12 @@ flag_tagger::flag_tagger(const char *name, const flag_tag &tag)

/*extern*/ void flags_initialize() { flag_registry::instance().load_from_config(); }

/*extern*/ error_s update_flag(const char *name, const char *val)
/*extern*/ error_s update_flag(const std::string &name, const std::string &val)
{
return flag_registry::instance().update_flag(name, val);
}

/*extern*/ error_with<bool> has_tag(const char *name, const flag_tag &tag)
/*extern*/ bool has_tag(const std::string &name, const flag_tag &tag)
{
return flag_registry::instance().has_tag(name, tag);
}
Expand Down
9 changes: 3 additions & 6 deletions src/utils/test/flag_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,15 @@ TEST(flag_test, tag_flag)
{
// has tag
auto res = has_tag("has_tag", flag_tag::FT_MUTABLE);
ASSERT_TRUE(res.is_ok());
ASSERT_TRUE(res.get_value());
ASSERT_TRUE(res);

// doesn't has tag
res = has_tag("no_tag", flag_tag::FT_MUTABLE);
ASSERT_TRUE(res.is_ok());
ASSERT_FALSE(res.get_value());
ASSERT_FALSE(res);

// flag is not exist
res = has_tag("no_flag", flag_tag::FT_MUTABLE);
ASSERT_FALSE(res.is_ok());
ASSERT_EQ(res.get_error().code(), ERR_OBJECT_NOT_FOUND);
ASSERT_FALSE(res);
}
} // namespace utils
} // namespace dsn

0 comments on commit f41964d

Please sign in to comment.