>From 4a3da8b88d64958b49faf3e52e2f399dcf31e668 Mon Sep 17 00:00:00 2001
From: Karol Lewandowski <[email protected]>
Date: Fri, 28 Jan 2011 17:43:31 +0100
Subject: [PATCH 1/3] Fix: Handle symlinks with trailing slash correctly

Don't append trailing slash just because some symlink in the middle of
resolved path had it.

This fixes following error:

  $ mkdir dir
  $ ln -s dir/ sdir
  $ touch dir/touchme
  $ sb2 -- cat sdir/touchme
cat: sdir/touchme: Not a directory

  $ strace -f sb2 -- cat sdir/touchme
[..]
[pid  2432] readlink("/home/lmctl/testdir/sdir", "dir/"..., 4096) = 4
[pid  2432] readlink("/home/lmctl/testdir", 0xbfb94a87, 4096) = -1 EINVAL (Invalid argument)
[pid  2432] readlink("/home/lmctl/testdir/dir", 0xbfb94a87, 4096) = -1 EINVAL (Invalid argument)
[pid  2432] readlink("/home/lmctl/testdir/dir/touchme", 0xbfb94a87, 4096) = -1 EINVAL (Invalid argument)
[pid  2432] open("dir/touchme/", O_RDONLY|O_LARGEFILE) = -1 ENOTDIR (Not a directory)

Change-Id: I14698359b8ede3aa8e9467e4b90611bcd7e2d275
---
 luaif/paths.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/luaif/paths.c b/luaif/paths.c
index 86763e0..639c436 100644
--- a/luaif/paths.c
+++ b/luaif/paths.c
@@ -1320,6 +1320,19 @@ static void sb_path_resolution_resolve_symlink(
 
 		SB_LOG(SB_LOGLEVEL_NOISE, "absolute symlink");
 		symlink_entries = split_path_to_path_entries(link_dest, &flags);
+
+		/* If we aren't resolving last component of path
+		 * then we have to clear out the "trailing slash
+		 * flag".  Without this we would end up with '/'
+		 * appended when any of the symlinks we traverse
+		 * ends up with slash ("a -> b/").
+		 *
+		 * We have to do the same for relative symlinks
+		 * (see below).
+		 */
+		if (virtual_path_work_ptr->pe_next)
+		     flags &= ~PATH_FLAGS_HAS_TRAILING_SLASH;
+
 		if (rest_of_virtual_path) {
 			append_path_entries(symlink_entries, rest_of_virtual_path);
 			rest_of_virtual_path = NULL;
@@ -1355,6 +1368,13 @@ static void sb_path_resolution_resolve_symlink(
 		}
 
 		link_dest_entries = split_path_to_path_entries(link_dest, &flags);
+
+		/* Avoid problems with symlinks containing trailing
+		 * slash ("a -> b/").
+		 */
+		if (virtual_path_work_ptr->pe_next)
+		     flags &= ~PATH_FLAGS_HAS_TRAILING_SLASH;
+
 		symlink_entries = append_path_entries(
 			dirnam_entries, link_dest_entries);
 		link_dest_entries = NULL;
-- 
1.7.0.4

_______________________________________________
Scratchbox-devel mailing list
[email protected]
http://lists.scratchbox.org/cgi-bin/mailman/listinfo/scratchbox-devel

Reply via email to