If we are walking /a/b/c and a or b is a symlink, follow it. It's only
c that we don't follow when !followsym.
Signed-off-by: Sage Weil <sage@inktank.com>
int r = _lookup(cur, dname.c_str(), &next);
if (r < 0)
return r;
- if (i == path.depth() - 1 &&
- followsym &&
- next &&
- next->is_symlink()) {
- // resolve symlink
+ // only follow trailing symlink if followsym. always follow
+ // 'directory' symlinks.
+ if (next &&
+ next->is_symlink() &&
+ (followsym || i < path.depth() - 1)) {
if (next->symlink[0] == '/') {
path = next->symlink.c_str();
// reset position