ngx_err_t
ngx_create_full_path(u_char *dir, ngx_uint_t access)
{
    u_char     *p, ch;
    ngx_err_t   err;
    for (p = dir + 1; *p; p++) {
        ch = *p;
        if (ch != '/') {
            continue;
        }
        *p = '\0';
        if (ngx_create_dir(dir, access) == NGX_FILE_ERROR) {
            err = ngx_errno;
            if (err != NGX_EEXIST) {
                return err;
            }
        }
        *p = '/';
    }
    return 0;
}
['static void\nngx_http_upstream_store(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n    size_t                  root;\n    time_t                  lm;\n    ngx_str_t               path;\n    ngx_temp_file_t        *tf;\n    ngx_ext_rename_file_t   ext;\n    tf = u->pipe->temp_file;\n    if (tf->file.fd == NGX_INVALID_FILE) {\n        tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));\n        if (tf == NULL) {\n            return;\n        }\n        tf->file.fd = NGX_INVALID_FILE;\n        tf->file.log = r->connection->log;\n        tf->path = u->conf->temp_path;\n        tf->pool = r->pool;\n        tf->persistent = 1;\n        if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,\n                                 tf->persistent, tf->clean, tf->access)\n            != NGX_OK)\n        {\n            return;\n        }\n        u->pipe->temp_file = tf;\n    }\n    ext.access = u->conf->store_access;\n    ext.path_access = u->conf->store_access;\n    ext.time = -1;\n    ext.create_path = 1;\n    ext.delete_file = 1;\n    ext.log_rename_error = 1;\n    ext.log = r->connection->log;\n    if (u->headers_in.last_modified) {\n        lm = ngx_http_parse_time(u->headers_in.last_modified->value.data,\n                                 u->headers_in.last_modified->value.len);\n        if (lm != NGX_ERROR) {\n            ext.time = lm;\n            ext.fd = tf->file.fd;\n        }\n    }\n    if (u->conf->store_lengths == NULL) {\n        ngx_http_map_uri_to_path(r, &path, &root, 0);\n    } else {\n        if (ngx_http_script_run(r, &path, u->conf->store_lengths->elts, 0,\n                                u->conf->store_values->elts)\n            == NULL)\n        {\n            return;\n        }\n    }\n    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n                   "upstream stores \\"%s\\" to \\"%s\\"",\n                   tf->file.name.data, path.data);\n    (void) ngx_ext_rename_file(&tf->file.name, &path, &ext);\n}', 'u_char *\nngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,\n    size_t *root_length, size_t reserved)\n{\n    u_char                    *last;\n    size_t                     alias;\n    ngx_http_core_loc_conf_t  *clcf;\n    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n    alias = clcf->alias ? clcf->name.len : 0;\n    if (alias && !r->valid_location) {\n        ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,\n                      "\\"alias\\" could not be used in location \\"%V\\" "\n                      "where URI was rewritten", &clcf->name);\n        return NULL;\n    }\n    if (clcf->root_lengths == NULL) {\n        *root_length = clcf->root.len;\n        path->len = clcf->root.len + reserved + r->uri.len - alias + 1;\n        path->data = ngx_pnalloc(r->pool, path->len);\n        if (path->data == NULL) {\n            return NULL;\n        }\n        last = ngx_copy(path->data, clcf->root.data, clcf->root.len);\n    } else {\n#if (NGX_PCRE)\n        ngx_uint_t  captures;\n        captures = alias && clcf->captures;\n        reserved += captures ? 1 : r->uri.len - alias + 1;\n#else\n        reserved += r->uri.len - alias + 1;\n#endif\n        if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved,\n                                clcf->root_values->elts)\n            == NULL)\n        {\n            return NULL;\n        }\n        if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0) != NGX_OK) {\n            return NULL;\n        }\n        *root_length = path->len - reserved;\n        last = path->data + *root_length;\n#if (NGX_PCRE)\n        if (captures) {\n            *last = \'\\0\';\n            return last;\n        }\n#endif\n    }\n    last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1);\n    return last;\n}', 'ngx_int_t\nngx_ext_rename_file(ngx_str_t *src, ngx_str_t *to, ngx_ext_rename_file_t *ext)\n{\n    ngx_err_t  err;\n#if !(NGX_WIN32)\n    if (ext->access) {\n        if (ngx_change_file_access(src->data, ext->access) == NGX_FILE_ERROR) {\n            ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno,\n                          ngx_change_file_access_n " \\"%s\\" failed", src->data);\n            err = 0;\n            goto failed;\n        }\n    }\n#endif\n    if (ext->time != -1) {\n        if (ngx_set_file_time(src->data, ext->fd, ext->time) != NGX_OK) {\n            ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno,\n                          ngx_set_file_time_n " \\"%s\\" failed", src->data);\n            err = 0;\n            goto failed;\n        }\n    }\n    if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) {\n        return NGX_OK;\n    }\n    err = ngx_errno;\n    if (err == NGX_ENOENT) {\n        if (!ext->create_path) {\n            goto failed;\n        }\n        err = ngx_create_full_path(to->data, ngx_dir_access(ext->path_access));\n        if (err) {\n            ngx_log_error(NGX_LOG_CRIT, ext->log, err,\n                          ngx_create_dir_n " \\"%s\\" failed", to->data);\n            err = 0;\n            goto failed;\n        }\n        if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) {\n            return NGX_OK;\n        }\n        err = ngx_errno;\n        goto failed;\n    }\n#if (NGX_WIN32)\n    if (err == NGX_EEXIST) {\n        if (ngx_win32_rename_file(src, to, ext->log) == NGX_OK) {\n            if (ngx_rename_file(src->data, to->data) != NGX_FILE_ERROR) {\n                return NGX_OK;\n            }\n            err = ngx_errno;\n        } else {\n            err = 0;\n        }\n    }\n#endif\nfailed:\n    if (ext->delete_file) {\n        if (ngx_delete_file(src->data) == NGX_FILE_ERROR) {\n            ngx_log_error(NGX_LOG_CRIT, ext->log, ngx_errno,\n                          ngx_delete_file_n " \\"%s\\" failed", src->data);\n        }\n    }\n    if (err && ext->log_rename_error) {\n        ngx_log_error(NGX_LOG_CRIT, ext->log, err,\n                      ngx_rename_file_n " \\"%s\\" to \\"%s\\" failed",\n                      src->data, to->data);\n    }\n    ext->rename_error = err;\n    return NGX_ERROR;\n}', "ngx_err_t\nngx_create_full_path(u_char *dir, ngx_uint_t access)\n{\n    u_char     *p, ch;\n    ngx_err_t   err;\n    for (p = dir + 1; *p; p++) {\n        ch = *p;\n        if (ch != '/') {\n            continue;\n        }\n        *p = '\\0';\n        if (ngx_create_dir(dir, access) == NGX_FILE_ERROR) {\n            err = ngx_errno;\n            if (err != NGX_EEXIST) {\n                return err;\n            }\n        }\n        *p = '/';\n    }\n    return 0;\n}"]