-
Notifications
You must be signed in to change notification settings - Fork 28
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
File tree maxdepth #587
Open
nullmonk
wants to merge
12
commits into
main
Choose a base branch
from
file-tree-maxdepth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
File tree maxdepth #587
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
417933a
Add headers and recursive depth to file_list
nullmonk e0fc8f8
remove recursion, add glob support
nullmonk 4781f8d
update metadata
nullmonk 996584e
Add permissions check to file_tree
nullmonk a07260a
Undo file_list changes
nullmonk af79a3b
Clarifying placeholder
nullmonk 10293fb
Missed a line, rip build system
nullmonk 8875fc0
Merge branch 'main' into file-tree-maxdepth
0a85dfe
Bypass windows permissions
nullmonk 7726f3f
Merge branch 'main' into file-tree-maxdepth
a600ba5
Fix windows bug and strip newlines
nullmonk fdd8d60
remove depth check
nullmonk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,70 @@ | ||
block_list = ["/proc","/sys","/lib","/libx32","/lib32","/lib64","/boot","/srv","/usr","/snap","/run","/dev","/cores"] | ||
|
||
usernfo = sys.get_user() | ||
windows = sys.is_windows() | ||
|
||
def file_list(path,tree): | ||
def can_read(f): | ||
"""Return true if the user can read this dir/file | ||
""" | ||
# Bypass until windows perms are implemented | ||
if windows: | ||
return True | ||
|
||
PERM_READ = 4 | ||
f_user = int(f["permissions"][-3]) # User byte | ||
f_group = int(f["permissions"][-2]) # Group byte | ||
|
||
# Check world byte first so it hopefully is fast | ||
if int(f["permissions"][-1]) & PERM_READ: | ||
return True | ||
|
||
# Are we root? | ||
root = usernfo["euid"]["uid"] == 0 | ||
|
||
# If the user isnt root and the user doesnt own the file, clear the user byte | ||
if not root and f["owner"] not in (usernfo["euid"]["name"], usernfo["uid"]["name"]): | ||
f_user = 0 | ||
|
||
# TODO: https://github.com/spellshift/realm/issues/570 | ||
# Will NOT match any group other than primary until #570 is fixed | ||
|
||
# If the user isnt root and the group doesnt own the file, clear the group byte | ||
if not root and f["group"] not in (str(usernfo["egid"]), str(usernfo["gid"])): | ||
f_group = 0 | ||
|
||
if (f_group & PERM_READ) | (f_user & PERM_READ): | ||
return True | ||
return False | ||
|
||
def file_list(path,tree, depth=-1): | ||
tree="|\t"+tree | ||
if depth == 0: | ||
return | ||
files = file.list(path) | ||
for f in files: | ||
if path+f['file_name'] in block_list: | ||
print("Skipping: "+path+f['file_name']+"\n") | ||
print("Skipping: "+path+f['file_name']) | ||
continue | ||
if f['type'] == "Directory": | ||
print(tree+"|---"+path+"/"+f['file_name']+"\n") | ||
file_list(path+"/"+f['file_name'],tree) | ||
print(tree+"|---"+f['file_name']+"/") | ||
if can_read(f): | ||
file_list(path+"/"+f['file_name'],tree, depth=depth-1) | ||
if f['type'] == "Link": | ||
print(tree+"|---"+f['file_name']+"\n") | ||
print(tree+"|---"+f['file_name']) | ||
if f['type'] == "File": | ||
print(tree+"|---"+f['file_name']+"\n") | ||
print(tree+"|---"+f['file_name']) | ||
|
||
def main(path): | ||
def main(path, depth=-1): | ||
tree="" | ||
depth=int(depth) | ||
if file.is_dir(path): | ||
print(path+"\n") | ||
if path == "/": | ||
print("It looks like you're trying to list every file on the system.\n") | ||
print("This generates a lot of data so I'm going to exclude less helpful directories\n") | ||
print("If you really really want everything including /proc and /sys specify \"//\"\n") | ||
file_list(path,tree) | ||
print("It looks like you're trying to list every file on the system.") | ||
print("This generates a lot of data so I'm going to exclude less helpful directories") | ||
print("If you really really want everything including /proc and /sys specify \"//\"") | ||
file_list(path,tree, depth=depth) | ||
elif file.is_file(path): | ||
print("Error: Invalid Path ("+path+")\n") | ||
print("Error: Invalid Path ("+path+")") | ||
|
||
main(input_params['path']) | ||
print("\n") | ||
print("\n") | ||
main(input_params['path'], input_params["depth"]) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seem redundant with the above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean redundant? -1 is not handled properly by the is digit function. This also gracefully exits rather than just crashing