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

Sergey Kandaurov pluknet at nginx.com
Fri Feb 24 10:33:08 UTC 2023


details:   https://hg.nginx.org/nginx/rev/4b06186670ed
branches:  
changeset: 8137:4b06186670ed
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Thu Feb 23 20:49:54 2023 +0300
description:
Win32: non-ASCII names support in ngx_delete_file().

This makes it possible to delete files 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 37a184966ab3 -r 4b06186670ed src/os/win32/ngx_files.c
--- a/src/os/win32/ngx_files.c	Thu Feb 23 20:49:52 2023 +0300
+++ b/src/os/win32/ngx_files.c	Thu Feb 23 20:49:54 2023 +0300
@@ -207,6 +207,42 @@ ngx_write_console(ngx_fd_t fd, void *buf
 }
 
 
+ngx_int_t
+ngx_delete_file(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 = DeleteFileW(u);
+
+failed:
+
+    if (u != utf16) {
+        err = ngx_errno;
+        ngx_free(u);
+        ngx_set_errno(err);
+    }
+
+    return rc;
+}
+
+
 ngx_err_t
 ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log)
 {
diff -r 37a184966ab3 -r 4b06186670ed src/os/win32/ngx_files.h
--- a/src/os/win32/ngx_files.h	Thu Feb 23 20:49:52 2023 +0300
+++ b/src/os/win32/ngx_files.h	Thu Feb 23 20:49:54 2023 +0300
@@ -123,7 +123,7 @@ ssize_t ngx_write_console(ngx_fd_t fd, v
 #define NGX_LINEFEED                CRLF
 
 
-#define ngx_delete_file(name)       DeleteFile((const char *) name)
+ngx_int_t ngx_delete_file(u_char *name);
 #define ngx_delete_file_n           "DeleteFile()"
 
 


More information about the nginx-devel mailing list