mirror of
https://github.com/ceph/ceph
synced 2025-02-21 01:47:25 +00:00
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 <sage@inktank.com>
This commit is contained in:
parent
a7e13681e7
commit
4fc67c5228
@ -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; i<path.depth() && cur; i++) {
|
||||
unsigned i=0;
|
||||
while (i < path.depth() && cur) {
|
||||
const string &dname = path[i];
|
||||
ldout(cct, 10) << " " << i << " " << *cur << " " << dname << dendl;
|
||||
Inode *next;
|
||||
int r = _lookup(cur, dname.c_str(), &next);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (i == path.depth() - 1 && followsym &&
|
||||
next && next->is_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;
|
||||
|
Loading…
Reference in New Issue
Block a user