infra: fix removal of stale directories

This commit is contained in:
Thomas Schoebel-Theuer 2014-02-20 16:59:37 +01:00 committed by Thomas Schoebel-Theuer
parent 5d2a682cfd
commit 3acb6a02fe
3 changed files with 12 additions and 0 deletions

View File

@ -3837,6 +3837,10 @@ static int prepare_delete(void *buf, struct mars_dent *dent)
MARS_WRN("target '%s' has newer timestamp than deletion link, ignoring\n", dent->new_link);
goto ok;
}
if (target->d_child_count) {
MARS_WRN("target '%s' has %d children, cannot kill\n", dent->new_link, target->d_child_count);
goto ok;
}
status = mars_unlink(dent->new_link);
target->d_killme = true;
MARS_DBG("target '%s' deleted (status = %d) and marked for removal\n", dent->new_link, status);

View File

@ -49,6 +49,7 @@ extern char *my_id(void);
int d_class; /* for pre-grouping order */ \
int d_serial; /* for pre-grouping order */ \
int d_version; /* dynamic programming per call of mars_ent_work() */ \
int d_child_count; \
char d_once_error; \
bool d_killme; \
bool d_use_channel; \

View File

@ -674,7 +674,11 @@ found:
dent->d_type = d_type;
dent->d_class = class;
dent->d_serial = serial;
if (dent->d_parent)
dent->d_parent->d_child_count--;
dent->d_parent = cookie->parent;
if (dent->d_parent)
dent->d_parent->d_child_count++;
dent->d_depth = cookie->depth;
dent->d_global = global;
dent->d_killme = false;
@ -998,6 +1002,9 @@ void mars_free_dent(struct mars_dent *dent)
brick_string_free(dent->d_path);
brick_string_free(dent->old_link);
brick_string_free(dent->new_link);
if (likely(dent->d_parent)) {
dent->d_parent->d_child_count--;
}
if (dent->d_private_destruct) {
dent->d_private_destruct(dent->d_private);
}