Ticket #557: ngx_autoindex_show_dot_files.patch

File ngx_autoindex_show_dot_files.patch, 2.4 KB (added by Shin Sterneck, 12 years ago)

patch to introduce new option for autoindex to show dot-files

  • ngx_http_autoindex_module.c

    diff -u nginx-1.6.0/src/http/modules/ngx_http_autoindex_module.c nginx-1.6.0/src/http/modules.new/ngx_http_autoindex_module.c
    old new  
    4040    ngx_flag_t     enable;
    4141    ngx_flag_t     localtime;
    4242    ngx_flag_t     exact_size;
     43    ngx_flag_t     show_dot_files;
    4344} ngx_http_autoindex_loc_conf_t;
    4445
    4546
     
    8182      offsetof(ngx_http_autoindex_loc_conf_t, exact_size),
    8283      NULL },
    8384
     85    { ngx_string("autoindex_show_dot_files"),
     86      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
     87      ngx_conf_set_flag_slot,
     88      NGX_HTTP_LOC_CONF_OFFSET,
     89      offsetof(ngx_http_autoindex_loc_conf_t, show_dot_files),
     90      NULL },
     91
    8492      ngx_null_command
    8593};
    8694
     
    279287
    280288        len = ngx_de_namelen(&dir);
    281289
    282         if (ngx_de_name(&dir)[0] == '.') {
    283             continue;
    284         }
     290        if (!alcf->show_dot_files) {
     291                if (ngx_de_name(&dir)[0] == '.') {
     292                        continue;
     293                }
     294        }
    285295
    286296        if (!dir.valid_info) {
    287297
     
    413423
    414424    b->last = ngx_cpymem(b->last, "</h1>", sizeof("</h1>") - 1);
    415425
    416     b->last = ngx_cpymem(b->last, "<hr><pre><a href=\"../\">../</a>" CRLF,
    417                          sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1);
     426    if (!alcf->show_dot_files) {
     427        b->last = ngx_cpymem(b->last, "<hr><pre><a href=\"../\">../</a>" CRLF,
     428                             sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1);
     429    } else {
     430        b->last = ngx_cpymem(b->last, "<hr><pre>" CRLF,
     431                             sizeof("<hr><pre>" CRLF) - 1);
     432    }
    418433
    419434    tp = ngx_timeofday();
    420435
     
    667682    conf->enable = NGX_CONF_UNSET;
    668683    conf->localtime = NGX_CONF_UNSET;
    669684    conf->exact_size = NGX_CONF_UNSET;
     685    conf->show_dot_files = NGX_CONF_UNSET;
    670686
    671687    return conf;
    672688}
     
    681697    ngx_conf_merge_value(conf->enable, prev->enable, 0);
    682698    ngx_conf_merge_value(conf->localtime, prev->localtime, 0);
    683699    ngx_conf_merge_value(conf->exact_size, prev->exact_size, 1);
     700    ngx_conf_merge_value(conf->show_dot_files, prev->show_dot_files, 0);
    684701
    685702    return NGX_CONF_OK;
    686703}