From de7be9c82b78271d30e33b4f2440e67a460429d2 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 4 Sep 2025 12:07:43 +0800 Subject: [PATCH 01/19] modules/dav/main/mod_dav.h: define callback `set_mtime` for `struct dav_hooks_repository` modules/dav/fs/repos.c: implement `dav_fs_set_mtime` Signed-off-by: Leo --- modules/dav/fs/repos.c | 17 ++++++++++++++++- modules/dav/main/mod_dav.h | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index 614154502e7..cd7e3a1b1d0 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -1164,6 +1164,20 @@ static dav_error * dav_fs_deliver(const dav_resource *resource, #endif /* DEBUG_GET_HANDLER */ +static dav_error * dav_fs_set_mtime(dav_resource *resource, apr_time_t mtime) +{ + apr_pool_t *pool; + apr_status_t status; + + pool = resource->pool; + status = apr_file_mtime_set(resource->info->pathname, mtime, pool); + + if (status != APR_SUCCESS) { + return dav_new_error(pool, HTTP_BAD_REQUEST, 0, status, "Could not set mtime."); + } + + return NULL; +} static dav_error * dav_fs_create_collection(dav_resource *resource) { @@ -1972,7 +1986,8 @@ static const dav_hooks_repository dav_hooks_repository_fs = dav_fs_getetag, NULL, dav_fs_get_request_rec, - dav_fs_pathname + dav_fs_pathname, + dav_fs_set_mtime }; static dav_prop_insert dav_fs_insert_prop(const dav_resource *resource, diff --git a/modules/dav/main/mod_dav.h b/modules/dav/main/mod_dav.h index 6b42d8203fd..39378d9598d 100644 --- a/modules/dav/main/mod_dav.h +++ b/modules/dav/main/mod_dav.h @@ -2166,6 +2166,13 @@ struct dav_hooks_repository /* Get the pathname for a resource */ const char * (*get_pathname)(const dav_resource *resource); + + /* Set modification time for a resource */ + dav_error * (*set_mtime)( + dav_resource *resource, + const apr_time_t mtime + ); + }; From e77869fabfce2e306aa44d187a62202b8303896c Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 4 Sep 2025 12:09:51 +0800 Subject: [PATCH 02/19] modules/dav/main/mod_dav.c: add new config flag `DavHonorMtimeHeader` Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index fdfe2c60948..a4161413096 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -90,6 +90,7 @@ typedef struct { int allow_depthinfinity; int allow_lockdiscovery; int msext_opts; + int honor_mtime_header; } dav_dir_conf; /* per-server configuration */ @@ -213,6 +214,8 @@ static void *dav_merge_dir_config(apr_pool_t *p, void *base, void *overrides) allow_depthinfinity); newconf->allow_lockdiscovery = DAV_INHERIT_VALUE(parent, child, allow_lockdiscovery); + newconf->honor_mtime_header = DAV_INHERIT_VALUE(parent, child, + honor_mtime_header); newconf->msext_opts = DAV_INHERIT_VALUE(parent, child, msext_opts); @@ -304,6 +307,20 @@ static const char *dav_cmd_dav(cmd_parms *cmd, void *config, const char *arg1) return NULL; } +/* + * Command handler for the DAVHonorMtimeHeader directive, which is FLAG. + */ +static const char *dav_cmd_davhonormtimeheader(cmd_parms *cmd, void *config, const int arg) +{ + dav_dir_conf *conf = (dav_dir_conf *)config; + + if (arg) + conf->honor_mtime_header = DAV_ENABLED_ON; + else + conf->honor_mtime_header = DAV_ENABLED_OFF; + return NULL; +} + /* * Command handler for the DAVBasePath directive, which is TAKE1 */ @@ -5345,6 +5362,11 @@ static const command_rec dav_cmds[] = ACCESS_CONF|RSRC_CONF, "allow lock discovery by PROPFIND requests"), + /* per directory/location */ + AP_INIT_FLAG("DAVHonorMtimeHeader", dav_cmd_davhonormtimeheader, NULL, + ACCESS_CONF, + "Set modification time based on X-OC-Mtime header"), + /* per directory/location, or per server */ AP_INIT_ITERATE("DAVMSext", dav_cmd_davmsext, NULL, ACCESS_CONF|RSRC_CONF, From 86e42ae6bf9c6ae7637b8dca9752f0a0fe235a8b Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 4 Sep 2025 12:14:23 +0800 Subject: [PATCH 03/19] modules/dav/main/mod_dav.c: implement `dav_parse_range` Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index a4161413096..c5ffe806697 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -964,6 +964,37 @@ static int dav_parse_range(request_rec *r, return 1; } +/** + * @return 1 if valid x-oc-mtime, + * 0 if no x-oc-mtime, + * -1 if malformed x-oc-mtime + */ +static int dav_parse_mtime(request_rec *r, apr_time_t *mtime) +{ + const char *hdr; + char *endp; + apr_int64_t n; + + if ((hdr = apr_table_get(r->headers_in, "x-oc-mtime")) == NULL) { + return 0; + } + + for (apr_size_t i = 0; i < strlen(hdr); i++) { + if (!apr_isdigit(hdr[i])) { + return -1; + } + } + + errno = 0; + n = apr_strtoi64(hdr, &endp, 10); + if (errno || endp == hdr) { + return -1; + } + + *mtime = (apr_time_t) apr_time_from_sec(n); + return 1; +} + /* handle the GET method */ static int dav_method_get(request_rec *r) { From 177801f3d1036796304f00f3674143c9752d0d85 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 4 Sep 2025 12:36:39 +0800 Subject: [PATCH 04/19] modules/dav/main/mod_dav.c: parse x-oc-mtime for PUT requests Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index c5ffe806697..fd11b2ee370 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1091,6 +1091,7 @@ static int dav_method_put(request_rec *r) const char *body; dav_error *err; dav_error *err2; + dav_error *err3; dav_stream_mode mode; dav_stream *stream; dav_response *multi_response; @@ -1098,6 +1099,8 @@ static int dav_method_put(request_rec *r) apr_off_t range_start; apr_off_t range_end; int rc; + int mtime_ret; + apr_time_t mtime; /* Ask repository module to resolve the resource */ err = dav_get_resource(r, 0 /* label_allowed */, 0 /* use_checked_in */, @@ -1162,6 +1165,14 @@ static int dav_method_put(request_rec *r) mode = DAV_MODE_WRITE_TRUNC; } + /* try parsing x-oc-mtime header */ + if ((mtime_ret = dav_parse_mtime(r, &mtime)) == -1) { + body = apr_psprintf(r->pool, + "Malformed X-OC-Mtime header for MKCOL %s.", + ap_escape_html(r->pool, r->uri)); + return dav_error_response(r, HTTP_BAD_REQUEST, body); + } + /* make sure the resource can be modified (if versioning repository) */ if ((err = dav_auto_checkout(r, resource, 0 /* not parent_only */, @@ -1255,7 +1266,13 @@ static int dav_method_put(request_rec *r) err2 = (*resource->hooks->close_stream)(stream, err == NULL /* commit */); + + if (err == NULL && mtime_ret == 1) { + err3 = (*resource->hooks->set_mtime)(resource, mtime); + } + err = dav_join_error(err, err2); + err = dav_join_error(err, err3); } /* From 66a76575dadb733acd2b081c2dd1fc28f3095370 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 9 Sep 2025 10:14:52 +0800 Subject: [PATCH 05/19] modules/dav/main/mod_dav.c: only try parse X-Oc-Mtime header and set mtime when `conf->honor_mtime_header == DAV_ENABLED_ON`, check `set_mtime` callback is available before invoking, log debug-level messages docs/log-message-tags: bumped with `docs/log-message-tags/update-log-msg-tags` Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index fd11b2ee370..8031482ba73 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1099,6 +1099,7 @@ static int dav_method_put(request_rec *r) apr_off_t range_start; apr_off_t range_end; int rc; + int mtime_aware; int mtime_ret; apr_time_t mtime; @@ -1166,11 +1167,13 @@ static int dav_method_put(request_rec *r) } /* try parsing x-oc-mtime header */ - if ((mtime_ret = dav_parse_mtime(r, &mtime)) == -1) { - body = apr_psprintf(r->pool, - "Malformed X-OC-Mtime header for MKCOL %s.", - ap_escape_html(r->pool, r->uri)); - return dav_error_response(r, HTTP_BAD_REQUEST, body); + if (conf->honor_mtime_header == DAV_ENABLED_ON) { + if ((mtime_ret = dav_parse_mtime(r, &mtime)) == -1) { + body = apr_psprintf(r->pool, + "Malformed X-OC-Mtime header for MKCOL %s.", + ap_escape_html(r->pool, r->uri)); + return dav_error_response(r, HTTP_BAD_REQUEST, body); + } } /* make sure the resource can be modified (if versioning repository) */ @@ -1267,12 +1270,24 @@ static int dav_method_put(request_rec *r) err2 = (*resource->hooks->close_stream)(stream, err == NULL /* commit */); - if (err == NULL && mtime_ret == 1) { - err3 = (*resource->hooks->set_mtime)(resource, mtime); + + mtime_aware = *resource->hooks->set_mtime != NULL; + if (err == NULL && conf->honor_mtime_header == DAV_ENABLED_ON && mtime_ret == 1) { + if (mtime_aware) { + err3 = (*resource->hooks->set_mtime)(resource, mtime); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(10519) + "Setting mtime for file."); + } else { + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(10520) + "Unable to set mtime: provider does not support \"set_mtime\"."); + } } err = dav_join_error(err, err2); - err = dav_join_error(err, err3); + + if (conf->honor_mtime_header == DAV_ENABLED_ON && mtime_aware) { + err = dav_join_error(err, err3); + } } /* From 8217af3f75342a54cb2bfaf0aea4a2279559f331 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 9 Sep 2025 10:31:09 +0800 Subject: [PATCH 06/19] modules/dav/fs/repos.c: return 500 instead of 400 upon `apr_file_mtime_set` fails, emit error-level log message also docs/log-message-tags: bumped with `docs/log-message-tags/update-log-msg-tags` Signed-off-by: Leo --- modules/dav/fs/repos.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index cd7e3a1b1d0..2232946bce5 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -1168,12 +1168,17 @@ static dav_error * dav_fs_set_mtime(dav_resource *resource, apr_time_t mtime) { apr_pool_t *pool; apr_status_t status; + char errbuf[1024]; pool = resource->pool; status = apr_file_mtime_set(resource->info->pathname, mtime, pool); if (status != APR_SUCCESS) { - return dav_new_error(pool, HTTP_BAD_REQUEST, 0, status, "Could not set mtime."); + apr_strerror(status, errbuf, sizeof(errbuf)); + ap_log_perror(APLOG_MARK, APLOG_ERR, status, pool, APLOGNO(10521) + "Failed setting mtime for file %s: apr_file_mtime_set: %s", + resource->info->pathname, errbuf); + return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not set mtime"); } return NULL; From 32a4cce30de144f2a7ad634dfdac51022a5e8b15 Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 20 Sep 2025 16:24:23 +0800 Subject: [PATCH 07/19] modules/dav/main/mod_dav.c: fix type on request method in error message Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 8031482ba73..55f9ad96db4 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1170,7 +1170,7 @@ static int dav_method_put(request_rec *r) if (conf->honor_mtime_header == DAV_ENABLED_ON) { if ((mtime_ret = dav_parse_mtime(r, &mtime)) == -1) { body = apr_psprintf(r->pool, - "Malformed X-OC-Mtime header for MKCOL %s.", + "Malformed X-OC-Mtime header for PUT %s.", ap_escape_html(r->pool, r->uri)); return dav_error_response(r, HTTP_BAD_REQUEST, body); } From 76ee8e069d62612b161866fd690983263d122f77 Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 20 Sep 2025 16:30:44 +0800 Subject: [PATCH 08/19] modules/dav/main/mod_dav.c: bugfix: retrieve module config at the very beginning of `dav_method_put()`, this avoids access of uninitialized structure Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 55f9ad96db4..40228540124 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1103,6 +1103,9 @@ static int dav_method_put(request_rec *r) int mtime_ret; apr_time_t mtime; + /* retrieve module config */ + conf = ap_get_module_config(r->per_dir_config, &dav_module); + /* Ask repository module to resolve the resource */ err = dav_get_resource(r, 0 /* label_allowed */, 0 /* use_checked_in */, &resource); @@ -1320,7 +1323,6 @@ static int dav_method_put(request_rec *r) } /* This performs MS-WDV PROPPATCH combined with PUT */ - conf = ap_get_module_config(r->per_dir_config, &dav_module); if (conf->msext_opts & DAV_MSEXT_OPT_WDV) (void)dav_mswdv_postprocessing(r); From 16ec946527384a1c51862bad403eebc7f929ebcc Mon Sep 17 00:00:00 2001 From: Leo Date: Sat, 20 Sep 2025 16:53:57 +0800 Subject: [PATCH 09/19] modules/dav/main/mod_dav.c: parse x-oc-mtime for MKCOL requests Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 40228540124..ca2cca615c8 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -2814,6 +2814,13 @@ static int dav_method_mkcol(request_rec *r) int result; int rc; dav_response *multi_status; + dav_dir_conf *conf; + int mtime_aware; + int mtime_ret; + apr_time_t mtime; + + /* retrieve module config */ + conf = ap_get_module_config(r->per_dir_config, &dav_module); /* handle the request body */ /* ### this may move lower once we start processing bodies */ @@ -2841,6 +2848,16 @@ static int dav_method_mkcol(request_rec *r) return HTTP_METHOD_NOT_ALLOWED; } + /* try parsing x-oc-mtime header */ + if (conf->honor_mtime_header == DAV_ENABLED_ON) { + if ((mtime_ret = dav_parse_mtime(r, &mtime)) == -1) { + return dav_error_response(r, HTTP_BAD_REQUEST, + apr_psprintf(r->pool, + "Malformed X-OC-Mtime header for MKCOL %s.", + ap_escape_html(r->pool, r->uri))); + } + } + resource_state = dav_get_resource_state(r, resource); /* @@ -2921,6 +2938,27 @@ static int dav_method_mkcol(request_rec *r) } } + mtime_aware = resource->hooks->set_mtime != NULL; + if (conf->honor_mtime_header == DAV_ENABLED_ON && mtime_ret == 1) { + if (mtime_aware) { + err = (resource->hooks->set_mtime)(resource, mtime); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO() + "Setting mtime for file."); + } else { + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO() + "Unable to set mtime: provider does not support \"set_mtime\"."); + } + } + + if (err != NULL) { + /* The dir creation was successful, but setting mtime failed. */ + err = dav_push_error(r->pool, err->status, 0, + "The MKCOL was successful, but there " + "was a problem setting its modification time.", + err); + return dav_handle_err(r, err, NULL); + } + /* return an appropriate response (HTTP_CREATED) */ rc = dav_created(r, NULL, "Collection", 0); From 18c79d2c8152ca2804656f9c7b4db472e3547683 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 23 Sep 2025 17:30:26 +0800 Subject: [PATCH 10/19] modules/dav/main/mod_dav.c: code style fixes ref: https://github.com/apache/httpd/pull/556#pullrequestreview-3253471705 Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index ca2cca615c8..689ba713b8d 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1280,7 +1280,8 @@ static int dav_method_put(request_rec *r) err3 = (*resource->hooks->set_mtime)(resource, mtime); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(10519) "Setting mtime for file."); - } else { + } + else { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(10520) "Unable to set mtime: provider does not support \"set_mtime\"."); } @@ -2944,7 +2945,8 @@ static int dav_method_mkcol(request_rec *r) err = (resource->hooks->set_mtime)(resource, mtime); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO() "Setting mtime for file."); - } else { + } + else { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO() "Unable to set mtime: provider does not support \"set_mtime\"."); } From b776d4d6d5be5fe86c4c6916b03f173ac50d012c Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 23 Sep 2025 17:39:32 +0800 Subject: [PATCH 11/19] modules/dav/main/mod_dav.c: zero-ing `errno` before `apr_strtoi64()` invocation is not required Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 689ba713b8d..f56247726e4 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -985,9 +985,8 @@ static int dav_parse_mtime(request_rec *r, apr_time_t *mtime) } } - errno = 0; n = apr_strtoi64(hdr, &endp, 10); - if (errno || endp == hdr) { + if (errno != 0 || endp == hdr) { return -1; } From 44959b96a584d83b8978360b631d622ee79f19d7 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 23 Sep 2025 17:41:58 +0800 Subject: [PATCH 12/19] modules/dav/main/mod_dav.c: use proper language in logs, avoid unnecessary terminologies Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index f56247726e4..145eb37a978 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1278,11 +1278,11 @@ static int dav_method_put(request_rec *r) if (mtime_aware) { err3 = (*resource->hooks->set_mtime)(resource, mtime); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(10519) - "Setting mtime for file."); + "Setting modification time for file."); } else { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(10520) - "Unable to set mtime: provider does not support \"set_mtime\"."); + "Provider does not support setting modification times."); } } From a14efe00390f23ef52b470897a71451b80f7f2ec Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 23 Sep 2025 17:49:55 +0800 Subject: [PATCH 13/19] modules/dav/fs/repo.c: avoid unnecessary `apr_strerror` invocation Signed-off-by: Leo --- modules/dav/fs/repos.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index 2232946bce5..04d7db6be3c 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -1168,17 +1168,16 @@ static dav_error * dav_fs_set_mtime(dav_resource *resource, apr_time_t mtime) { apr_pool_t *pool; apr_status_t status; - char errbuf[1024]; pool = resource->pool; status = apr_file_mtime_set(resource->info->pathname, mtime, pool); if (status != APR_SUCCESS) { - apr_strerror(status, errbuf, sizeof(errbuf)); ap_log_perror(APLOG_MARK, APLOG_ERR, status, pool, APLOGNO(10521) - "Failed setting mtime for file %s: apr_file_mtime_set: %s", - resource->info->pathname, errbuf); - return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not set mtime"); + "Failed setting modification time for file %s.", + resource->info->pathname); + return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR, 0, status, + "Could not set modification time."); } return NULL; From de608fd67c4396498667567860289bf16ac4d1d8 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 30 Sep 2025 21:00:28 +0800 Subject: [PATCH 14/19] modules/dav/fs/repos.c, modules/dav/main/mod_dav.c: remove APLOGNO() for debug and trace level logs Signed-off-by: Leo --- modules/dav/fs/repos.c | 2 +- modules/dav/main/mod_dav.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index 04d7db6be3c..791e3c5c787 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -1173,7 +1173,7 @@ static dav_error * dav_fs_set_mtime(dav_resource *resource, apr_time_t mtime) status = apr_file_mtime_set(resource->info->pathname, mtime, pool); if (status != APR_SUCCESS) { - ap_log_perror(APLOG_MARK, APLOG_ERR, status, pool, APLOGNO(10521) + ap_log_perror(APLOG_MARK, APLOG_ERR, status, pool, APLOGNO() "Failed setting modification time for file %s.", resource->info->pathname); return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR, 0, status, diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 145eb37a978..d07866668c4 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1277,12 +1277,12 @@ static int dav_method_put(request_rec *r) if (err == NULL && conf->honor_mtime_header == DAV_ENABLED_ON && mtime_ret == 1) { if (mtime_aware) { err3 = (*resource->hooks->set_mtime)(resource, mtime); - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(10519) - "Setting modification time for file."); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, + "Setting modification time for file."); } else { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(10520) - "Provider does not support setting modification times."); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, + "Provider does not support setting modification times."); } } @@ -2942,11 +2942,11 @@ static int dav_method_mkcol(request_rec *r) if (conf->honor_mtime_header == DAV_ENABLED_ON && mtime_ret == 1) { if (mtime_aware) { err = (resource->hooks->set_mtime)(resource, mtime); - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO() + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Setting mtime for file."); } else { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO() + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Unable to set mtime: provider does not support \"set_mtime\"."); } } From ca3b0371623fcdc6153acae2cbe71628cd613306 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 30 Sep 2025 21:03:30 +0800 Subject: [PATCH 15/19] modules/dav/fs/repo.c, docs/log-message-tags/next-number: `update-log-msg-tags` invocation Signed-off-by: Leo --- modules/dav/fs/repos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index 791e3c5c787..e6abc717e0b 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -1173,7 +1173,7 @@ static dav_error * dav_fs_set_mtime(dav_resource *resource, apr_time_t mtime) status = apr_file_mtime_set(resource->info->pathname, mtime, pool); if (status != APR_SUCCESS) { - ap_log_perror(APLOG_MARK, APLOG_ERR, status, pool, APLOGNO() + ap_log_perror(APLOG_MARK, APLOG_ERR, status, pool, APLOGNO(10519) "Failed setting modification time for file %s.", resource->info->pathname); return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR, 0, status, From f2d3df8de05fdefc3855d34ed8b2afa5fe7edac5 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 30 Sep 2025 21:05:54 +0800 Subject: [PATCH 16/19] modules/dav/main/mod_dav.c: rephrase log messages when setting modification times for directory (MKCOL) Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index d07866668c4..419ae976d51 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -2943,11 +2943,11 @@ static int dav_method_mkcol(request_rec *r) if (mtime_aware) { err = (resource->hooks->set_mtime)(resource, mtime); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, - "Setting mtime for file."); + "Setting modification time for directory."); } else { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, - "Unable to set mtime: provider does not support \"set_mtime\"."); + "Provider does not support setting modification times."); } } From 87ce719de6b574dc4f8140e191363a3d30fe96d8 Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 2 Oct 2025 21:47:29 +0800 Subject: [PATCH 17/19] modules/dav/main/mod_dav.c: `dav_parse_mtime()`: ensure C89 conformity Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 419ae976d51..d4b70f4425c 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -974,12 +974,13 @@ static int dav_parse_mtime(request_rec *r, apr_time_t *mtime) const char *hdr; char *endp; apr_int64_t n; + apr_size_t i; if ((hdr = apr_table_get(r->headers_in, "x-oc-mtime")) == NULL) { return 0; } - for (apr_size_t i = 0; i < strlen(hdr); i++) { + for (i = 0; i < strlen(hdr); i++) { if (!apr_isdigit(hdr[i])) { return -1; } From 817090632b95a571c430a076e4fc126cef0108a9 Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 3 Oct 2025 00:45:33 +0800 Subject: [PATCH 18/19] modules/dav/main/mod_dav.c: compile errors fixes - remove unnecessary variable declarations: `mtime_aware`, `err3` - always initialize `mtime_ret` to `0` - simplify mtime-setting procedures Signed-off-by: Leo --- modules/dav/main/mod_dav.c | 41 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index d4b70f4425c..c3c383916a0 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1091,7 +1091,6 @@ static int dav_method_put(request_rec *r) const char *body; dav_error *err; dav_error *err2; - dav_error *err3; dav_stream_mode mode; dav_stream *stream; dav_response *multi_response; @@ -1099,7 +1098,6 @@ static int dav_method_put(request_rec *r) apr_off_t range_start; apr_off_t range_end; int rc; - int mtime_aware; int mtime_ret; apr_time_t mtime; @@ -1170,6 +1168,7 @@ static int dav_method_put(request_rec *r) } /* try parsing x-oc-mtime header */ + mtime_ret = 0; if (conf->honor_mtime_header == DAV_ENABLED_ON) { if ((mtime_ret = dav_parse_mtime(r, &mtime)) == -1) { body = apr_psprintf(r->pool, @@ -1273,11 +1272,12 @@ static int dav_method_put(request_rec *r) err2 = (*resource->hooks->close_stream)(stream, err == NULL /* commit */); + err = dav_join_error(err, err2); - mtime_aware = *resource->hooks->set_mtime != NULL; - if (err == NULL && conf->honor_mtime_header == DAV_ENABLED_ON && mtime_ret == 1) { - if (mtime_aware) { - err3 = (*resource->hooks->set_mtime)(resource, mtime); + if (err == NULL && mtime_ret == 1) { + if (*resource->hooks->set_mtime != NULL) { + err2 = (*resource->hooks->set_mtime)(resource, mtime); + err = dav_join_error(err, err2); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Setting modification time for file."); } @@ -1286,12 +1286,6 @@ static int dav_method_put(request_rec *r) "Provider does not support setting modification times."); } } - - err = dav_join_error(err, err2); - - if (conf->honor_mtime_header == DAV_ENABLED_ON && mtime_aware) { - err = dav_join_error(err, err3); - } } /* @@ -2816,7 +2810,6 @@ static int dav_method_mkcol(request_rec *r) int rc; dav_response *multi_status; dav_dir_conf *conf; - int mtime_aware; int mtime_ret; apr_time_t mtime; @@ -2850,6 +2843,7 @@ static int dav_method_mkcol(request_rec *r) } /* try parsing x-oc-mtime header */ + mtime_ret = 0; if (conf->honor_mtime_header == DAV_ENABLED_ON) { if ((mtime_ret = dav_parse_mtime(r, &mtime)) == -1) { return dav_error_response(r, HTTP_BAD_REQUEST, @@ -2939,10 +2933,16 @@ static int dav_method_mkcol(request_rec *r) } } - mtime_aware = resource->hooks->set_mtime != NULL; - if (conf->honor_mtime_header == DAV_ENABLED_ON && mtime_ret == 1) { - if (mtime_aware) { + if (mtime_ret == 1) { + if (resource->hooks->set_mtime != NULL) { err = (resource->hooks->set_mtime)(resource, mtime); + if (err != NULL) { + err = dav_push_error(r->pool, err->status, 0, + "The MKCOL was successful, but there " + "was a problem setting its modification time.", + err); + return dav_handle_err(r, err, NULL); + } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Setting modification time for directory."); } @@ -2952,15 +2952,6 @@ static int dav_method_mkcol(request_rec *r) } } - if (err != NULL) { - /* The dir creation was successful, but setting mtime failed. */ - err = dav_push_error(r->pool, err->status, 0, - "The MKCOL was successful, but there " - "was a problem setting its modification time.", - err); - return dav_handle_err(r, err, NULL); - } - /* return an appropriate response (HTTP_CREATED) */ rc = dav_created(r, NULL, "Collection", 0); From f4128ddd02b4f6abd565f4f227fac87097b69997 Mon Sep 17 00:00:00 2001 From: Leo Date: Fri, 3 Oct 2025 00:51:07 +0800 Subject: [PATCH 19/19] modules/dav/fs/repos.c, docs/log-message-tags/next-number: reset `APLOGNO()` after rebase Signed-off-by: Leo --- docs/log-message-tags/next-number | 2 +- modules/dav/fs/repos.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/log-message-tags/next-number b/docs/log-message-tags/next-number index 01d130b6cac..9f0b3f30565 100644 --- a/docs/log-message-tags/next-number +++ b/docs/log-message-tags/next-number @@ -1 +1 @@ -10543 +10544 diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index e6abc717e0b..746681877f2 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -1173,7 +1173,7 @@ static dav_error * dav_fs_set_mtime(dav_resource *resource, apr_time_t mtime) status = apr_file_mtime_set(resource->info->pathname, mtime, pool); if (status != APR_SUCCESS) { - ap_log_perror(APLOG_MARK, APLOG_ERR, status, pool, APLOGNO(10519) + ap_log_perror(APLOG_MARK, APLOG_ERR, status, pool, APLOGNO(10543) "Failed setting modification time for file %s.", resource->info->pathname); return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR, 0, status,