From 58dca8ef5989ce711e11a8ae9f4bfc98b221cf87 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Thu, 10 Aug 2023 09:34:05 +0200 Subject: [PATCH] - coding style --- client/mksubvolume.cc | 2 +- snapper/FileUtils.cc | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/mksubvolume.cc b/client/mksubvolume.cc index 792ee751..36e29572 100644 --- a/client/mksubvolume.cc +++ b/client/mksubvolume.cc @@ -20,7 +20,7 @@ */ -#include +#include #include #include #include diff --git a/snapper/FileUtils.cc b/snapper/FileUtils.cc index 9da572f3..aa6bc165 100644 --- a/snapper/FileUtils.cc +++ b/snapper/FileUtils.cc @@ -405,23 +405,27 @@ namespace snapper static const char letters[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; + const size_t num_letters = strlen(letters); + static uint64_t value; struct timeval tv; gettimeofday(&tv, NULL); value += ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; - unsigned int attempts = 62 * 62 * 62; + unsigned int attempts = num_letters * num_letters * num_letters; string::size_type length = name.size(); + assert(length >= 6); + for (unsigned int count = 0; count < attempts; value += 7777, ++count) { uint64_t v = value; for (string::size_type i = length - 6; i < length; ++i) { - name[i] = letters[v % 62]; - v /= 62; + name[i] = letters[v % num_letters]; + v /= num_letters; } int fd = open(name, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR); -- 2.47.3