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

Main program entry point. More...

#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "deng.h"
#include "fd.h"
#include "fl.h"
#include "fs.h"
#include "index.h"
#include "lcmd.h"
#include "log.h"
#include "prog.h"
#include "tp.h"
Include dependency graph for main.c:

Macros

#define strdupoptarg(into)
 Duplicates the current optarg value into the specified variable. If the duplication fails, an error message is printed and the function returns 1.
 

Functions

static void freeinitargs (void)
 Frees all duplicated initialization arguments.
 
static void freeall (void)
 Frees all allocated resources.
 
static int parseinitargs (const int argc, char **const argv)
 Parses the program initialization arguments into initargs.
 
static int loadindex (struct index_s *idx, const char *fp)
 Loads the index from the specified file path into the provided index.
 
static int writeindex (struct index_s *idx, const char *fp)
 Writes the index to the specified file path.
 
static bool filterjunk (const char *fp)
 Filters out junk files from the index based on loaded command sets cmdsets and the initargs.includejunk flag/program option.
 
static void onnotify (const enum deng_notif_t notif)
 Callback function passed to the diff engine to handle progress notifications. This function will print a progress bar to the console when a directory is completed, and block between stage completions to ensure all thread work requests are complete before the next stage.
 
static void trigfileevent (struct inode_s *in, const int trig)
 Queues command execution for a file event of the specified type, using the provided inode for the file information. If the skipproc flag is set, the command execution is skipped. If the verbose flag is set, the command execution is done with verbose output.
 
static void onnew (struct inode_s *in)
 Callback function for the diff engine to handle new file events. This will log a work request in the thread pool for any command sets which match the new file event.
 
static void ondel (struct inode_s *in)
 Callback function for the diff engine to handle deleted file events. This will log a work request in the thread pool for any command sets which match the deleted file event.
 
static void onmod (struct inode_s *in)
 Callback function for the diff engine to handle modified file events. This will log a work request in the thread pool for any command sets which match the modified file event.
 
static void onnop (struct inode_s *in)
 Callback function for the diff engine to handle no-op file events. This will log a work request in the thread pool for any command sets which match the unmodified file event.
 
static int cmpchanges (void)
 Compares the current file system state with a previously saved index.
 
static int tracefile (const char *fp)
 Traces which command sets match the specified file by manually invoking the command execution logic with a trace flag. lcmdexec will print the command set names that match the file.
 
static void printmsspent (void)
 Prints the time spent for each command set to the console.
 
int main (int argc, char **argv)
 Main program entry point.
 

Variables

struct { 
 
   char *   configfile 
 Configuration file path (-c) More...
 
   char *   indexfile 
 Index file path (-i) More...
 
   char *   lockfile 
 Exclusive lock file path (-x) More...
 
   char *   searchdir 
 Search directory root (-s) More...
 
   char *   tracefile 
 Trace file path (-r) More...
 
   _Bool   pipefiles 
 Pipe subprocess stdout/stderr to files (-p) More...
 
   _Bool   includejunk 
 Include ignored files in index (-j) More...
 
   _Bool   listspent 
 List time spent for each command set (-l) More...
 
   _Bool   skipproc 
 Skip processing files, only update file index (-u) More...
 
   int   threads 
 Number of worker threads (-t) More...
 
