[nginx] Win32: non-ASCII names support in ngx_rename_file().
Sergey Kandaurov
pluknet at nginx.com
Fri Feb 24 10:33:11 UTC 2023
details: https://hg.nginx.org/nginx/rev/96d894b38667
branches:
changeset: 8138:96d894b38667
user: Maxim Dounin <mdounin at mdounin.ru>
date: Thu Feb 23 20:49:55 2023 +0300
description:
Win32: non-ASCII names support in ngx_rename_file().
This makes it possible to upload files with non-ASCII characters
when using the dav module (ticket #1433).
diffstat:
src/os/win32/ngx_files.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
src/os/win32/ngx_files.h | 2 +-
2 files changed, 56 insertions(+), 1 deletions(-)
diffs (77 lines):
diff -r 4b06186670ed -r 96d894b38667 src/os/win32/ngx_files.c
--- a/src/os/win32/ngx_files.c Thu Feb 23 20:49:54 2023 +0300
+++ b/src/os/win32/ngx_files.c Thu Feb 23 20:49:55 2023 +0300
@@ -243,6 +243,61 @@ failed:
}
+ngx_int_t
+ngx_rename_file(u_char *from, u_char *to)
+{
+ long rc;
+ size_t len;
+ u_short *fu, *tu;
+ ngx_err_t err;
+ u_short utf16f[NGX_UTF16_BUFLEN];
+ u_short utf16t[NGX_UTF16_BUFLEN];
+
+ len = NGX_UTF16_BUFLEN;
+ fu = ngx_utf8_to_utf16(utf16f, from, &len, 0);
+
+ if (fu == NULL) {
+ return NGX_FILE_ERROR;
+ }
+
+ rc = NGX_FILE_ERROR;
+ tu = NULL;
+
+ if (ngx_win32_check_filename(fu, len, 0) != NGX_OK) {
+ goto failed;
+ }
+
+ len = NGX_UTF16_BUFLEN;
+ tu = ngx_utf8_to_utf16(utf16t, to, &len, 0);
+
+ if (tu == NULL) {
+ goto failed;
+ }
+
+ if (ngx_win32_check_filename(tu, len, 1) != NGX_OK) {
+ goto failed;
+ }
+
+ rc = MoveFileW(fu, tu);
+
+failed:
+
+ if (fu != utf16f) {
+ err = ngx_errno;
+ ngx_free(fu);
+ ngx_set_errno(err);
+ }
+
+ if (tu && tu != utf16t) {
+ err = ngx_errno;
+ ngx_free(tu);
+ 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 4b06186670ed -r 96d894b38667 src/os/win32/ngx_files.h
--- a/src/os/win32/ngx_files.h Thu Feb 23 20:49:54 2023 +0300
+++ b/src/os/win32/ngx_files.h Thu Feb 23 20:49:55 2023 +0300
@@ -127,7 +127,7 @@ ngx_int_t ngx_delete_file(u_char *name);
#define ngx_delete_file_n "DeleteFile()"
-#define ngx_rename_file(o, n) MoveFile((const char *) o, (const char *) n)
+ngx_int_t ngx_rename_file(u_char *from, u_char *to);
#define ngx_rename_file_n "MoveFile()"
ngx_err_t ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log);
More information about the nginx-devel
mailing list