[nginx] Win32: non-ASCII directory names support in ngx_delete_dir().

Sergey Kandaurov pluknet at nginx.com
Fri Feb 24 10:32:59 UTC 2023


details:   https://hg.nginx.org/nginx/rev/7d60e4584d9e
branches:  
changeset: 8134:7d60e4584d9e
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Thu Feb 23 20:49:47 2023 +0300
description:
Win32: non-ASCII directory names support in ngx_delete_dir().

This makes it possible to delete directories with non-ASCII characters
when using the dav module (ticket #1433).

diffstat:

 src/os/win32/ngx_files.c |  36 ++++++++++++++++++++++++++++++++++++
 src/os/win32/ngx_files.h |   2 +-
 2 files changed, 37 insertions(+), 1 deletions(-)

diffs (58 lines):

diff -r e0f385521c79 -r 7d60e4584d9e src/os/win32/ngx_files.c
--- a/src/os/win32/ngx_files.c	Thu Feb 23 20:49:45 2023 +0300
+++ b/src/os/win32/ngx_files.c	Thu Feb 23 20:49:47 2023 +0300
@@ -614,6 +614,42 @@ failed:
 
 
 ngx_int_t
+ngx_delete_dir(u_char *name)
+{
+    long        rc;
+    size_t      len;
+    u_short    *u;
+    ngx_err_t   err;
+    u_short     utf16[NGX_UTF16_BUFLEN];
+
+    len = NGX_UTF16_BUFLEN;
+    u = ngx_utf8_to_utf16(utf16, name, &len, 0);
+
+    if (u == NULL) {
+        return NGX_FILE_ERROR;
+    }
+
+    rc = NGX_FILE_ERROR;
+
+    if (ngx_win32_check_filename(u, len, 0) != NGX_OK) {
+        goto failed;
+    }
+
+    rc = RemoveDirectoryW(u);
+
+failed:
+
+    if (u != utf16) {
+        err = ngx_errno;
+        ngx_free(u);
+        ngx_set_errno(err);
+    }
+
+    return rc;
+}
+
+
+ngx_int_t
 ngx_open_glob(ngx_glob_t *gl)
 {
     u_char     *p;
diff -r e0f385521c79 -r 7d60e4584d9e src/os/win32/ngx_files.h
--- a/src/os/win32/ngx_files.h	Thu Feb 23 20:49:45 2023 +0300
+++ b/src/os/win32/ngx_files.h	Thu Feb 23 20:49:47 2023 +0300
@@ -206,7 +206,7 @@ ngx_int_t ngx_create_dir(u_char *name, n
 #define ngx_create_dir_n            "CreateDirectory()"
 
 
-#define ngx_delete_dir(name)        RemoveDirectory((const char *) name)
+ngx_int_t ngx_delete_dir(u_char *name);
 #define ngx_delete_dir_n            "RemoveDirectory()"
 
 


More information about the nginx-devel mailing list