Re: [PATCH 1/1] mingw: handle absolute paths in expand_user_path()
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Nov 6, 2018, 21:32 UTC
- Message-ID
- <a374e4bb-1970-9ec7-fe94-a273f1206d6b@kdbg.org>
- In-Reply-To
- <2287dd96cf0b9e9e250fdf92a32dcf666510e67d.1541515994.git.gitgitgadget@gmail.com>
Am 06.11.18 um 15:53 schrieb Johannes Schindelin via GitGitGadget:
> From: Johannes Schindelin <johannes.schindelin@gmx.de> > > On Windows, an absolute POSIX path needs to be turned into a Windows > one.
If I were picky, I would say that in a pure Windows application there cannot be POSIX paths to begin with.
Even if a path looks like a POSIX paths, i.e. it starts with a directory separator, but not with drive-letter-colon, it still has a particular meaning, namely (as far as I know) that the path is anchored at the root of the drive of the current working directory.
If a user specifies such a path on Windows, and it must undergo expand_user_path(), then that is a user error, or the user knows what they are doing.
I think it is wrong to interpret such a path as relative to some random other directory, like this patch seems to do.
Show 30 quoted lines
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> path.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/path.c b/path.c
> index 34f0f98349..a72abf0e1f 100644
> --- a/path.c
> +++ b/path.c
> @@ -11,6 +11,7 @@
> #include "path.h"
> #include "packfile.h"
> #include "object-store.h"
> +#include "exec-cmd.h"
>
> static int get_st_mode_bits(const char *path, int *mode)
> {
> @@ -709,6 +710,10 @@ char *expand_user_path(const char *path, int real_home)
>
> if (path == NULL)
> goto return_null;
> +#ifdef __MINGW32__
> + if (path[0] == '/')
> + return system_path(path + 1);
> +#endif
> if (path[0] == '~') {
> const char *first_slash = strchrnul(path, '/');
> const char *username = path + 1;
>