28 |
#include <cctype> |
#include <cctype> |
29 |
#include <cstdio> |
#include <cstdio> |
30 |
#include <cstring> |
#include <cstring> |
31 |
|
#include <sys/stat.h> |
32 |
|
|
33 |
#include "../../common/File.h" |
#include "../../common/File.h" |
34 |
#include "../../common/Path.h" |
#include "../../common/Path.h" |
1104 |
std::string line; |
std::string line; |
1105 |
currentLine = 0; |
currentLine = 0; |
1106 |
|
|
1107 |
|
// remember latest modification time of file |
1108 |
|
checkFileModified(file); |
1109 |
|
|
1110 |
while (std::getline(fs, line)) |
while (std::getline(fs, line)) |
1111 |
{ |
{ |
1112 |
currentLine++; |
currentLine++; |
1296 |
} |
} |
1297 |
} |
} |
1298 |
|
|
1299 |
|
optional<File::Time> File::getModTimeOfFile(std::string filename) { |
1300 |
|
struct stat st; |
1301 |
|
|
1302 |
|
if (stat(filename.c_str(), &st)) |
1303 |
|
return optional<File::Time>::nothing; |
1304 |
|
|
1305 |
|
return (Time) { |
1306 |
|
#if defined(WIN32) |
1307 |
|
.sec = (intmax_t) st.st_mtime, |
1308 |
|
.nsec = (uint32_t) 0 |
1309 |
|
#elif defined(__APPLE__) |
1310 |
|
.sec = (intmax_t) st.st_mtimespec.tv_sec, |
1311 |
|
.nsec = (uint32_t) st.st_mtimespec.tv_nsec |
1312 |
|
#else |
1313 |
|
.sec = (intmax_t) st.st_mtim.tv_sec, |
1314 |
|
.nsec = (uint32_t) st.st_mtim.tv_nsec |
1315 |
|
#endif |
1316 |
|
}; |
1317 |
|
} |
1318 |
|
|
1319 |
|
bool File::checkFileModified(std::string filename) { |
1320 |
|
if (filename.empty()) { |
1321 |
|
bool res = false; |
1322 |
|
for (const auto& mod_time : mod_times) { |
1323 |
|
res |= checkFileModified(mod_time.first); |
1324 |
|
} |
1325 |
|
return res; |
1326 |
|
} |
1327 |
|
optional<Time> mod_time = getModTimeOfFile(filename); |
1328 |
|
if (!mod_time) return false; |
1329 |
|
Time& prevTime = mod_times[filename]; |
1330 |
|
const bool res = *mod_time != prevTime; |
1331 |
|
prevTime = *mod_time; // remember changed mtime |
1332 |
|
return res; |
1333 |
|
} |
1334 |
|
|
1335 |
File::~File() |
File::~File() |
1336 |
{ |
{ |
1337 |
for (int i = 0; i < _current_containers.size(); i++) |
for (int i = 0; i < _current_containers.size(); i++) |