Skip to content

Commit

Permalink
fix renames when only receiving one of two events
Browse files Browse the repository at this point in the history
  • Loading branch information
petersilva committed Aug 7, 2024
1 parent be7e0c0 commit 42a5259
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sr3_cpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,15 @@ void dir_stack_check4events(struct sr_context *sr_c)
struct inotify_event *e;
struct dir_stack *d;
int ret;
/* A normal rename is two events IN_MOVED_FROM, and IN_MOVED_TO.
* if the source is outside the paths being monitored, we only get IN_MOVED_TO.
* if the destination is outside, we only get IN_MOVED_FROM.
*
* an *rename_single_event* is one where we only receive one event.
* Since we don't have anything outside the tree, this turns into a normal
* post of a file, or a removal.
*/
int rename_single_event=0;
struct rename_list *old_names = NULL, *on = NULL, *prevon = NULL;

struct hash_entry *new_entry, *entries_done, *tmpe = NULL;
Expand Down Expand Up @@ -447,13 +456,15 @@ void dir_stack_check4events(struct sr_context *sr_c)
sr_log_msg(sr_c->cfg->logctx,LOG_DEBUG, "rename, %sname=%s\n",
((e->mask & IN_MOVED_TO) ==
IN_MOVED_TO) ? "new" : "old", fn);
rename_single_event=1;
if (old_names) {
prevon = NULL;
for (on = old_names;
(on && (on->cookie != e->cookie)); on = on->next)
prevon = on;
if (on) {
if (on->ofn) {
rename_single_event=0;
sr_log_msg(sr_c->cfg->logctx,LOG_DEBUG,
"ok invoking rename ofn=%s %s\n",
on->ofn, fn);
Expand All @@ -463,6 +474,7 @@ void dir_stack_check4events(struct sr_context *sr_c)
sr_log_msg(sr_c->cfg->logctx,LOG_DEBUG,
"ok invoking rename %s nfn=%s\n",
fn, on->nfn);
rename_single_event=0;
sr_post_rename(sr_c, fn, on->nfn);
free(on->nfn);
}
Expand Down Expand Up @@ -512,7 +524,7 @@ void dir_stack_check4events(struct sr_context *sr_c)
sr_log_msg(sr_c->cfg->logctx,LOG_DEBUG,
"e->mask=%04x from: %04x to: %04x \n",
e->mask, IN_MOVED_FROM, IN_MOVED_TO);
if (!(e->mask & (IN_ATTRIB | IN_MOVED_FROM | IN_MOVED_TO))) {
if (rename_single_event || !(e->mask & (IN_ATTRIB | IN_MOVED_FROM | IN_MOVED_TO))) {
if (!(e->mask & IN_ATTRIB)
|| (sr_c->cfg->events & SR_EVENT_ATTRIB)) {
sr_log_msg(sr_c->cfg->logctx,LOG_DEBUG, "do one file: %s\n", fn);
Expand Down

0 comments on commit 42a5259

Please sign in to comment.