GCC Code Coverage Report


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