pkg package includes several utility functions for common file system operations used throughout Pumu.
File System Checks
FileExists
Reports whether a path exists and is a regular file (not a directory).The file path to check
Returns
true if the path exists and is a file, false otherwise- Returns
falseif the path doesn’t exist - Returns
falseif the path exists but is a directory - Returns
trueonly if the path exists and is a regular file
DirExists
Reports whether a path exists and is a directory.The directory path to check
Returns
true if the path exists and is a directory, false otherwise- Returns
falseif the path doesn’t exist - Returns
falseif the path exists but is a file - Returns
trueonly if the path exists and is a directory
Directory Removal
RemoveDirectory
Synchronously removes a directory and all its contents usingos.RemoveAll. Returns the duration it took to complete the removal.
The directory path to remove
The time it took to remove the directory
Returns an error if the removal fails,
nil otherwiseRemoveDirectory uses os.RemoveAll, which is optimized for modern file systems and typically provides the fastest directory removal from Go. For large directories (like node_modules with thousands of files), removal times can range from milliseconds to several seconds depending on:
- Directory size (number of files and total bytes)
- File system type (ext4, APFS, NTFS)
- Storage medium (SSD vs HDD)
- Operating system caching
Usage in Pumu
These utility functions are used throughout Pumu’s codebase:FileExists- Used by the detector to check for lock files (package-lock.json, Cargo.toml, etc.)DirExists- Used by the scanner to verify dependency folders exist before attempting removalRemoveDirectory- Used by the sweep and repair commands to delete heavy dependency folders