Commit 2acd12c7 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

fs: unix: Simplify and don't call twice on the same file

parent b3b89327
......@@ -112,10 +112,6 @@ void Directory::read() const
}
std::string path = m_path + "/" + result->d_name;
#if defined(_DIRENT_HAVE_D_TYPE) && defined(_BSD_SOURCE)
if ( result->d_type == DT_DIR )
{
#else
struct stat s;
if ( lstat( path.c_str(), &s ) != 0 )
{
......@@ -128,7 +124,6 @@ void Directory::read() const
}
if ( S_ISDIR( s.st_mode ) )
{
#endif
auto dirPath = toAbsolute( path );
if ( *dirPath.crbegin() != '/' )
dirPath += '/';
......@@ -138,7 +133,7 @@ void Directory::read() const
else
{
auto filePath = toAbsolute( path );
m_files.emplace_back( std::make_shared<File>( filePath ) );
m_files.emplace_back( std::make_shared<File>( filePath, s ) );
}
}
}
......
......@@ -28,12 +28,9 @@
namespace fs
{
File::File( const std::string& filePath )
File::File( const std::string& filePath, const struct stat& s )
: CommonFile( filePath )
{
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;
}
......
......@@ -24,13 +24,15 @@
#include "filesystem/common/CommonFile.h"
struct stat;
namespace fs
{
class File : public CommonFile
{
public:
explicit File( const std::string& filePath );
explicit File( const std::string& filePath, const struct stat& s );
virtual unsigned int lastModificationDate() const override;
......
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