Skip to content

feat: recusively scan folders [#120]#124

Merged
plusvic merged 4 commits intoVirusTotal:masterfrom
JicLotus:josec/issue-120
Feb 17, 2026
Merged

feat: recusively scan folders [#120]#124
plusvic merged 4 commits intoVirusTotal:masterfrom
JicLotus:josec/issue-120

Conversation

@JicLotus
Copy link
Contributor

@JicLotus JicLotus commented Feb 15, 2026

Description

#120


Note on permissions: If recursion is disabled, the function behaves like the previous implementation and will only fail if the top-level directory is unreadable. With recursion enabled, permission errors can occur on subdirectories, as WalkDir attempts to access them.

Note on OS compatibility: We are using filepath.Clean and filepath.WalkDir, which are cross-platform aware, so depth calculation using strings.Split(path, string(os.PathSeparator)) should work on Windows/Unix.


This PR refactors NewFileDirReader to use Go’s standard filepath.WalkDir (here) for directory traversal, and avoid custom recursive implementations. The function efficiently reads all files under a directory, optionally traversing subdirectories up to a configurable maxDepth. Traversal is stopped immediately for directories beyond the allowed depth or when recursion is disabled using fs.SkipDir, avoiding unnecessary filesystem reads and reducing resource usage. This approach is safe, efficient, and reduces the risk of errors compared to manual recursion, while remaining idiomatic and easy to maintain.

Usage:

  • vt scan file YOUR_DIRECTORY (default recursive disabled + maxDepth == 1)
  • vt scan file YOUR_DIRECTORY -r (recursive enabled with default maxDepth == 1)
  • vt scan file YOUR_DIRECTORY -r -d 3 (recursive enabled + setting up maxDepth to read more subtrees until reaching depth == 3 on each subdirectory)

Testing

  1. Unit testing: Added comprehensive unit tests covering scenarios with recursion enabled and disabled, as well as multiple depth levels, both with and without subdirectories.

  2. Manual build testing(mac-os). Successfully built+installed the binary and verified normal usage. Note we scanning multiple directories now

image
  1. Compiled in all architectures make all
image
  1. Windows tests. Everything runs as expected, you can see scanning files from multiple directories
image

@JicLotus JicLotus marked this pull request as ready for review February 15, 2026 15:41
@JicLotus JicLotus changed the title feat: Recusively scan folders [WIP][#120] feat: Recusively scan folders [#120] Feb 15, 2026
@JicLotus JicLotus mentioned this pull request Feb 15, 2026
@plusvic plusvic changed the title feat: Recusively scan folders [#120] feat: recusively scan folders [#120] Feb 17, 2026
@plusvic plusvic merged commit e671a5d into VirusTotal:master Feb 17, 2026
2 checks passed
@JicLotus JicLotus deleted the josec/issue-120 branch February 17, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants