Commit 7ca0977b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

IFile: expose file last modification date

parent e1146135
......@@ -15,5 +15,6 @@ namespace fs
/// Returns the entire path, plus filename
virtual const std::string& fullPath() const = 0;
virtual const std::string& extension() const = 0;
virtual unsigned int lastModificationDate() const = 0;
};
}
#include "File.h"
#include "Utils.h"
#include <stdexcept>
#include <sys/stat.h>
namespace fs
{
......@@ -10,6 +13,10 @@ File::File( const std::string& path, const std::string& fileName )
, m_fullPath( path + ( *path.rbegin() != '/' ? "/" : "" ) + fileName )
, m_extension( utils::file::extension( fileName ) )
{
struct stat s;
if ( lstat( m_fullPath.c_str(), &s ) )
throw std::runtime_error( "Failed to get file stats" );
m_lastModificationDate = s.st_mtim.tv_sec;
}
const std::string& File::name() const
......@@ -32,4 +39,9 @@ const std::string& File::extension() const
return m_extension;
}
unsigned int File::lastModificationDate() const
{
return m_lastModificationDate;
}
}
......@@ -17,12 +17,14 @@ public:
virtual const std::string& path() const override;
virtual const std::string& fullPath() const override;
virtual const std::string& extension() const override;
virtual unsigned int lastModificationDate() const override;
private:
const std::string m_path;
const std::string m_name;
const std::string m_fullPath;
const std::string m_extension;
unsigned int m_lastModificationDate;
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment