October 16, 2012 08:54AM
Новая версия патча. Вроде учел все замечания.
Опция называется 'dav_copy_hardlink'.
Если у кого-то есть идеи получше касательно названия, предлагайте.
---
src/core/ngx_file.c | 21 +++++++++++++++++++++
src/core/ngx_file.h | 2 ++
src/http/modules/ngx_http_dav_module.c | 17 +++++++++++++++++
3 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index d9b30f8..c960f04 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -608,6 +608,7 @@ ngx_ext_rename_file(ngx_str_t *src, ngx_str_t *to, ngx_ext_rename_file_t *ext)
cf.access = ext->access;
cf.time = ext->time;
cf.log = ext->log;
+ cf.hardlink = 0;

name = ngx_alloc(to->len + 1 + 10 + 1, ext->log);
if (name == NULL) {
@@ -681,6 +682,24 @@ ngx_copy_file(u_char *from, u_char *to, ngx_copy_file_t *cf)
rc = NGX_ERROR;
buf = NULL;
nfd = NGX_INVALID_FILE;
+ fd = NGX_INVALID_FILE;
+
+#ifndef NGX_WIN32
+ if (cf->hardlink &&
+ link((const char *) from, (const char *) to) == NGX_OK)
+ {
+ if (chmod((const char *) to, cf->access) != NGX_OK) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno,
+ "chmod() \"%s\" failed", to);
+
+ ngx_delete_file(to);
+
+ goto failed;
+ }
+
+ goto set_time;
+ }
+#endif

fd = ngx_open_file(from, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);

@@ -763,6 +782,8 @@ ngx_copy_file(u_char *from, u_char *to, ngx_copy_file_t *cf)
size -= n;
}

+set_time:
+
if (cf->time != -1) {
if (ngx_set_file_time(to, nfd, cf->time) != NGX_OK) {
ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h
index 7023e67..81c706a 100644
--- a/src/core/ngx_file.h
+++ b/src/core/ngx_file.h
@@ -94,6 +94,8 @@ typedef struct {
ngx_uint_t access;
time_t time;

+ unsigned hardlink:1;
+
ngx_log_t *log;
} ngx_copy_file_t;

diff --git a/src/http/modules/ngx_http_dav_module.c b/src/http/modules/ngx_http_dav_module.c
index dbb17ac..f9e5daf 100644
--- a/src/http/modules/ngx_http_dav_module.c
+++ b/src/http/modules/ngx_http_dav_module.c
@@ -25,12 +25,14 @@ typedef struct {
ngx_uint_t access;
ngx_uint_t min_delete_depth;
ngx_flag_t create_full_put_path;
+ ngx_flag_t hardlink;
} ngx_http_dav_loc_conf_t;


typedef struct {
ngx_str_t path;
size_t len;
+ unsigned hardlink:1;
} ngx_http_dav_copy_ctx_t;


@@ -106,6 +108,13 @@ static ngx_command_t ngx_http_dav_commands[] = {
offsetof(ngx_http_dav_loc_conf_t, access),
NULL },

+ { ngx_string("dav_copy_hardlink"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+ ngx_conf_set_flag_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_dav_loc_conf_t, hardlink),
+ NULL },
+
ngx_null_command
};

@@ -767,7 +776,10 @@ overwrite_done:
ngx_create_dir_n, copy.path.data);
}

+ dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
+
copy.len = path.len;
+ copy.hardlink = dlcf->hardlink;

tree.init_handler = NULL;
tree.file_handler = ngx_http_dav_copy_tree_file;
@@ -818,6 +830,7 @@ overwrite_done:
cf.access = dlcf->access;
cf.time = ngx_file_mtime(&fi);
cf.log = r->connection->log;
+ cf.hardlink = dlcf->hardlink;

