Skip to content

Commit

Permalink
2009-11-12 Geoff Norton <gnorton@novell.com>
Browse files Browse the repository at this point in the history
	* mono-path.c: When resolving symlinks in a path, we need to
	split on the directory separator and check each level, as
	readlink only checks the final destination.

svn path=/trunk/mono/; revision=146071
  • Loading branch information
Geoff Norton committed Nov 12, 2009
1 parent 35595b0 commit ae4f242
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
6 changes: 6 additions & 0 deletions mono/utils/ChangeLog
@@ -1,3 +1,9 @@
2009-11-12 Geoff Norton <gnorton@novell.com>

* mono-path.c: When resolving symlinks in a path, we need to
split on the directory separator and check each level, as
readlink only checks the final destination.

2009-11-08 Rodrigo Kumpera <rkumpera@novell.com> 2009-11-08 Rodrigo Kumpera <rkumpera@novell.com>


* mono-sigcontext.h: Add ucontext support for FreeBSD/ppc64. * mono-sigcontext.h: Add ucontext support for FreeBSD/ppc64.
Expand Down
41 changes: 36 additions & 5 deletions mono/utils/mono-path.c
Expand Up @@ -86,12 +86,10 @@ mono_path_canonicalize (const char *path)
* This ensures that the path that we store points to the final file * This ensures that the path that we store points to the final file
* not a path to a symlink. * not a path to a symlink.
*/ */
gchar * #if !defined(PLATFORM_NO_SYMLINKS)
mono_path_resolve_symlinks (const char *path) static gchar *
resolve_symlink (const char *path)
{ {
#if defined(PLATFORM_NO_SYMLINKS)
return mono_path_canonicalize (path);
#else
char *p, *concat, *dir; char *p, *concat, *dir;
char buffer [PATH_MAX+1]; char buffer [PATH_MAX+1];
int n, iterations = 0; int n, iterations = 0;
Expand Down Expand Up @@ -120,6 +118,39 @@ mono_path_resolve_symlinks (const char *path)
g_free (concat); g_free (concat);
} while (iterations < MAXSYMLINKS); } while (iterations < MAXSYMLINKS);


return p;
}
#endif

gchar *
mono_path_resolve_symlinks (const char *path)
{
#if defined(PLATFORM_NO_SYMLINKS)
return mono_path_canonicalize (path);
#else
gchar **split = g_strsplit (path, G_DIR_SEPARATOR_S, -1);
gchar *p = g_strdup_printf ("");
int i;

for (i = 0; split [i] != NULL; i++) {
gchar *tmp = NULL;

// resolve_symlink of "" goes into canonicalize which resolves to cwd
if (strcmp (split [i], "") != 0) {
tmp = g_strdup_printf ("%s%s", p, split [i]);
g_free (p);
p = resolve_symlink (tmp);
g_free (tmp);
}

if (split [i+1] != NULL) {
tmp = g_strdup_printf ("%s%s", p, G_DIR_SEPARATOR_S);
g_free (p);
p = tmp;
}
}

g_free (split);
return p; return p;
#endif #endif
} }
Expand Down

0 comments on commit ae4f242

Please sign in to comment.