mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-13 22:48:29 +00:00
changed delayed boolean to dirdelay pointers
This commit is contained in:
parent
f7b6450c2e
commit
464852202b
94
lsyncd.c
94
lsyncd.c
@ -207,9 +207,16 @@ struct watch {
|
|||||||
struct watch *parent;
|
struct watch *parent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On a delay to be handled.
|
* There is one or several delays to be handled
|
||||||
|
* dor this directory
|
||||||
|
*
|
||||||
|
* In case of non-atomic opperation this points
|
||||||
|
* directly to the delay struct.
|
||||||
|
*
|
||||||
|
* In case of atomic opperatoin this points to
|
||||||
|
* a file_delay_vector struct.
|
||||||
*/
|
*/
|
||||||
bool delayed;
|
void * dirdelay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The applicable configuration for this directory
|
* The applicable configuration for this directory
|
||||||
@ -415,6 +422,11 @@ struct delay {
|
|||||||
* Pointer to the next delay.
|
* Pointer to the next delay.
|
||||||
*/
|
*/
|
||||||
struct delay * next;
|
struct delay * next;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pointer to the before delay.
|
||||||
|
*/
|
||||||
|
struct delay * before;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1029,33 +1041,39 @@ dir_conf_add_target(const struct log *log, struct dir_conf *dir_conf, char *targ
|
|||||||
/**
|
/**
|
||||||
* Adds a directory on the delays list
|
* Adds a directory on the delays list
|
||||||
*
|
*
|
||||||
* @param log logging information
|
* @param opts global options
|
||||||
* @param delays the delays FIFO
|
* @param delays the delays FIFO
|
||||||
* @param watch the index in watches to the directory
|
* @param watch the index in watches to the directory
|
||||||
* @param alarm times() when the directory should be acted
|
* @param alarm times() when the directory should be acted
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
append_delay(const struct log *log,
|
append_delay(const struct global_options *opts,
|
||||||
struct delay_vector *delays,
|
struct delay_vector *delays,
|
||||||
struct watch *watch,
|
struct watch *watch,
|
||||||
clock_t alarm)
|
clock_t alarm)
|
||||||
{
|
{
|
||||||
|
const struct log *log = &opts->log;
|
||||||
struct delay * newd;
|
struct delay * newd;
|
||||||
if (watch->delayed) {
|
if (watch->dirdelay) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
watch->delayed = true;
|
|
||||||
|
|
||||||
newd = s_calloc(log, 1, sizeof(struct delay), "a delay");
|
newd = s_calloc(log, 1, sizeof(struct delay), "a delay");
|
||||||
newd->watch = watch;
|
newd->watch = watch;
|
||||||
newd->alarm = alarm;
|
newd->alarm = alarm;
|
||||||
newd->next = NULL;
|
newd->next = NULL;
|
||||||
|
|
||||||
|
if (opts->flag_atomic) {
|
||||||
|
exit(1); //TODO ATOMIC
|
||||||
|
} else {
|
||||||
|
watch->dirdelay = newd;
|
||||||
|
}
|
||||||
|
|
||||||
if (!delays->first) {
|
if (!delays->first) {
|
||||||
// delays vector was empty
|
// delays vector was empty
|
||||||
delays->first = delays->last = newd;
|
delays->first = delays->last = newd;
|
||||||
} else {
|
} else {
|
||||||
delays->last->next = newd;
|
delays->last->next = newd;
|
||||||
|
newd->before = delays->last;
|
||||||
delays->last = newd;
|
delays->last = newd;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1067,12 +1085,19 @@ append_delay(const struct log *log,
|
|||||||
* @param delays the delay FIFO.
|
* @param delays the delay FIFO.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
remove_first_delay(struct delay_vector *delays)
|
remove_first_delay(const struct global_options *opts, struct delay_vector *delays)
|
||||||
{
|
{
|
||||||
struct delay *fd = delays->first;
|
struct delay *fd = delays->first;
|
||||||
fd->watch->delayed = false;
|
if (opts->flag_atomic) {
|
||||||
|
exit(1); // TODO ATOMIC
|
||||||
|
} else {
|
||||||
|
fd->watch->dirdelay = NULL;
|
||||||
|
}
|
||||||
delays->first = fd->next;
|
delays->first = fd->next;
|
||||||
if (!delays->first) {
|
if (delays->first) {
|
||||||
|
delays->first->before = NULL;
|
||||||
|
} else {
|
||||||
|
// this was the only entry
|
||||||
delays->last = NULL;
|
delays->last = NULL;
|
||||||
}
|
}
|
||||||
s_free(fd);
|
s_free(fd);
|
||||||
@ -1339,7 +1364,7 @@ add_watch(const struct global_options *opts,
|
|||||||
w->parent = parent;
|
w->parent = parent;
|
||||||
w->dirname = s_strdup(log, dirname, "dirname");
|
w->dirname = s_strdup(log, dirname, "dirname");
|
||||||
w->dir_conf = dir_conf;
|
w->dir_conf = dir_conf;
|
||||||
w->delayed = false;
|
w->dirdelay = NULL;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1498,7 +1523,7 @@ delay_or_act_dir(const struct global_options *opts,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = append_delay(log, delays, watch, alarm);
|
ret = append_delay(opts, delays, watch, alarm);
|
||||||
if (event_name) {
|
if (event_name) {
|
||||||
printlogf(log, NORMAL, "%s %s in %s%s - delayed.",
|
printlogf(log, NORMAL, "%s %s in %s%s - delayed.",
|
||||||
event_text, event_name, pathname, ret ? "" : " already");
|
event_text, event_name, pathname, ret ? "" : " already");
|
||||||
@ -1705,29 +1730,26 @@ remove_dirwatch(const struct global_options *opts,
|
|||||||
s_free(w->dirname);
|
s_free(w->dirname);
|
||||||
w->dirname = NULL;
|
w->dirname = NULL;
|
||||||
|
|
||||||
// remove a possible delay
|
|
||||||
// (this dir is on the to do/delay list)
|
if (!w->dirdelay) {
|
||||||
if (w->delayed) {
|
return true;
|
||||||
struct delay *d, *bd; // the current and the pointer before.
|
}
|
||||||
bd = NULL;
|
// otherwise remove the delay entries for this dir.
|
||||||
d = delays->first;
|
if (opts->flag_atomic) {
|
||||||
while (d) {
|
exit(1); // TODO ATOMIC
|
||||||
if (d->watch == w) {
|
} else {
|
||||||
// remove this entry
|
struct delay * d = (struct delay *) w->dirdelay;
|
||||||
if (bd) {
|
if (d->before) {
|
||||||
bd->next = d->next;
|
d->before->next = d->next;
|
||||||
} else {
|
} else {
|
||||||
// this is the first;
|
// this was first entry
|
||||||
delays->first = d->next;
|
delays->first = d->next;
|
||||||
}
|
}
|
||||||
if (delays->last == d) {
|
if (d->next) {
|
||||||
delays->last = bd;
|
d->next->before = d->before;
|
||||||
}
|
} else {
|
||||||
s_free(d);
|
// this was last entry
|
||||||
break;
|
delays->last = d->before;
|
||||||
}
|
|
||||||
bd = d;
|
|
||||||
d = d->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1948,7 +1970,7 @@ master_loop(const struct global_options *opts,
|
|||||||
// again as time may progresses while handling delayed entries.
|
// again as time may progresses while handling delayed entries.
|
||||||
while (delays->first && time_after_eq(times(NULL), delays->first->alarm)) {
|
while (delays->first && time_after_eq(times(NULL), delays->first->alarm)) {
|
||||||
rsync_dir(opts, delays->first->watch, "delay expired");
|
rsync_dir(opts, delays->first->watch, "delay expired");
|
||||||
remove_first_delay(delays);
|
remove_first_delay(opts, delays);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ touch "${WORKSOURCE}"/a/f
|
|||||||
touch "${WORKSOURCE}"/b/g
|
touch "${WORKSOURCE}"/b/g
|
||||||
|
|
||||||
echo -e "$CON* starting lsyncd.$COFF"
|
echo -e "$CON* starting lsyncd.$COFF"
|
||||||
./lsyncd --logfile "${LOGFILE}" --pidfile "${PIDFILE}" "${WORKSOURCE}" "${WORKTARGET}"
|
./lsyncd --no-daemon --logfile "${LOGFILE}" --pidfile "${PIDFILE}" "${WORKSOURCE}" "${WORKTARGET}"&
|
||||||
LSYNCPID=$(cat "${PIDFILE}")
|
LSYNCPID=$(cat "${PIDFILE}")
|
||||||
|
|
||||||
echo -e "$CON* waiting for lsyncd to start.$COFF"
|
echo -e "$CON* waiting for lsyncd to start.$COFF"
|
||||||
|
Loading…
Reference in New Issue
Block a user