Skip to content

Commit

Permalink
Add template logic for walkdir
Browse files Browse the repository at this point in the history
  • Loading branch information
dmknght committed Oct 26, 2024
1 parent 55762e1 commit 0f2fea8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/engine/scan_file.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ proc fscanner_walk_dir_rec*(scan_dir: string) =
1. If node is a file or symlink of a file, call file scan
2. If node is a folder or symlink of a folder, call walk_dir rec
3. Do heuristic scan for hidden nodes (via d_name)
Linux's node types: https://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html
]#
discard

Expand All @@ -146,16 +148,35 @@ proc fscanner_walk_dir_rec*(scan_dir: string) =
break

current_node_name = $cast[cstring](addr(ptr_dir.d_name))
# Full path = scan_dir + "/" + current_node_name (if scan_dir doesn't end with "/")

if not isEmptyOrWhiteSpace(next_node_name) and next_node_name != current_node_name:
discard # TODO show this is a hidden node

if ptr_dir.d_reclen >= 256:
next_node_name = "" # Name of current node is too long. We can't parse next_node_name, or we might have a crash
# Name of current node is too long. We can't parse next_node_name, or we might have a crash
next_node_name = ""
else:
# d_reclen = len(current_node_name) + sizeof(chunk_bytes). casting a string at next position can get the name of next node
next_node_name = $cast[cstring](addr(ptr_dir.d_name[ptr_dir.d_reclen]))

case ptr_dir.d_type
of DT_DIR:
# call fscanner_walk_dir_rec here
discard
of DT_REG:
# Regular file, call scan file
discard
of DT_LNK:
# Either link of file or link of dir. Must handle this
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
else:
# DT_FIFO, DT_SOCK, DT_CHR (A character device), DT_BLK (A block device). Research first
discard

# TODO check node's type to do either walk dir or scan file

discard p_dir.closedir()

0 comments on commit 0f2fea8

Please sign in to comment.