From 019dc7a39c68cf223815d62b73b604544e07b628 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 1 Jul 2017 00:11:44 +0200 Subject: [PATCH] Use UUID format for random UIDs --- radicale/storage.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/radicale/storage.py b/radicale/storage.py index 2db9706..f201517 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -137,6 +137,12 @@ def check_item(vobject_item): raise ValueError("Unknown item type: %r" % vobject_item.name) +def random_uuid4(): + """Generate a pseudo-random UUID""" + r = "%016x" % getrandbits(128) + return "%s-%s-%s-%s-%s" % (r[:8], r[8:12], r[12:16], r[16:20], r[20:]) + + def scandir(path, only_dirs=False, only_files=False): """Iterator for directory elements. (For compatibility with Python < 3.5) @@ -600,7 +606,7 @@ class Collection(BaseCollection): def _find_available_file_name(exists_fn, suffix=""): # Prevent infinite loop for _ in range(1000): - file_name = "%016x" % getrandbits(64) + suffix + file_name = random_uuid4() + suffix if not exists_fn(file_name): return file_name # something is wrong with the PRNG