zpmod  b19981f
High-performance Zsh module for script optimization and filesystem helpers
zpmod_fpath.h File Reference
#include "zpmod.mdh"
Include dependency graph for zpmod_fpath.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ZPMOD_FPATH_H
 

Functions

int cmd_fpath_index (char *nam, char **argv)
 Implements zpmod fpath-index with intelligent skip detection. More...
 

Macro Definition Documentation

◆ ZPMOD_FPATH_H

#define ZPMOD_FPATH_H

Definition at line 3 of file zpmod_fpath.h.

Function Documentation

◆ cmd_fpath_index()

int cmd_fpath_index ( char *  nam,
char **  argv 
)

Implements zpmod fpath-index with intelligent skip detection.

Generates function-to-path mappings from FPATH directories with performance optimization through skip detection that avoids rebuilding unchanged indexes.

Index Format (v1)

The generated index uses a structured format for reliable skip detection:

# zpmod fpath-index v1
# dir 0 /first/fpath/dir 1234567890
# dir 1 /second/fpath/dir 1234567891
# dir 2 /third/fpath/dir -1
function_name /first/fpath/dir/function_name
other_func /second/fpath/dir/other_func

Skip Detection Algorithm

The skip detection was redesigned to handle missing directories consistently, fixing a critical issue where mtime mismatches caused unnecessary rebuilds.

Original Problem: When a directory didn't exist during index generation, we recorded -1 as the mtime. However, if the directory appeared later or stat() behaved differently during verification, we'd get a mismatch and force an unnecessary rebuild.

Solution: Unified mtime handling ensures consistent comparison:

  • During generation: stat() failure → record -1
  • During verification: stat() failure → use -1 for comparison
  • Both paths handle missing directories identically
Parameters
namBuiltin name for error reporting
argvCommand arguments (–out, –rebuild, –preload)
Returns
0 on success, 1 on failure
Note
The preload functionality populates shfunctab with function stubs for faster autoload resolution without writing index files.

Definition at line 57 of file fpath.c.