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

File: Allow lastModificationDate and size to be updated

parent 6dfb34a2
......@@ -146,6 +146,22 @@ bool File::isExternal() const
return m_isExternal;
}
bool File::updateFsInfo( uint32_t newLastModificationDate, uint32_t newSize )
{
if ( m_lastModificationDate == newLastModificationDate && m_size == newSize )
return true;
const std::string req = "UPDATE " + File::Table::Name +
" SET last_modification_date = ?, size = ? WHERE id_file = ?";
auto res = sqlite::Tools::executeUpdate( m_ml->getConn(), req,
newLastModificationDate, newSize, m_id );
if ( res == true )
{
m_lastModificationDate = newLastModificationDate;
m_size = newSize;
}
return res;
}
std::shared_ptr<Media> File::media() const
{
if ( m_mediaId == 0 )
......
......@@ -61,6 +61,7 @@ public:
virtual unsigned int lastModificationDate() const override;
virtual unsigned int size() const override;
virtual bool isExternal() const override;
bool updateFsInfo( uint32_t newLastModificationDate, uint32_t newSize );
std::shared_ptr<Media> media() const;
bool destroy();
......@@ -110,8 +111,8 @@ private:
// or the full file MRL for non removable ones
std::string m_mrl;
const Type m_type;
const std::time_t m_lastModificationDate;
const unsigned int m_size;
std::time_t m_lastModificationDate;
unsigned int m_size;
const int64_t m_folderId;
const bool m_isPresent;
const bool m_isRemovable;
......
......@@ -88,5 +88,22 @@ TEST_F( Files, SetMrl )
ASSERT_EQ( 1u, files.size() );
f = std::static_pointer_cast<File>( files[0] );
ASSERT_EQ( f->mrl(), newMrl );
}
TEST_F( Files, UpdateFsInfo )
{
auto res = f->updateFsInfo( 0, 0 );
ASSERT_TRUE( res );
f->updateFsInfo( 123, 456 );
ASSERT_EQ( 123u, f->lastModificationDate() );
ASSERT_EQ( 456u, f->size() );
Reload();
auto files = m->files();
ASSERT_EQ( 1u, files.size() );
f = std::static_pointer_cast<File>( files[0] );
ASSERT_EQ( 123u, f->lastModificationDate() );
ASSERT_EQ( 456u, f->size() );
}
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