   _Bool   verbose 
 Enable verbose output (-v) More...
 
initargs 
 Managed initialization arguments for the program.
 
static struct lcmdset_s ** cmdsets
 Command sets loaded from configuration.
 
static struct index_s lastmap
 Stored index from previous run (if any)
 
static struct index_s thismap
 Live checked index from this run.
 
static struct flock_s worklock
 Exclusive work lock for local directory.
 

Detailed Description

Main program entry point.

Macro Definition Documentation

◆ strdupoptarg

#define strdupoptarg ( into)
Value:
do { \
if ((into = strdup(optarg)) == NULL) { \
perror(NULL); \
return 1; \
} \
} while (0)

Duplicates the current optarg value into the specified variable. If the duplication fails, an error message is printed and the function returns 1.

Parameters
intoThe variable to duplicate into

Function Documentation

◆ cmpchanges()

static int cmpchanges ( void )
static

Compares the current file system state with a previously saved index.

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:

◆ filterjunk()

static bool filterjunk ( const char * fp)
static

Filters out junk files from the index based on loaded command sets cmdsets and the initargs.includejunk flag/program option.

Parameters
fpThe file path to filter
Returns
True if the file is considered junk, otherwise false.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ freeall()

static void freeall ( void )
static

Frees all allocated resources.

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

◆ freeinitargs()

static void freeinitargs ( void )
static

Frees all duplicated initialization arguments.

Here is the caller graph for this function:

◆ loadindex()

static int loadindex ( struct index_s * idx,
const char * fp )
static

Loads the index from the specified file path into the provided index.

Parameters
idxThe index to load into
fpThe file path to load the index from
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:

◆ main()

int main ( int argc,
char ** argv )

Main program entry point.

Parameters
argcThe number of arguments
argvThe argument array
Returns
0 if successful, otherwise a non-zero error code.
Here is the call graph for this function:

◆ ondel()

static void ondel ( struct inode_s * in)
static

Callback function for the diff engine to handle deleted file events. This will log a work request in the thread pool for any command sets which match the deleted file event.

Parameters
inThe inode for the deleted file
Here is the call graph for this function:
Here is the caller graph for this function:

◆ onmod()

static void onmod ( struct inode_s * in)
static

Callback function for the diff engine to handle modified file events. This will log a work request in the thread pool for any command sets which match the modified file event.

Parameters
inThe inode for the modified file
Here is the call graph for this function:
Here is the caller graph for this function:

◆ onnew()

static void onnew ( struct inode_s * in)
static

Callback function for the diff engine to handle new file events. This will log a work request in the thread pool for any command sets which match the new file event.

Parameters
inThe inode for the new file
Here is the call graph for this function:
Here is the caller graph for this function:

◆ onnop()

static void onnop ( struct inode_s * in)
static

Callback function for the diff engine to handle no-op file events. This will log a work request in the thread pool for any command sets which match the unmodified file event.

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

◆ onnotify()

static void onnotify ( const enum deng_notif_t notif)
static

Callback function passed to the diff engine to handle progress notifications. This function will print a progress bar to the console when a directory is completed, and block between stage completions to ensure all thread work requests are complete before the next stage.

Parameters
notifThe notification type
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseinitargs()

static int parseinitargs ( const int argc,
char **const argv )
static

Parses the program initialization arguments into initargs.

Parameters
argcThe number of arguments
argvThe argument array
Returns
0 if successful, otherwise a non-zero error code which indicates the caller should exit.
Note
This function will print the program usage and exit(0) if the -h option is provided.
Here is the caller graph for this function:

◆ printmsspent()

static void printmsspent ( void )
static

Prints the time spent for each command set to the console.

Here is the caller graph for this function:

◆ tracefile()

static int tracefile ( const char * fp)
static

Traces which command sets match the specified file by manually invoking the command execution logic with a trace flag. lcmdexec will print the command set names that match the file.

Parameters
fpThe file path to trace
Returns
0 if successful, otherwise a non-zero error code.
Here is the call graph for this function:

◆ trigfileevent()

static void trigfileevent ( struct inode_s * in,
const int trig )
static

Queues command execution for a file event of the specified type, using the provided inode for the file information. If the skipproc flag is set, the command execution is skipped. If the verbose flag is set, the command execution is done with verbose output.

Parameters
inThe inode for the file event
trigThe file event type
Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeindex()

static int writeindex ( struct index_s * idx,
const char * fp )
static

Writes the index to the specified file path.

Parameters
idxThe index to write
fpThe file path to save the index to
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:

Variable Documentation

◆ cmdsets

struct lcmdset_s** cmdsets
static

Command sets loaded from configuration.

◆ configfile

char* configfile

Configuration file path (-c)

◆ includejunk

_Bool includejunk

Include ignored files in index (-j)

◆ indexfile

char* indexfile

Index file path (-i)

◆ [struct]

struct { ... } initargs

Managed initialization arguments for the program.

◆ lastmap

struct index_s lastmap
static

Stored index from previous run (if any)

◆ listspent

_Bool listspent

List time spent for each command set (-l)

◆ lockfile

char* lockfile

Exclusive lock file path (-x)

◆ pipefiles

_Bool pipefiles

Pipe subprocess stdout/stderr to files (-p)

◆ searchdir

char* searchdir

Search directory root (-s)

◆ skipproc

_Bool skipproc

Skip processing files, only update file index (-u)

◆ thismap

struct index_s thismap
static

Live checked index from this run.

◆ threads

int threads

Number of worker threads (-t)

◆ tracefile

char* tracefile

Trace file path (-r)

◆ verbose

_Bool verbose

Enable verbose output (-v)

◆ worklock

struct flock_s worklock
static

Exclusive work lock for local directory.