[PATCH] fix ngx_realpath() for win32

Maxim Dounin mdounin at mdounin.ru
Tue Nov 1 15:29:28 UTC 2022


Hello!

On Tue, Nov 01, 2022 at 08:15:48PM +0900, Won-Kyu Park wrote:

> # HG changeset patch
> # User Won-Kyu Park <wkpark at gmail.com>
> # Date 1667298839 -32400
> #      Tue Nov 01 19:33:59 2022 +0900
> # Node ID c964b33d60679f5cd8d43a8f859d16c2ac6f89e1
> # Parent  1ae25660c0c76edef14121ca64362f28b9d57a70
> fix ngx_realpath() for win32
> 
> diff -r 1ae25660c0c7 -r c964b33d6067 src/os/win32/ngx_files.c
> --- a/src/os/win32/ngx_files.c Wed Oct 19 10:56:21 2022 +0300
> +++ b/src/os/win32/ngx_files.c Tue Nov 01 19:33:59 2022 +0900
> @@ -416,14 +416,6 @@
>  }
> 
> 
> -u_char *
> -ngx_realpath(u_char *path, u_char *resolved)
> -{
> -    /* STUB */
> -    return path;
> -}
> -
> -
>  ngx_int_t
>  ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir)
>  {
> diff -r 1ae25660c0c7 -r c964b33d6067 src/os/win32/ngx_files.h
> --- a/src/os/win32/ngx_files.h Wed Oct 19 10:56:21 2022 +0300
> +++ b/src/os/win32/ngx_files.h Tue Nov 01 19:33:59 2022 +0900
> @@ -172,7 +172,7 @@
>  void ngx_close_file_mapping(ngx_file_mapping_t *fm);
> 
> 
> -u_char *ngx_realpath(u_char *path, u_char *resolved);
> +#define ngx_realpath(path, resolved) (u_char *)_fullpath((char
> *)(resolved), (char *)(path), MAX_PATH)
>  #define ngx_realpath_n              ""
>  #define ngx_getcwd(buf, size)       GetCurrentDirectory(size, (char *) buf)
>  #define ngx_getcwd_n                "GetCurrentDirectory()"
> 
> ---- END --------
> This small fix would set $realpath_root as expected for win32.

Could you please clarify "as expected"?

It doesn't look like _fullpath() resolves symbolic links, which is 
expected behaviour for $realpath_root.

Rather, it looks like GetFinalPathNameByHandle() should be used if 
we want to actually support $realpath_root as it is expected to 
work, that is, providing path with symlinks resolved.  It might be 
tricky to use it though, as it is only available in Windows Vista 
or later.

-- 
Maxim Dounin
http://mdounin.ru/



More information about the nginx-devel mailing list