module
Memo::Files
Overview
File indexing support for memo CLI
Provides directory walking with ignore file support, binary file detection, and file metadata tracking for incremental updates.
Extended Modules
Defined in:
memo/files.crInstance Method Summary
-
#binary?(path : String) : Bool
Check if file is binary using libmagic
-
#binary_by_content?(path : String, sample_size : Int32 = 8192) : Bool
Fallback binary detection by checking for null bytes
-
#collect(root : String, ignore_file : String = ".gitignore") : Array(String)
Collect all text files in directory
-
#content_hash(path : String) : Bytes
Compute SHA256 hash of file content
-
#count(db : DBHandle) : Int64
Count indexed files
-
#delete(db : DBHandle, source_id : Int64) : Bool
Delete file record
-
#file_info(path : String, root : String) : FileInfo
DEPRECATED Paths are absolute now; use
#file_info(path) -
#file_info(path : String) : FileInfo
Get file info (path, hash, mtime, size).
-
#find(db : DBHandle, path : String, root : String, rekey : Bool = true) : FileRecord | Nil
The record for the file at
path(absolute, as file_info gives it). -
#get_by_hash(db : DBHandle, hash : Bytes) : FileRecord | Nil
Get file record by content hash
-
#get_by_path(db : DBHandle, path : String) : FileRecord | Nil
Get file record by path
-
#get_by_source(db : DBHandle, source_id : Int64) : FileRecord | Nil
Get file record by source_id
-
#list(db : DBHandle, limit : Int32 = 100, offset : Int32 = 0) : Array(FileRecord)
List all indexed files
-
#needs_update?(record : FileRecord, current_mtime : Int64) : Bool
Check if file needs re-indexing (mtime changed)
-
#store(db : DBHandle, source_id : Int64, info : FileInfo)
Store file record in database
-
#under(db : DBHandle, root : String) : Array(Tuple(Int64, String))
The files recorded under directory
root(absolute), as {source_id, path} -
#walk(root : String, ignore_file : String = ".gitignore", &block : String -> )
Walk directory and yield text files, respecting ignore patterns
Instance Method Detail
Fallback binary detection by checking for null bytes
Collect all text files in directory
DEPRECATED Paths are absolute now; use #file_info(path)
Get file info (path, hash, mtime, size). The path is absolute with symlinks resolved, so a file has one record however it's reached.
The record for the file at path (absolute, as file_info gives it).
Before memo keyed files by absolute path, it keyed them by their path
relative to the directory indexed (root, absolute with symlinks
resolved): a record under that key is found too, and with rekey
moved to path.
Get file record by content hash
Get file record by path
Get file record by source_id
List all indexed files
Check if file needs re-indexing (mtime changed)
Store file record in database
The files recorded under directory root (absolute), as {source_id, path}
Walk directory and yield text files, respecting ignore patterns
Uses ignoreme for .gitignore-style filtering. Uses magic.cr to detect and skip binary files. Symlinks inside the tree are skipped, to files and directories alike: they can lead out of it (a checkout could link to your home directory) or loop. The root itself may be one.
Options:
- root: Directory to walk
- ignore_file: Ignore file name (default ".gitignore")