From 4fc67c5228be815650d8b0ba36943a5e7efac276 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 4 Nov 2012 04:34:20 -0800 Subject: [PATCH] client: simplify path_walk() loop Most paths were kludging around the for loop's i++. Switch to a while loop to avoid such tomfoolery. Signed-off-by: Sage Weil --- src/client/Client.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 92e794f168f43..a699122ea6b09 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -3719,34 +3719,36 @@ int Client::path_walk(const filepath& origpath, Inode **final, bool followsym) ldout(cct, 10) << "path_walk " << path << dendl; - for (unsigned i=0; iis_symlink()) { + if (i == path.depth() - 1 && + followsym && + next && + next->is_symlink()) { // resolve symlink if (next->symlink[0] == '/') { path = next->symlink.c_str(); - next = root; - // reset position - will get incremented to 0 - i = -1; + // reset position + cur = root; + i = 0; } else { filepath more(next->symlink.c_str()); // we need to remove the symlink component from off of the path - // before adding the target that the symlink points to + // before adding the target that the symlink points to. remain + // at the same position in the path. path.pop_dentry(); path.append(more); - // reset position in path walk - --i; - // remain at the same inode - next = cur; } + continue; } cur = next; + i++; } if (!cur) return -ENOENT; -- 2.39.5