From 81e19df1f1a9413af533b8da2fdbec0a75f39091 Mon Sep 17 00:00:00 2001 From: rahulraj80 Date: Tue, 30 May 2023 16:32:29 +0530 Subject: [PATCH 1/2] Update start.py - blacklisted_element I am sure there will be more elegant ways to do this, but this seems to work. Changes: Added a list : black_listed_elements where all blacklisted items (with path, for example `blacklisted_elements = ["/webrepl_cfg.py", "/lib/microWebSrv.py"] )` Changed append to files and dirs so that there is only one pass over the elements. Earlier, the list expansion was passing over elements twice. Should be faster for large folders. --- weditor/start.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/weditor/start.py b/weditor/start.py index 2f61674..7afb519 100644 --- a/weditor/start.py +++ b/weditor/start.py @@ -3,7 +3,7 @@ import sys from microWebSrv import MicroWebSrv - +blacklisted_elements = ["/webrepl_cfg.py"] DEBUG_PRINT = False def dprint(string): @@ -27,8 +27,15 @@ def get_dir(httpClient, httpResponse): path = path[:len(path)-1] dprint("Listing dir {}".format(path)) elements = list(os.ilistdir(path)) - files = [pt[0] for pt in elements if pt[1]==32768 and pt[0] != "webrepl_cfg.py"] - dirs = [pt[0] for pt in elements if pt[1]==16384] + files = [] + dirs = [] + for pt in elements: + to_check = f"/{pt[0]}" if path == "/" else f"{path}/{pt[0]}" + if to_check not in blacklisted_elements : + if pt[1]==32768: + files.append(pt[0]) + if pt[1]==16384: + dirs.append(pt[0]) content = {"files": files, "dirs": dirs} _respond(httpResponse, content) From 359cadcf9a24c7be6af81e9d78e05a65e0a12296 Mon Sep 17 00:00:00 2001 From: rahulraj80 Date: Tue, 30 May 2023 16:38:21 +0530 Subject: [PATCH 2/2] Update start.py - With balcklisted_elements I am sure there will be more elegant ways to do this, but this seems to work. Changes: Added a list : black_listed_elements where all blacklisted items (with path, for example `blacklisted_elements = ["/webrepl_cfg.py", "/lib/microWebSrv.py"] )` Changed append to files and dirs so that there is only one pass over the elements. Earlier, the list expansion was passing over elements twice. Should be faster for large folders. --- weditor/start.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weditor/start.py b/weditor/start.py index 7afb519..4d71123 100644 --- a/weditor/start.py +++ b/weditor/start.py @@ -29,9 +29,9 @@ def get_dir(httpClient, httpResponse): elements = list(os.ilistdir(path)) files = [] dirs = [] + prefix = "" if path == "/" else f"{path}" for pt in elements: - to_check = f"/{pt[0]}" if path == "/" else f"{path}/{pt[0]}" - if to_check not in blacklisted_elements : + if f"{prefix}/{pt[0]}" not in blacklisted_elements : if pt[1]==32768: files.append(pt[0]) if pt[1]==16384: