[PATCH 05 of 12] Win32: non-ASCII directory names support in ngx_delete_dir()

Maxim Dounin mdounin at mdounin.ru
Thu Jan 12 21:35:28 UTC 2023


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1673548963 -10800
#      Thu Jan 12 21:42:43 2023 +0300
# Node ID fbe7d76fe0398ca674b5d62b4849cd524e35bf89
# Parent  331e40f73047c03455e10212b2b8701ec5ec35d0
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).

diff -r 331e40f73047 -r fbe7d76fe039 src/os/win32/ngx_files.c
--- a/src/os/win32/ngx_files.c	Thu Jan 12 21:42:38 2023 +0300
+++ b/src/os/win32/ngx_files.c	Thu Jan 12 21:42:43 2023 +0300
@@ -602,6 +602,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 331e40f73047 -r fbe7d76fe039 src/os/win32/ngx_files.h
--- a/src/os/win32/ngx_files.h	Thu Jan 12 21:42:38 2023 +0300
+++ b/src/os/win32/ngx_files.h	Thu Jan 12 21:42:43 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