if (ngx_copy_file(path.data, copy.path.data, &cf) == NGX_OK) {
return NGX_HTTP_NO_CONTENT;
@@ -959,6 +972,7 @@ ngx_http_dav_copy_tree_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
cf.access = ctx->access;
cf.time = ctx->mtime;
cf.log = ctx->log;
+ cf.hardlink = copy->hardlink;

(void) ngx_copy_file(path->data, file, &cf);

@@ -1096,6 +1110,7 @@ ngx_http_dav_create_loc_conf(ngx_conf_t *cf)
conf->min_delete_depth = NGX_CONF_UNSET_UINT;
conf->access = NGX_CONF_UNSET_UINT;
conf->create_full_put_path = NGX_CONF_UNSET;
+ conf->hardlink = NGX_CONF_UNSET;

return conf;
}
@@ -1118,6 +1133,8 @@ ngx_http_dav_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->create_full_put_path,
prev->create_full_put_path, 0);

+ ngx_conf_merge_value(conf->hardlink, prev->hardlink, 0);
+
return NGX_CONF_OK;
}

--
1.7.1

_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

[PATCH] implemented hardlink option in DAV module

arut October 15, 2012 07:42AM

Re: [PATCH] implemented hardlink option in DAV module

kav October 15, 2012 07:48AM

Re: [PATCH] implemented hardlink option in DAV module

arut October 15, 2012 07:58AM

Re: [PATCH] implemented hardlink option in DAV module

kav October 15, 2012 08:04AM

Re: [PATCH] implemented hardlink option in DAV module

arut October 15, 2012 08:10AM

Re: [PATCH] implemented hardlink option in DAV module

kav October 15, 2012 08:24AM

Re: [PATCH] implemented hardlink option in DAV module

Maxim Dounin October 15, 2012 11:34AM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв October 15, 2012 03:32PM

Re: [PATCH] implemented hardlink option in DAV module

Gena Makhomed October 15, 2012 03:58PM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв October 15, 2012 04:16PM

Re: [PATCH] implemented hardlink option in DAV module

Maxim Dounin October 16, 2012 06:18AM

Re: [PATCH] implemented hardlink option in DAV module

Maxim Dounin October 16, 2012 01:12PM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв October 16, 2012 01:32PM

Re: [PATCH] implemented hardlink option in DAV module

Maxim Dounin October 16, 2012 01:50PM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв October 16, 2012 02:06PM

Re: [PATCH] implemented hardlink option in DAV module

Maxim Dounin October 16, 2012 02:36PM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв October 16, 2012 03:04PM

Re: [PATCH] implemented hardlink option in DAV module

kav October 17, 2012 01:34AM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв October 17, 2012 05:28AM

Re: [PATCH] implemented hardlink option in DAV module

kav October 17, 2012 06:02AM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв January 14, 2014 12:34PM

Re: [PATCH] implemented hardlink option in DAV module

Maxim Dounin January 15, 2014 11:40AM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв January 15, 2014 01:18PM

Re: [PATCH] implemented hardlink option in DAV module

Валентин Бартенев January 15, 2014 02:12PM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв October 16, 2012 01:18PM

Re: [PATCH] implemented hardlink option in DAV module

Maxim Dounin October 16, 2012 01:38PM

Re[2]: [PATCH] implemented hardlink option in DAV module

Михаил Монашёв October 16, 2012 01:54PM

Re: [PATCH] implemented hardlink option in DAV module

Maxim Dounin October 16, 2012 02:06PM

Re: [PATCH] implemented hardlink option in DAV module

arut October 16, 2012 08:44AM

[PATCH] implemented DAV copy hardlinks

arut October 16, 2012 08:54AM

Re: [PATCH] implemented DAV copy hardlinks

Gena Makhomed October 16, 2012 11:42AM

Re[2]: [PATCH] implemented DAV copy hardlinks

Михаил Монашёв October 16, 2012 12:50PM

Re: [PATCH] implemented DAV copy hardlinks

arut October 16, 2012 01:08PM

Re: [PATCH] implemented DAV copy hardlinks

Maxim Dounin October 16, 2012 11:46AM

Re: [PATCH] implemented DAV copy hardlinks

arut October 19, 2012 03:22AM

Re: [PATCH] implemented DAV copy hardlinks

Maxim Dounin October 24, 2012 02:04PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 270
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready