BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
559148f
Branches
Tags
master
Blinker
src
linux
File.cpp
treating file status change as modification
Stefan Schuermans
commited
559148f
at 2011-10-24 20:45:07
File.cpp
Blame
History
Raw
/* Blinker Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #include <string> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include "File.h" #include "Time.h" namespace Blinker { /** * @brief constructor from path * @param[in] path path to file */ File::File(const std::string &path): m_path(path), m_lastCheck(Time::now()) { } /** * @brief get path to file * @return path to file */ const std::string & File::getPath() { return m_path; } /** * @brief check if file has been modified * @return if file has been modified since last check */ bool File::checkModified() { /* get current time before getting modification time for not missing any modification */ Time now = Time::now(); // get modification/change times struct stat s; if (stat(m_path.c_str(), &s)) return false; // cannot stat -> silently ignore Time modified(s.st_mtime); Time changed(s.st_mtime); // has file been modified/changed since last check bool mod = modified > m_lastCheck || changed > m_lastCheck; // remember "now" as last check time m_lastCheck = now; return mod; } } // namespace Blinker