From 6e8e837864d4e24c2fdb4d90e8eb262ded78c3a8 Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Sun, 28 Feb 2016 01:52:11 +0100
Subject: Fix mustbedir mechanism for symlinks

* libdiskfs/dir-lookup.c (diskfs_S_dir_lookup): When following a symlink,
if mustbedir is true, always append a slash to the symlink target, not only
when the target is absolute.  Reset mustbedir to 0 before continuing the
lookup loop.
* libnetfs/dir-lookup.c (netfs_S_dir_lookup): When following a symlink,
if mustbedir is true, append a slash to the symlink target. Reset mustbedir
to 0 before continuing the lookup loop.
* libtreefs/dir-lookup.c (_treefs_s_dir_lookup): Likewise.
---
 libtreefs/dir-lookup.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'libtreefs')

diff --git a/libtreefs/dir-lookup.c b/libtreefs/dir-lookup.c
index 8665059c..80b55388 100644
--- a/libtreefs/dir-lookup.c
+++ b/libtreefs/dir-lookup.c
@@ -229,7 +229,7 @@ _treefs_s_dir_lookup (struct treefs_handle *h,
 	    /* Symlink contents + extra path won't fit in our buffer, so
 	       reallocate it and try again.  */
 	    {
-	      path_buf_len = sym_len + nextname_len + 1;
+	      path_buf_len = sym_len + nextname_len + 1 + 1;
 	      path_buf = alloca (path_buf_len);
 	      err = treefs_node_get_symlink (node, path_buf, &sym_len);
 	    }
@@ -241,7 +241,13 @@ _treefs_s_dir_lookup (struct treefs_handle *h,
 	      path_buf[sym_len] = '/';
 	      bcopy (nextname, path_buf + sym_len + 1, nextname_len - 1);
 	    }
-	  path_buf[nextname_len + sym_len] = '\0';
+	  if (mustbedir)
+	    {
+	      path_buf[nextnamelen + sym_len] = '/';
+	      path_buf[nextnamelen + sym_len + 1] = '\0';
+	    }
+	  else
+	    path_buf[nextname_len + sym_len] = '\0';
 
 	  if (path_buf[0] == '/')
 	    {
@@ -253,6 +259,7 @@ _treefs_s_dir_lookup (struct treefs_handle *h,
 	    }
 	  
 	  path = path_buf;
+	  mustbedir = 0;
 	  if (lastcomp)
 	    {
 	      lastcomp = 0;
-- 
cgit v1.2.3