Skip to content

Commit

Permalink
Start using walk_dir_rec
Browse files Browse the repository at this point in the history
  • Loading branch information
dmknght committed Oct 27, 2024
1 parent cb3f031 commit 8db35a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/engine/scan_file.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ proc fscanner_scan_file*(scan_ctx: var FileScanCtx, scan_path: string, virname:
Linux's node types: https://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html
]#
proc fscanner_walk_dir_rec*(scan_dir: string) =
proc fscanner_walk_dir_rec*(scan_ctx: var FileScanCtx, scan_dir: string, virname: var cstring, scanned: var uint) =
var
p_dir = opendir(cstring(scan_dir))
ptr_dir: ptr Dirent
Expand All @@ -158,7 +158,10 @@ proc fscanner_walk_dir_rec*(scan_dir: string) =
break

current_node_name = $cast[cstring](addr(ptr_dir.d_name))
full_node_path = if full_node_path.endsWith("/"): scan_dir & current_node_name else: scan_dir & "/" & current_node_name
if current_node_name == "." or current_node_name == "..":
continue

full_node_path = if scan_dir.endsWith("/"): scan_dir & current_node_name else: scan_dir & "/" & current_node_name

if not isEmptyOrWhiteSpace(next_node_name) and next_node_name != current_node_name:
discard # TODO show this is a hidden node
Expand All @@ -173,21 +176,20 @@ proc fscanner_walk_dir_rec*(scan_dir: string) =
case ptr_dir.d_type
of DT_DIR:
# Recursive walk. Current node is a folder so it should ends with "/"
fscanner_walk_dir_rec(full_node_path & "/")
fscanner_walk_dir_rec(scan_ctx, full_node_path & "/", virname, scanned)
of DT_REG:
# Regular file, call scan file
# fscanner_scan_file()
discard
fscanner_scan_file(scan_ctx, full_node_path, virname, scanned)
of DT_LNK:
# Either link of file or link of dir. Must handle this
# if getSymlinkFileKind(full_node_path) == pcLinkToDir:
# fscanner_walk_dir_rec(full_node_path & "/")
discard
of DT_UNKNOWN:
# The type is unknown. Only some filesystems have full support to return the type of the file, others might always return this value. Debug first
discard
fscanner_scan_file(scan_ctx, full_node_path, virname, scanned)
else:
# DT_UNKNOWN, DT_FIFO, DT_SOCK, DT_CHR (A character device), DT_BLK (A block device). Research first
# DT_FIFO, DT_SOCK, DT_CHR (A character device), DT_BLK (A block device). Research first
discard

discard p_dir.closedir()
6 changes: 2 additions & 4 deletions src/scanners/scanners.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ proc scanners_cl_scan_files*(scan_ctx: var ScanCtx, list_path_objects: seq[strin
for each_scan_object in list_path_objects:
case getFileInfo(each_scan_object).kind
of pcDir:
for path in walkDirRec(each_scan_object):
fscanner_scan_file(file_scanner, path, virname, scanned)
fscanner_walk_dir_rec(file_scanner, each_scan_object, virname, scanned)
of pcLinkToDir:
for path in walkDirRec(each_scan_object):
fscanner_scan_file(file_scanner, path, virname, scanned)
fscanner_walk_dir_rec(file_scanner, each_scan_object, virname, scanned)
else:
fscanner_scan_file(file_scanner, each_scan_object, virname, scanned)
except KeyboardInterrupt:
Expand Down

0 comments on commit 8db35a7

Please sign in to comment.