libite/rsync.c
/**
 * rsync - Synchronize contents and optionally remove non-existing backups
 * @src: Source directory
 * @dst: Destination directory
 * @delete: Prune files from @dst that no longer exist in @src.
 * @filter: Optional filtering function for source directory.
 *
 * This is a miniature implementation of the famous rsync for local use only.
 * In fact, it is not even a true rsync since it copies all files from @src
 * to @dst.  The @delete option is useful for creating backups, when set all
 * files removed from src since last backup are pruned from the destination
 * (backup) directory.
 *
 * The filter callback, @filter, if provided, is used to determine what files to
 * include from the source directory when backing up.  If a file is to be skipped
 * the callback should simply return zero.
 *
 * Returns:
 * POSIX OK(0), or non-zero with @errno set on error.
 */


This is a miniature implementation of the famous rsync for local use only.
In fact, it is not even a true rsync since it copies all files from @src
to @dst.  The @delete option is useful for creating backups, when set all
files removed from src since last backup are pruned from the destination
(backup) directory.

The filter callback, @filter, if provided, is used to determine what files to
include from the source directory when backing up.  If a file is to be skipped
the callback should simply return zero.

POSIX OK(0), or non-zero with @errno set on error.
This is a miniature implementation of the famous rsync for local use only . In fact it is not even a true rsync since it copies all files from @src to @dst . The @delete option is useful for creating backups when set all files removed from src since last backup are pruned from the destination ( backup ) directory . The filter callback @filter if provided is used to determine what files to include from the source directory when backing up . If a file is to be skipped the callback should simply return zero . POSIX OK ( 0 ) or non - zero with @errno set on error .
int rsync(char *src, char *dst, int delete, int (*filter) (const char *file))
{
	char source[256];
	char dest[256];
	int i = 0, num = 0, result = 0;
	char **files;		
	if (!fisdir(dst))
		makedir(dst, 0755);
	if (!fisdir(src)) {
		if (!fexist(src))
			return 1;
		if (copy(src, dst))
			result++;
		return errno;
	}
	if (!fisslashdir(src)) {
		char *ptr = rindex(src, '/');
		if (!ptr)
			ptr = src;
		else
			ptr++;
		if (mdir(dest, sizeof(dest), dst, ptr, fmode(src)))
			return 1;
		dst = dest;
	}
	num = dir(src, "", filter, &files, 0);
	for (i = 0; i < num; i++) {
		snprintf(source, sizeof(source), "%s%s%s", src, fisslashdir(src) ? "" : "/", files[i]);
		if (fisdir(source)) {
			char dst2[256];
			strcat(source, "/");
			if (mdir (dst2, sizeof(dst2), dst, files[i], fmode(source))) {
				result++;
				continue;
			}
			rsync(source, dst2, delete, filter);
			continue;	
		}
		if (copy(source, dst))
			result++;
	}
	if (delete)
		prune(dst, files, num);
	if (num) {
		for (i = 0; i < num; i++)
			free(files[i]);
		free(files);
	}
	return result;
}
int rsync ( char * src , char * dst , int delete , int ( * filter ) ( const char * file ) ) { char source [ 256 ] ; char dest [ 256 ] ; int i = 0 , num = 0 , result = 0 ; char * * files ; if ( ! fisdir ( dst ) ) makedir ( dst , 0755 ) ; if ( ! fisdir ( src ) ) { if ( ! fexist ( src ) ) return 1 ; if ( copy ( src , dst ) ) result ++ ; return errno ; } if ( ! fisslashdir ( src ) ) { char * ptr = rindex ( src , ' ' ) ; if ( ! ptr ) ptr = src ; else ptr ++ ; if ( mdir ( dest , sizeof ( dest ) , dst , ptr , fmode ( src ) ) ) return 1 ; dst = dest ; } num = dir ( src , " " , filter , & files , 0 ) ; for ( i = 0 ; i < num ; i ++ ) { snprintf ( source , sizeof ( source ) , " " , src , fisslashdir ( src ) ? " " : " " , files [ i ] ) ; if ( fisdir ( source ) ) { char dst2 [ 256 ] ; strcat ( source , " " ) ; if ( mdir ( dst2 , sizeof ( dst2 ) , dst , files [ i ] , fmode ( source ) ) ) { result ++ ; continue ; } rsync ( source , dst2 , delete , filter ) ; continue ; } if ( copy ( source , dst ) ) result ++ ; } if ( delete ) prune ( dst , files , num ) ; if ( num ) { for ( i = 0 ; i < num ; i ++ ) free ( files [ i ] ) ; free ( files ) ; } return result ; }
rsync - Synchronize contents and optionally remove non-existing backups
 @src: Source directory
 @dst: Destination directory
 @delete: Prune files from @dst that no longer exist in @src.
rsync - Synchronize contents and optionally remove non - existing backups @src : Source directory @dst : Destination directory @delete : Prune files from @dst that no longer exist in @src .
/* Array of file names. */ /* Copy dir as well? */ /* Recursively copy sub-directries */ /* Next file/dir in @src to copy... */ /* We ignore any errors from the pruning, that phase albeit useful is only
	 * cosmetic. --Jocke 2011-03-24 */