Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7aaecce

Browse filesBrowse files
RafaelGSSruyadorno
authored andcommitted
permission: add debug log when inserting fs nodes
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: #48677 Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent 249879e commit 7aaecce
Copy full SHA for 7aaecce

File tree

Expand file treeCollapse file tree

3 files changed

+49
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+49
-3
lines changed
Open diff view settings
Collapse file

‎src/debug_utils.h‎

Copy file name to clipboardExpand all lines: src/debug_utils.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ void NODE_EXTERN_PRIVATE FWrite(FILE* file, const std::string& str);
4949
V(CODE_CACHE) \
5050
V(NGTCP2_DEBUG) \
5151
V(WASI) \
52-
V(MKSNAPSHOT)
52+
V(MKSNAPSHOT) \
53+
V(PERMISSION_MODEL)
5354

5455
enum class DebugCategory : unsigned int {
5556
#define V(name) name,
Collapse file

‎src/permission/fs_permission.cc‎

Copy file name to clipboardExpand all lines: src/permission/fs_permission.cc
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "fs_permission.h"
22
#include "base_object-inl.h"
3+
#include "debug_utils-inl.h"
34
#include "util.h"
45
#include "v8.h"
56

@@ -72,6 +73,46 @@ namespace node {
7273

7374
namespace permission {
7475

76+
void PrintTree(FSPermission::RadixTree::Node* node, int spaces = 0) {
77+
std::string whitespace(spaces, ' ');
78+
79+
if (node == nullptr) {
80+
return;
81+
}
82+
if (node->wildcard_child != nullptr) {
83+
per_process::Debug(DebugCategory::PERMISSION_MODEL,
84+
"%s Wildcard: %s\n",
85+
whitespace,
86+
node->prefix);
87+
} else {
88+
per_process::Debug(DebugCategory::PERMISSION_MODEL,
89+
"%s Prefix: %s\n",
90+
whitespace,
91+
node->prefix);
92+
if (node->children.size()) {
93+
int child = 0;
94+
for (const auto pair : node->children) {
95+
++child;
96+
per_process::Debug(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);
102+
}
103+
per_process::Debug(DebugCategory::PERMISSION_MODEL,
104+
"%s End of tree - child(%s)\n",
105+
whitespace,
106+
child);
107+
} else {
108+
per_process::Debug(DebugCategory::PERMISSION_MODEL,
109+
"%s End of tree: %s\n",
110+
whitespace,
111+
node->prefix);
112+
}
113+
}
114+
}
115+
75116
// allow = '*'
76117
// allow = '/tmp/,/home/example.js'
77118
void FSPermission::Apply(const std::string& allow, PermissionScope scope) {
@@ -176,6 +217,12 @@ void FSPermission::RadixTree::Insert(const std::string& path) {
176217
parent_node_prefix_len = i;
177218
}
178219
}
220+
221+
if (UNLIKELY(per_process::enabled_debug_list.enabled(
222+
DebugCategory::PERMISSION_MODEL))) {
223+
per_process::Debug(DebugCategory::PERMISSION_MODEL, "Inserting %s\n", path);
224+
PrintTree(root_node_);
225+
}
179226
}
180227

181228
} // namespace permission
Collapse file

‎src/permission/fs_permission.h‎

Copy file name to clipboardExpand all lines: src/permission/fs_permission.h
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class FSPermission final : public PermissionBase {
1818
void Apply(const std::string& allow, PermissionScope scope) override;
1919
bool is_granted(PermissionScope perm, const std::string_view& param) override;
2020

21-
// For debugging purposes, use the gist function to print the whole tree
22-
// https://gist.github.com/RafaelGSS/5b4f09c559a54f53f9b7c8c030744d19
2321
struct RadixTree {
2422
struct Node {
2523
std::string prefix;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.