Skip to content

Commit 72f75bb

Browse files
RafaelGSSaduh95
authored andcommitted
src,permission: enhance permission model debug
This commit enhance the permission model debug logs when NODE_DEBUG_NATIVE=PERMISSION_MODEL is used Example Inserting /Users/rafaelgss/repos/os/node/t.js └─ / β”œβ”€ Users/rafaelgss/repos/os/node/t.js └─ tm β”œβ”€ 3 β”œβ”€ 2 └─ p/* Signed-off-by: RafaelGSS <[email protected]> PR-URL: #58898 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Marco Ippolito <[email protected]>
1 parent 7c54085 commit 72f75bb

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

β€Žsrc/permission/fs_permission.cc

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,43 +72,53 @@ bool is_tree_granted(
7272
return granted_tree->Lookup(resolved_param, true);
7373
}
7474

75-
void PrintTree(const node::permission::FSPermission::RadixTree::Node* node,
76-
size_t spaces = 0) {
77-
std::string whitespace(spaces, ' ');
75+
static const char* kBoxDrawingsLightUpAndRight = "└─ ";
76+
static const char* kBoxDrawingsLightVerticalAndRight = "β”œβ”€ ";
7877

78+
void PrintTree(const node::permission::FSPermission::RadixTree::Node* node,
79+
size_t depth = 0,
80+
const std::string& branch_prefix = "",
81+
bool is_last = true) {
7982
if (node == nullptr) {
8083
return;
8184
}
82-
if (node->wildcard_child != nullptr) {
83-
node::per_process::Debug(node::DebugCategory::PERMISSION_MODEL,
84-
"%s Wildcard: %s\n",
85-
whitespace,
86-
node->prefix);
87-
} else {
85+
86+
if (depth > 0 || (node->prefix.length() > 0)) {
87+
std::string indent;
88+
89+
if (depth > 0) {
90+
indent = branch_prefix;
91+
if (is_last) {
92+
indent += kBoxDrawingsLightUpAndRight;
93+
} else {
94+
indent += kBoxDrawingsLightVerticalAndRight;
95+
}
96+
}
97+
8898
node::per_process::Debug(node::DebugCategory::PERMISSION_MODEL,
89-
"%s Prefix: %s\n",
90-
whitespace,
91-
node->prefix);
92-
if (node->children.size()) {
93-
size_t child = 0;
94-
for (const auto& pair : node->children) {
95-
++child;
96-
node::per_process::Debug(node::DebugCategory::PERMISSION_MODEL,
97-
"%s Child(%s): %s\n",
98-
whitespace,
99-
child,
100-
std::string(1, pair.first));
101-
PrintTree(pair.second, spaces + 2);
99+
"%s%s\n",
100+
indent.c_str(),
101+
node->prefix.c_str());
102+
}
103+
104+
if (node->children.size() > 0) {
105+
size_t count = 0;
106+
size_t total = node->children.size();
107+
108+
std::string next_branch_prefix;
109+
if (depth > 0) {
110+
next_branch_prefix = branch_prefix;
111+
if (is_last) {
112+
next_branch_prefix += " ";
113+
} else {
114+
next_branch_prefix += "β”‚ ";
102115
}
103-
node::per_process::Debug(node::DebugCategory::PERMISSION_MODEL,
104-
"%s End of tree - child(%s)\n",
105-
whitespace,
106-
child);
107-
} else {
108-
node::per_process::Debug(node::DebugCategory::PERMISSION_MODEL,
109-
"%s End of tree: %s\n",
110-
whitespace,
111-
node->prefix);
116+
}
117+
118+
for (const auto& pair : node->children) {
119+
count++;
120+
bool child_is_last = (count == total);
121+
PrintTree(pair.second, depth + 1, next_branch_prefix, child_is_last);
112122
}
113123
}
114124
}

0 commit comments

Comments
Β (0)