Skip to content

Commit 63e4148

Browse files
authored
Merge pull request #1706 from pbiering/relax-mtime-resolution-check
Relax mtime resolution check
2 parents 93970a1 + 18338b3 commit 63e4148

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Add: option [auth] type oauth2 by code migration from https://gitlab.mim-libre.fr/alphabet/radicale_oauth/-/blob/dev/oauth2/
66
* Fix: catch OS errors on PUT MKCOL MKCALENDAR MOVE PROPPATCH (insufficient storage, access denied, internal server error)
77
* Test: skip bcrypt related tests if module is missing
8+
* Improve: relax mtime check on storage filesystem
89

910
## 3.4.1
1011
* Add: option [auth] dovecot_connection_type / dovecot_host / dovecot_port

radicale/storage/multifilesystem/__init__.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright © 2014 Jean-Marc Martins
33
# Copyright © 2012-2017 Guillaume Ayoub
44
# Copyright © 2017-2021 Unrud <unrud@outlook.com>
5-
# Copyright © 2024-2024 Peter Bieringer <pb@bieringer.de>
5+
# Copyright © 2024-2025 Peter Bieringer <pb@bieringer.de>
66
#
77
# This library is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
@@ -95,15 +95,21 @@ class Storage(
9595
def _analyse_mtime(self):
9696
# calculate and display mtime resolution
9797
path = os.path.join(self._filesystem_folder, ".Radicale.mtime_test")
98+
logger.debug("Storage item mtime resolution test with file: %r", path)
9899
try:
99100
with open(path, "w") as f:
100101
f.write("mtime_test")
101102
f.close
102103
except Exception as e:
103-
logger.error("Storage item mtime resolution test not possible, cannot write file: %r (%s)", path, e)
104+
logger.warning("Storage item mtime resolution test not possible, cannot write file: %r (%s)", path, e)
104105
raise
105106
# set mtime_ns for tests
106-
os.utime(path, times=None, ns=(MTIME_NS_TEST, MTIME_NS_TEST))
107+
try:
108+
os.utime(path, times=None, ns=(MTIME_NS_TEST, MTIME_NS_TEST))
109+
except Exception as e:
110+
logger.warning("Storage item mtime resolution test not possible, cannot set utime on file: %r (%s)", path, e)
111+
os.remove(path)
112+
raise
107113
logger.debug("Storage item mtime resoultion test set: %d" % MTIME_NS_TEST)
108114
mtime_ns = os.stat(path).st_mtime_ns
109115
logger.debug("Storage item mtime resoultion test get: %d" % mtime_ns)
@@ -147,17 +153,20 @@ def __init__(self, configuration: config.Configuration) -> None:
147153
logger.info("Storage cache subfolder usage for 'history': %s", self._use_cache_subfolder_for_history)
148154
logger.info("Storage cache subfolder usage for 'sync-token': %s", self._use_cache_subfolder_for_synctoken)
149155
logger.info("Storage cache use mtime and size for 'item': %s", self._use_mtime_and_size_for_item_cache)
150-
(precision, precision_unit, unit) = self._analyse_mtime()
151-
if precision >= 100000000:
152-
# >= 100 ms
153-
logger.warning("Storage item mtime resolution test result: %d %s (VERY RISKY ON PRODUCTION SYSTEMS)" % (precision_unit, unit))
154-
elif precision >= 10000000:
155-
# >= 10 ms
156-
logger.warning("Storage item mtime resolution test result: %d %s (RISKY ON PRODUCTION SYSTEMS)" % (precision_unit, unit))
157-
else:
158-
logger.info("Storage item mtime resolution test result: %d %s" % (precision_unit, unit))
159-
if self._use_mtime_and_size_for_item_cache is False:
160-
logger.info("Storage cache using mtime and size for 'item' may be an option in case of performance issues")
156+
try:
157+
(precision, precision_unit, unit) = self._analyse_mtime()
158+
if precision >= 100000000:
159+
# >= 100 ms
160+
logger.warning("Storage item mtime resolution test result: %d %s (VERY RISKY ON PRODUCTION SYSTEMS)" % (precision_unit, unit))
161+
elif precision >= 10000000:
162+
# >= 10 ms
163+
logger.warning("Storage item mtime resolution test result: %d %s (RISKY ON PRODUCTION SYSTEMS)" % (precision_unit, unit))
164+
else:
165+
logger.info("Storage item mtime resolution test result: %d %s" % (precision_unit, unit))
166+
if self._use_mtime_and_size_for_item_cache is False:
167+
logger.info("Storage cache using mtime and size for 'item' may be an option in case of performance issues")
168+
except Exception:
169+
logger.warning("Storage item mtime resolution test result not successful")
161170
logger.debug("Storage cache action logging: %s", self._debug_cache_actions)
162171
if self._use_cache_subfolder_for_item is True or self._use_cache_subfolder_for_history is True or self._use_cache_subfolder_for_synctoken is True:
163172
logger.info("Storage cache subfolder: %r", self._get_collection_cache_folder())

0 commit comments

Comments
 (0)