[PATCH 01 of 15] ngx core - obtain number appended to the temp file name

Jiří Setnička jiri.setnicka at cdn77.com
Fri Jan 28 16:31:53 UTC 2022


# HG changeset patch
# User Jiří Setnička  <jiri.setnicka at cdn77.com>
# Date 1643385660 -3600
#      Fri Jan 28 17:01:00 2022 +0100
# Node ID ca39d3040e2a9c37eb0940c5880fead78d5d137c
# Parent  c0a432c0301b89816ec379a7e5a754a4777008b2
ngx core - obtain number appended to the temp file name

diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -111,8 +111,9 @@ ngx_write_chain_to_temp_file(ngx_temp_fi
     ngx_int_t  rc;
 
     if (tf->file.fd == NGX_INVALID_FILE) {
-        rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool,
-                                  tf->persistent, tf->clean, tf->access);
+        rc = ngx_create_temp_file_n(&tf->file, tf->path, tf->pool,
+                                    tf->persistent, tf->clean, tf->access,
+                                    &tf->suffix_number);
 
         if (rc != NGX_OK) {
             return rc;
@@ -141,6 +142,15 @@ ngx_int_t
 ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool,
     ngx_uint_t persistent, ngx_uint_t clean, ngx_uint_t access)
 {
+    return ngx_create_temp_file_n(file, path, pool, persistent, clean, access,
+                                  NULL);
+}
+
+
+ngx_int_t
+ngx_create_temp_file_n(ngx_file_t *file, ngx_path_t *path, ngx_pool_t *pool,
+    ngx_uint_t persistent, ngx_uint_t clean, ngx_uint_t access, uint32_t *nn)
+{
     size_t                    levels;
     u_char                   *p;
     uint32_t                  n;
@@ -213,6 +223,10 @@ ngx_create_temp_file(ngx_file_t *file, n
             clnf->name = file->name.data;
             clnf->log = pool->log;
 
+            if (nn != NULL) {
+                *nn = n;
+            }
+
             return NGX_OK;
         }
 
diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h
--- a/src/core/ngx_file.h
+++ b/src/core/ngx_file.h
@@ -76,6 +76,7 @@ typedef struct {
     char                      *warn;
 
     ngx_uint_t                 access;
+    uint32_t                   suffix_number;
 
     unsigned                   log_level:8;
     unsigned                   persistent:1;
@@ -139,6 +140,9 @@ ssize_t ngx_write_chain_to_temp_file(ngx
 ngx_int_t ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
     ngx_pool_t *pool, ngx_uint_t persistent, ngx_uint_t clean,
     ngx_uint_t access);
+ngx_int_t ngx_create_temp_file_n(ngx_file_t *file, ngx_path_t *path,
+    ngx_pool_t *pool, ngx_uint_t persistent, ngx_uint_t clean,
+    ngx_uint_t access, uint32_t *n);
 void ngx_create_hashed_filename(ngx_path_t *path, u_char *file, size_t len);
 ngx_int_t ngx_create_path(ngx_file_t *file, ngx_path_t *path);
 ngx_err_t ngx_create_full_path(u_char *dir, ngx_uint_t access);


More information about the nginx-devel mailing list