Skip to content

Commit 77f6d6f

Browse files
committed
Unify the return type of File::getTime() to make the code cleaner
1 parent 27935e9 commit 77f6d6f

File tree

2 files changed

+48
-58
lines changed

2 files changed

+48
-58
lines changed

src/common/config/ConfigCache.cpp

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -82,60 +82,39 @@ Firebird::PathName ConfigCache::getFileName()
8282
return files->fileName;
8383
}
8484

85-
#ifdef WIN_NT
86-
void ConfigCache::File::getTime(DWORD& timeLow, DWORD& timeHigh)
85+
ConfigCache::File::PreciseTime ConfigCache::File::getTime()
8786
{
87+
#ifdef WIN_NT
8888
WIN32_FILE_ATTRIBUTE_DATA fInfo;
8989

9090
if (!GetFileAttributesEx(fileName.c_str(), GetFileExInfoStandard, &fInfo))
91-
{
92-
timeLow = 0;
93-
timeHigh = 0;
94-
return;
95-
}
91+
return PreciseTime();
9692

97-
timeLow = fInfo.ftLastWriteTime.dwLowDateTime;
98-
timeHigh = fInfo.ftLastWriteTime.dwHighDateTime;
99-
}
93+
return PreciseTime(fInfo.ftLastWriteTime);
10094
#else
101-
void ConfigCache::File::getTime(timespec& time)
102-
{
10395
struct STAT st;
10496

10597
if (os_utils::stat(fileName.c_str(), &st) != 0)
10698
{
10799
if (errno == ENOENT)
108100
{
109101
// config file is missing, but this is not our problem
110-
time.tv_sec = 0;
111-
time.tv_nsec = 0;
112-
return;
102+
return PreciseTime();
113103
}
114104
system_call_failed::raise("stat");
115105
}
116106

117107
#ifdef DARWIN
118-
time.tv_sec = st.st_mtimespec.tv_sec;
119-
time.tv_nsec = st.st_mtimespec.tv_nsec;
108+
return PreciseTime(st.st_mtimespec);
120109
#else
121-
time.tv_sec = st.st_mtim.tv_sec;
122-
time.tv_nsec = st.st_mtim.tv_nsec;
110+
return PreciseTime(st.st_mtim);
123111
#endif
124-
}
125112
#endif
113+
}
126114

127115
ConfigCache::File::File(MemoryPool& p, const PathName& fName)
128-
: PermanentStorage(p), fileName(getPool(), fName),
129-
next(NULL)
130-
{
131-
#ifdef WIN_NT
132-
fileTimeLow = 0;
133-
fileTimeHigh = 0;
134-
#else
135-
fileTime.tv_sec = 0;
136-
fileTime.tv_nsec = 0;
137-
#endif
138-
}
116+
: PermanentStorage(p), fileName(getPool(), fName), next(NULL)
117+
{ }
139118

140119
ConfigCache::File::~File()
141120
{
@@ -144,30 +123,15 @@ ConfigCache::File::~File()
144123

145124
bool ConfigCache::File::checkLoadConfig(bool set)
146125
{
147-
#ifdef WIN_NT
148-
DWORD newTimeLow;
149-
DWORD newTimeHigh;
150-
getTime(newTimeLow, newTimeHigh);
151-
if (fileTimeLow == newTimeLow && fileTimeHigh == newTimeHigh)
152-
#else
153-
timespec newTime;
154-
getTime(newTime);
155-
if (fileTime.tv_sec == newTime.tv_sec && fileTime.tv_nsec == newTime.tv_nsec)
156-
#endif
126+
const PreciseTime newTime = getTime();
127+
if (fileTime == newTime)
157128
{
158129
return next ? next->checkLoadConfig(set) : true;
159130
}
160131

161132
if (set)
162133
{
163-
#ifdef WIN_NT
164-
fileTimeLow = newTimeLow;
165-
fileTimeHigh = newTimeHigh;
166-
#else
167-
fileTime.tv_sec = newTime.tv_sec;
168-
fileTime.tv_nsec = newTime.tv_nsec;
169-
#endif
170-
134+
fileTime = newTime;
171135
if (next)
172136
{
173137
next->checkLoadConfig(set);

src/common/config/ConfigCache.h

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@ class ConfigCache : public Firebird::PermanentStorage
4848
private:
4949
class File : public Firebird::PermanentStorage
5050
{
51+
class PreciseTime
52+
{
53+
#ifdef WIN_NT
54+
using TimeType = FILETIME;
55+
#else
56+
using TimeType = timespec;
57+
#endif
58+
59+
public:
60+
PreciseTime()
61+
{
62+
}
63+
64+
PreciseTime(TimeType time)
65+
: m_time(time)
66+
{
67+
}
68+
69+
bool operator==(const PreciseTime& other) const
70+
{
71+
#ifdef WIN_NT
72+
return m_time.dwLowDateTime == other.m_time.dwLowDateTime &&
73+
m_time.dwHighDateTime == other.m_time.dwHighDateTime;
74+
#else
75+
return m_time.tv_sec == other.m_time.tv_sec &&
76+
m_time.tv_nsec == other.m_time.tv_nsec;
77+
#endif
78+
}
79+
80+
private:
81+
TimeType m_time = {};
82+
};
83+
5184
public:
5285
File(Firebird::MemoryPool& p, const Firebird::PathName& fName);
5386
~File();
@@ -60,16 +93,9 @@ class ConfigCache : public Firebird::PermanentStorage
6093
Firebird::PathName fileName;
6194

6295
private:
63-
#ifdef WIN_NT
64-
volatile DWORD fileTimeLow;
65-
volatile DWORD fileTimeHigh;
66-
void getTime(DWORD& timeLow, DWORD& timeHigh);
67-
#else
68-
volatile timespec fileTime;
69-
void getTime(timespec& time);
70-
#endif
71-
96+
PreciseTime fileTime;
7297
File* next;
98+
PreciseTime getTime();
7399
};
74100
File* files;
75101

0 commit comments

Comments
 (0)