zpmod  b19981f
High-performance Zsh module for script optimization and filesystem helpers
fpath.c File Reference

FPATH indexing for autoload. More...

#include "zpmod.mdh"
#include "zpmod.pro"
#include "zpmod_fpath.h"
#include "zpmod_vendor_shims.h"
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
Include dependency graph for fpath.c:

Go to the source code of this file.

Functions

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

Detailed Description

FPATH indexing for autoload.

Definition in file fpath.c.

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.

References addhashnode(), dupstring(), getaparam(), gethashnode2(), shfunctab, zalloc(), ztrdup(), and zwarnnam().

Referenced by bin_zpmod().

Here is the call graph for this function:
Here is the caller graph for this function: