Directory: | cvmfs/ |
---|---|
File: | cvmfs/repository_tag.cc |
Date: | 2025-06-22 02:36:02 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 3 | 13 | 23.1% |
Branches: | 1 | 8 | 12.5% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * This file is part of the CernVM File System. | ||
3 | */ | ||
4 | |||
5 | #include "repository_tag.h" | ||
6 | |||
7 | #include "util/platform.h" | ||
8 | #include "util/string.h" | ||
9 | |||
10 | 146 | RepositoryTag::RepositoryTag(const std::string &name, | |
11 | 146 | const std::string &description) | |
12 |
1/2✓ Branch 2 taken 146 times.
✗ Branch 3 not taken.
|
146 | : name_(name), description_(description) { } |
13 | |||
14 | /** | ||
15 | * Check if tag name is of the form "generic-*" | ||
16 | */ | ||
17 | ✗ | bool RepositoryTag::HasGenericName() { | |
18 | ✗ | return HasPrefix(name_, "generic-", false); | |
19 | } | ||
20 | |||
21 | /** | ||
22 | * Set a generic tag name of the form "generic-YYYY-MM-DDThh:mm:ss.sssZ" | ||
23 | */ | ||
24 | ✗ | void RepositoryTag::SetGenericName() { | |
25 | ✗ | const uint64_t nanoseconds = platform_realtime_ns(); | |
26 | |||
27 | // Use strftime() to format timestamp to one-second resolution | ||
28 | ✗ | const time_t seconds = static_cast<time_t>(nanoseconds / 1000000000); | |
29 | struct tm timestamp; | ||
30 | ✗ | gmtime_r(&seconds, ×tamp); | |
31 | char seconds_buffer[32]; | ||
32 | ✗ | strftime(seconds_buffer, sizeof(seconds_buffer), "generic-%Y-%m-%dT%H:%M:%S", | |
33 | ×tamp); | ||
34 | |||
35 | // Append milliseconds | ||
36 | ✗ | const unsigned offset_milliseconds = ((nanoseconds / 1000000) % 1000); | |
37 | char name_buffer[48]; | ||
38 | ✗ | snprintf(name_buffer, sizeof(name_buffer), "%s.%03dZ", seconds_buffer, | |
39 | offset_milliseconds); | ||
40 | |||
41 | ✗ | name_ = std::string(name_buffer); | |
42 | } | ||
43 |