Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

permission: mark const functions as such #50705

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/permission/child_process_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void ChildProcessPermission::Apply(const std::vector<std::string>& allow,
}

bool ChildProcessPermission::is_granted(PermissionScope perm,
const std::string_view& param) {
const std::string_view& param) const {
return deny_all_ == false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/permission/child_process_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ChildProcessPermission final : public PermissionBase {
void Apply(const std::vector<std::string>& allow,
PermissionScope scope) override;
bool is_granted(PermissionScope perm,
const std::string_view& param = "") override;
const std::string_view& param = "") const override;

private:
bool deny_all_;
Expand Down
9 changes: 5 additions & 4 deletions src/permission/fs_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ void FreeRecursivelyNode(
delete node;
}

bool is_tree_granted(node::permission::FSPermission::RadixTree* granted_tree,
const std::string_view& param) {
bool is_tree_granted(
const node::permission::FSPermission::RadixTree* granted_tree,
const std::string_view& param) {
#ifdef _WIN32
// is UNC file path
if (param.rfind("\\\\", 0) == 0) {
Expand Down Expand Up @@ -147,7 +148,7 @@ void FSPermission::GrantAccess(PermissionScope perm, const std::string& res) {
}

bool FSPermission::is_granted(PermissionScope perm,
const std::string_view& param = "") {
const std::string_view& param = "") const {
switch (perm) {
case PermissionScope::kFileSystem:
return allow_all_in_ && allow_all_out_;
Expand All @@ -171,7 +172,7 @@ FSPermission::RadixTree::~RadixTree() {
}

bool FSPermission::RadixTree::Lookup(const std::string_view& s,
bool when_empty_return = false) {
bool when_empty_return = false) const {
FSPermission::RadixTree::Node* current_node = root_node_;
if (current_node->children.size() == 0) {
return when_empty_return;
Expand Down
11 changes: 6 additions & 5 deletions src/permission/fs_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class FSPermission final : public PermissionBase {
public:
void Apply(const std::vector<std::string>& allow,
PermissionScope scope) override;
bool is_granted(PermissionScope perm, const std::string_view& param) override;
bool is_granted(PermissionScope perm,
const std::string_view& param) const override;

struct RadixTree {
struct Node {
Expand Down Expand Up @@ -72,7 +73,7 @@ class FSPermission final : public PermissionBase {
return wildcard_child;
}

Node* NextNode(const std::string& path, size_t idx) {
Node* NextNode(const std::string& path, size_t idx) const {
if (idx >= path.length()) {
return nullptr;
}
Expand Down Expand Up @@ -115,7 +116,7 @@ class FSPermission final : public PermissionBase {
// ---> '\000' ASCII (0) || \0
// ---> er
// ---> n
bool IsEndNode() {
bool IsEndNode() const {
if (children.size() == 0) {
return true;
}
Expand All @@ -126,8 +127,8 @@ class FSPermission final : public PermissionBase {
RadixTree();
~RadixTree();
void Insert(const std::string& s);
bool Lookup(const std::string_view& s) { return Lookup(s, false); }
bool Lookup(const std::string_view& s, bool when_empty_return);
bool Lookup(const std::string_view& s) const { return Lookup(s, false); }
bool Lookup(const std::string_view& s, bool when_empty_return) const;

private:
Node* root_node_;
Expand Down
2 changes: 1 addition & 1 deletion src/permission/inspector_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void InspectorPermission::Apply(const std::vector<std::string>& allow,
}

bool InspectorPermission::is_granted(PermissionScope perm,
const std::string_view& param) {
const std::string_view& param) const {
return deny_all_ == false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/permission/inspector_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class InspectorPermission final : public PermissionBase {
void Apply(const std::vector<std::string>& allow,
PermissionScope scope) override;
bool is_granted(PermissionScope perm,
const std::string_view& param = "") override;
const std::string_view& param = "") const override;

private:
bool deny_all_;
Expand Down
2 changes: 1 addition & 1 deletion src/permission/permission_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PermissionBase {
virtual void Apply(const std::vector<std::string>& allow,
PermissionScope scope) = 0;
virtual bool is_granted(PermissionScope perm,
const std::string_view& param = "") = 0;
const std::string_view& param = "") const = 0;
};

} // namespace permission
Expand Down
2 changes: 1 addition & 1 deletion src/permission/worker_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void WorkerPermission::Apply(const std::vector<std::string>& allow,
}

bool WorkerPermission::is_granted(PermissionScope perm,
const std::string_view& param) {
const std::string_view& param) const {
return deny_all_ == false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/permission/worker_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WorkerPermission final : public PermissionBase {
void Apply(const std::vector<std::string>& allow,
PermissionScope scope) override;
bool is_granted(PermissionScope perm,
const std::string_view& param = "") override;
const std::string_view& param = "") const override;

private:
bool deny_all_;
Expand Down
Loading