From 287bb506b9e7d2a295894a607304be47e34641a6 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Thu, 2 Feb 2012 11:57:59 +0100 Subject: [PATCH] fix symlink update (only when really changed) --- sy_old/mars_light.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/sy_old/mars_light.c b/sy_old/mars_light.c index 9d884736..95cc5c57 100644 --- a/sy_old/mars_light.c +++ b/sy_old/mars_light.c @@ -1306,9 +1306,10 @@ void _create_new_logfile(const char *path) } static -int _update_replaylink(const char *parent_path, const char *host, int sequence, loff_t start_pos, loff_t end_pos, bool check_exist) +int _update_replaylink(struct mars_global *global, const char *parent_path, const char *host, int sequence, loff_t start_pos, loff_t end_pos, bool check_exist) { struct timespec now = {}; + struct mars_dent *check; char *old = NULL; char *new = NULL; char *test = NULL; @@ -1338,6 +1339,15 @@ int _update_replaylink(const char *parent_path, const char *host, int sequence, goto out; } + /* Check whether something really has changed (avoid + * useless/disturbing timestamp updates) + */ + check = mars_find_dent(global, new); + if (check && check->new_link && !strcmp(check->new_link, old)) { + MARS_DBG("replay symlink '%s' -> '%s' has not changed\n", old, new); + goto out; + } + get_lamport(&now); status = mars_symlink(old, new, &now, 0); if (status < 0) { @@ -1360,6 +1370,7 @@ int _update_versionlink(struct mars_global *global, const char *parent_path, con struct mars_dent *prev_link = NULL; char *prev_digest = NULL; struct timespec now = {}; + struct mars_dent *check; int i; int status = -ENOMEM; int len = 0; @@ -1405,6 +1416,15 @@ int _update_versionlink(struct mars_global *global, const char *parent_path, con goto out; } + /* Check whether something really has changed (avoid + * useless/disturbing timestamp updates) + */ + check = mars_find_dent(global, new); + if (check && check->new_link && !strcmp(check->new_link, old)) { + MARS_DBG("version symlink '%s' -> '%s' has not changed\n", old, new); + goto out; + } + get_lamport(&now); status = mars_symlink(old, new, &now, 0); if (status < 0) { @@ -1467,7 +1487,7 @@ int __update_all_links(struct mars_global *global, const char *parent_path, stru status = 0; if (both) - status = _update_replaylink(parent_path, host, sequence, min_pos, max_pos, check_exist); + status = _update_replaylink(global, parent_path, host, sequence, min_pos, max_pos, check_exist); status |= _update_versionlink(global, parent_path, host, sequence, max_pos, max_pos); if (!status) trans_input->last_jiffies = jiffies;