diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 1add7616c..c6dd13e4a 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -1306,6 +1306,26 @@ bool Utility::PathExists(const String& path) return fs::exists(fs::path(path.Begin(), path.End()), ec) && !ec; } +double Utility::GetModTime(const String& path) +{ +#ifndef _WIN32 + struct stat statbuf; + + if (stat(path.CStr(), &statbuf) < 0) { +#else /* _WIN32 */ + struct _stat statbuf; + + if (_stat(path.CStr(), &statbuf) < 0) { +#endif /* _WIN32 */ + BOOST_THROW_EXCEPTION(posix_error() + << boost::errinfo_api_function("stat") + << boost::errinfo_errno(errno) + << boost::errinfo_file_name(path)); + } + + return statbuf.st_mtime; +} + Value Utility::LoadJsonFile(const String& path) { std::ifstream fp; diff --git a/lib/base/utility.hpp b/lib/base/utility.hpp index 4505dc918..236a5bdd7 100644 --- a/lib/base/utility.hpp +++ b/lib/base/utility.hpp @@ -111,6 +111,7 @@ public: static tm LocalTime(time_t ts); static bool PathExists(const String& path); + static double GetModTime(const String& path); static void Remove(const String& path); static void RemoveDirRecursive(const String& path);