fsautoproc
Basic file transformation automation management utility
Loading...
Searching...
No Matches
deng.c File Reference

Differential file search implementation. More...

#include "deng.h"
#include <assert.h>
#include <stdio.h>
#include "jemalloc/jemalloc.h"
#include "fs.h"
#include "index.h"
#include "log.h"
Include dependency graph for deng.c:

Data Structures

struct  deng_state_s
 Search state context provided to the diff engine as user data which is passed to the file event hook functions. More...

Macros

#define callevent(mach, type, arg)
 Invokes a file event hook function if it is not NULL.
#define notifyhook(mach, type)
 Invokes the notify hook function if it is not NULL.

Functions

static int stagepre (const char *fp, const struct fsstat_s *st, void *udata)
 Processes a file before the command execution stage to ensure all files are indexed. This function may trigger new (NEW), modified (MOD), and unmodified (NOP) events for each file in the directory tree.
static int stagepost (const char *fp, const struct fsstat_s *st, void *udata)
 Processes a file after the command execution stage to ensure all files are indexed. This function may trigger new (NEW) and modified (MOD) events for each file in the directory tree.
static int execstage (struct deng_state_s *mach, const char *sd, fswalkfn_t filefn)
 Walks the directory tree starting at sd and invokes the provided file function filefn for each file found. After the walk is complete, the stage done notification is triggered.
static int checkremoved (struct deng_state_s *mach)
 Compares the current file system state with a previous index to determine which files were removed. This function may trigger deleted (DEL) events for each file in the previous index that is not present in the current index.
int dengsearch (const char *sd, deng_filter_t filter, const struct deng_hooks_s *hooks, const struct index_s *old, struct index_s *new)
 Recursively scans directory sd and compares the file system state with a previously saved index. Any new, modified, deleted, or unmodified files are reported to the caller via the provided hooks structure, hooks. The index state new is then updated with the current file system state.

Detailed Description

Differential file search implementation.

Macro Definition Documentation

◆ callevent

#define callevent ( mach,
type,
arg )
Value:
do { \
if ((mach)->hooks->event != NULL) (mach)->hooks->event(type, arg); \
} while (0)

Invokes a file event hook function if it is not NULL.

Parameters
machThe diff engine state context
typeThe event type to pass to the hook function
argThe argument to pass to the hook function

◆ notifyhook

#define notifyhook ( mach,
type )
Value:
do { \
if ((mach)->hooks->notify != NULL) (mach)->hooks->notify(type); \
} while (0)

Invokes the notify hook function if it is not NULL.

Parameters
machThe diff engine state context
typeThe notification type to pass to the hook

Function Documentation

◆ checkremoved()

int checkremoved ( struct deng_state_s * mach)
static

Compares the current file system state with a previous index to determine which files were removed. This function may trigger deleted (DEL) events for each file in the previous index that is not present in the current index.

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

◆ dengsearch()

int dengsearch ( const char * sd,
deng_filter_t filter,
const struct deng_hooks_s * hooks,
const struct index_s * old,
struct index_s * new )

Recursively scans directory sd and compares the file system state with a previously saved index. Any new, modified, deleted, or unmodified files are reported to the caller via the provided hooks structure, hooks. The index state new is then updated with the current file system state.

Parameters
sdThe directory to scan for conditionally ignoring files
filterThe file filter function
hooksThe file event hook functions
oldThe previous index state
newThe current index state
Returns
0 if successful, otherwise a non-zero error code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ execstage()

int execstage ( struct deng_state_s * mach,
const char * sd,
fswalkfn_t filefn )
static

Walks the directory tree starting at sd and invokes the provided file function filefn for each file found. After the walk is complete, the stage done notification is triggered.

Parameters
machThe diff engine state context
sdThe initial search directory path
filefnThe function to invoke for each file in the directory tree
Returns
0 if successful, otherwise a non-zero error code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stagepost()

int stagepost ( const char * fp,
const struct fsstat_s * st,
void * udata )
static

Processes a file after the command execution stage to ensure all files are indexed. This function may trigger new (NEW) and modified (MOD) events for each file in the directory tree.

Parameters
fpThe file path to process
stThe file stat information
udataThe diff engine state context
Returns
0 if successful, otherwise a non-zero error code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stagepre()

int stagepre ( const char * fp,
const struct fsstat_s * st,
void * udata )
static

Processes a file before the command execution stage to ensure all files are indexed. This function may trigger new (NEW), modified (MOD), and unmodified (NOP) events for each file in the directory tree.

Parameters
fpThe file path to process
stThe file stat information
udataThe diff engine state context
Returns
0 if successful, otherwise a non-zero error code.
Here is the call graph for this function:
Here is the caller graph for this function: