Filesync is a utility which makes it easy to keep two places synchron. It listens on the one place for changes and applies them to the other.
Basic functionality:
- Synchronize two directories
State:
- Branched
New features:
New features:
All Sub-versions will be used to submit patches and bugfixes etc.
Option | Description |
---|---|
-r, --rsync | Rsync executable path. |
-s, --source | The path to the source directory. |
-t, --target | The path to the target directory. |
-d, --depth | The depth to dive into the |
directory. | |
-D, --daemon | Runs filesync as daemon. |
-p, --pid-file | Sets the file in which the daemon writes its PID. |
-l, --log-file | The log-file to redirect messages to (default: stderr). |
-c, --conf-file | A lua configuration file. |
Filesync can be used as a daemon using the initscript filesyncd.
This is configured through a configuration either in $HOME/.filesyncrc
,
/etc/filesyncrc
or in a file specified through the --config
option.
The configuration-file is a simple bash script which can set the following options:
FILESYNC_EXE=filesync_path JOBS=(config_files ...)
config_files
are lua scripts according to the Profile functionality.
Filesync will be able to limit the watching depth. Means the depth of diving recoursive into a directory.
- -1 means unlimited depth
- 0 means: visit only the given directory without watching any subdirectories.
- n: Visit n subdirectory-levels.
Implemented as enum.
enum BOOL { FALSE, TRUE }
src/watch_session.h src/watch_session.c
struct watch_session *new_watch_session(); struct watch_session { /** \brief The src directory which is watched. */ char *src; /** \brief The target which will be synchronized. */ char *target; /** \brief The path to the rsync-executable. */ char *rsync_path; /** \brief The depth to watch the source directory. */ int depth; /** \brief Inotify dscriptor. */ int notify_descr; /** \brief The watch-table. */ struct dir_watch *watch_table; /** \brief The watch filter mask. */ uint32_t watch_mask; }; void destroy_watch_session(struct watch_session *ws);
depth = -1 means unlimited depth. rsync-cmd-cache is a buffer for the prebuild (Build rsync command) rsync command.
file:src/watch_session.c::/* TODO: Free the hash structure. */
file:src/watch_session.c::/* TODO: Fix this with default bitmask. */
Also affects src/notify.c
The logging mechanism should be used to output various messages. Three levels are defined which should be used in appropriate situations.
Level | Description |
---|---|
INFO | A normal program message. |
WARN | Outputted if warnings are enabled. |
ERROR | Always outputted (system critical errors). |
DEBUG | Only outputted if debug is explicitely requested. |
The levels are implemented using int constants which can be concatenated to a flag map.
Logging has a unique interface where it is easy to write to log files or use the standard error output etc. The logging interface is initialized using a initialization function that takes a pointer to the FILE object which will be used for logging. The second argument shows whether a newline should be appended to each output. The initialization function needs to be called at least once. Otherwise the program will abort on a logging request.
The initialization function initializes the logging interface and configures it.
void init_log(FILE *c, BOOL nl, int filter);
The second argument is of Boolean type. The third argument tells the interface which levels should be logged. The logging itself is done using the log\_msg() function. It takes the level and the string (as format string) to log.
void log_msg(LOG_LEVEL l, const char *fmt, ...);
The logging should be closed using the close function. This function closes the stored file descriptor (if != stderr and != stdout).
void close_log();
The rsync-cmd-cache field in the watch-session structure represents a template of the used rsync command. This can be done because we need only one command all the time with different parameters. But these parameters can be format sprintf. The building of the command should be done by a seperate function.
char *build_rsync_cmd_tmpl(const char *rsync_path, const char *src);
src/rsync_proxy.h src/rsync_proxy.c
A proxy function that abstracts the rsync call.
int sync_file(struct watch_session *ws, const char *path);
path should be relative to the target path. The function should return a value != 0 if something went wrong. A value != 0 is a constant that can be looked up in a error table.
src/cmdparser.h src/cmdparser.c
A command line parser which parses the command line and fills the fields of a watch_session structure.
The command line mainly consists of a method that takes a pointer to a watch-session struct. This watch-session is filled with the information extracted from the command line. The watch session should be created with new_watch_session().
Errors and warnings are logged through the logging interface. A return-value != 0 indicates an error while parsing.
int parse_cmd_line(struct watch_session *ws, int argc, const char **argv);
file:src/main.c::/* TODO: make the verbosity level cutomizable through command line. */
The user authentication should be done with ssh-keys or standard-input. Filesync doesn’t support plain text authentication via the command line interface to avoid attackers to read the password via the process table.
struct dir_watch { int wd; /** \brief The path of the watched directory (relative to the top level). */ char *path; /** \brief The depth-level of the watched directory. */ int depth_level; /** \brief Needed to make this hashable. */ UT_hash_handle hh; };
Top-level (src directory) is level 0.
Makes it possible to exclude certain files from synchronization.
This describes the possibility to declare filesync options within a config file (profile) and call filesync with this config file as configuration instruction.
A configuration file is a simple lua script which can set the following variables which will be interpreted by filesync.
src = "Your source directory" target = "Your target" exclude = "Exclude regex" depth = -1
Filesync should be a daemon that runs in memory and waits for requests that tell him to watch a certain directory and synchronize it with another.
Unix-Sockets will be used as communication interface.
Command (1 byte) | Argument | EOF |
---|
enum command { ADD_JOB, SHUTDOWN };
The first byte of the message is the command byte. It specifies what the daemon should do. The rest of the message is reserved for arguments for the command.
Command | Arguments | Description |
---|---|---|
ADD_JOB | <src>\0<target>\0<depth>\0<watch-mask> | This command |
takes the src-directory, target- | ||
directory, depth and watch-mask | ||
seperated by null-bytes. It creates then | ||
a new watch-session and launches it. | ||
SHUTDOWN | <none> | This argument simply shuts the daemon down. |
Copyright (C) 2010, 2011 Dominik Burgdörfer <dominik.burgdoerfer@googlemail.com>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.