-
Notifications
You must be signed in to change notification settings - Fork 59
File tree maxdepth #587
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
Changes from all commits
417933a
e0fc8f8
4781f8d
996584e
a07260a
af79a3b
10293fb
8875fc0
0a85dfe
7726f3f
a600ba5
fdd8d60
35275a5
30b273b
a4e51a2
8365789
9f4bf1e
09dd39c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,65 @@ | ||
| block_list = ["/proc", "/sys", "/lib", "/libx32", "/lib32", "/lib64", | ||
| "/boot", "/srv", "/usr", "/snap", "/run", "/dev", "/cores"] | ||
|
|
||
| usernfo = sys.get_user() | ||
| windows = sys.is_windows() | ||
|
|
||
| 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 | ||
|
|
||
| def file_list(path, tree): | ||
| tree = f"|\t{tree}" | ||
| files = file.list(path) | ||
| for f in files: | ||
| file_name = f['file_name'] | ||
| if path+f['file_name'] in block_list: | ||
| print(f"Skipping: {path}/{file_name}") | ||
| print("Skipping: "+path+f['file_name']) | ||
| continue | ||
| if f['type'] == "Directory": | ||
| print(f"{tree}|---{path}/{file_name}") | ||
| file_list(f"{path}/{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(f"{tree}|---{file_name}") | ||
| print(tree+"|---"+f['file_name']) | ||
| if f['type'] == "File": | ||
| print(f"{tree}|---{file_name}") | ||
|
|
||
| print(tree+"|---"+f['file_name']) | ||
|
|
||
| def main(path): | ||
| tree = "" | ||
| def main(path, depth=-1): | ||
| tree="" | ||
| depth=int(depth) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seem redundant with the above
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| if file.is_dir(path): | ||
| print(path+"") | ||
| if path == "/": | ||
|
|
||
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.
Instead of adding
can_readlets makefile.listfail in a recoverable way similar to the newfile.findfunctionThere 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.
We'll move forward with it as is and then remove the
can_readhere once the eldritch change has been made.