From 9f25365263682b2b8cb7ef760d9668157830f566 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 10 Feb 2016 19:55:35 -0600 Subject: [PATCH] win32_apply.c: don't add extra slash to link target --- src/win32_apply.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/win32_apply.c b/src/win32_apply.c index faacd718..3a2c077d 100644 --- a/src/win32_apply.c +++ b/src/win32_apply.c @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2013, 2014, 2015 Eric Biggers + * Copyright (C) 2013-2016 Eric Biggers * * This file is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free @@ -2109,6 +2109,17 @@ try_rpfix(struct reparse_buffer_disk *rpbuf, u16 *rpbuflen_p, target_ntpath_nchars = ctx->target_ntpath.Length / sizeof(wchar_t); + /* If the target directory is a filesystem root, such as \??\C:\, then + * it already will have a trailing slash. Don't include this slash if + * we are already adding slashes via 'relpath'. This prevents an extra + * slash from being generated each time the link is extracted. And + * unlike on UNIX, the number of slashes in paths on Windows can be + * significant; Windows won't understand the link target if it contains + * too many slashes. */ + if (target_ntpath_nchars > 0 && relpath_nchars > 0 && + ctx->target_ntpath.Buffer[target_ntpath_nchars - 1] == L'\\') + target_ntpath_nchars--; + fixed_subst_name_nchars = target_ntpath_nchars + relpath_nchars; wchar_t fixed_subst_name[fixed_subst_name_nchars]; -- 2.43.0