medialibrary: expose new ml_file_t values

The medialibrary has files sizes and last modification dates in its
database. This patch exposes theses two previously ignored values.
This commit is contained in:
Alaric Senat 2021-02-05 12:23:47 +01:00 committed by Hugo Beauzée-Luyssen
parent edfcc459ec
commit 80864e9975
5 changed files with 43 additions and 9 deletions

View File

@ -150,6 +150,8 @@ typedef struct vlc_ml_label_list_t
typedef struct vlc_ml_file_t
{
char* psz_mrl;
int64_t i_size;
time_t i_last_modification_date;
vlc_ml_file_type_t i_type;
bool b_external;
bool b_removable;

View File

@ -296,6 +296,8 @@ bool Convert( const medialibrary::IFile* input, vlc_ml_file_t& output )
vlc_assert_unreachable();
}
output.i_size = input->size();
output.i_last_modification_date = input->lastModificationDate();
output.b_removable = input->isRemovable();
output.b_present = true;
try

View File

@ -26,12 +26,15 @@
#include "file.h"
#include "util.h"
#include <sys/stat.h>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <system_error>
#include <vlc_common.h>
#include <vlc_url.h>
#include <vlc_input_item.h>
#include <vlc_fs.h>
#include <vlc_input.h>
#include <vlc_threads.h>
#include <vlc_cxx_helpers.hpp>
@ -233,14 +236,33 @@ SDDirectory::read() const
void
SDDirectory::addFile(std::string mrl, IFile::LinkedFileType fType, std::string linkedFile) const
{
time_t lastModificationDate = 0;
int64_t fileSize = 0;
if ( m_fs.isNetworkFileSystem() == false )
{
const auto path = vlc::wrap_cptr( vlc_uri2path( mrl.c_str() ) );
struct stat stat;
if ( vlc_stat( path.get(), &stat ) != 0 )
{
if ( errno == EACCES )
return;
throw errors::System{ errno, "Failed to get file info" };
}
lastModificationDate = stat.st_mtime;
fileSize = stat.st_size;
}
if ( fType == IFile::LinkedFileType::None )
{
m_files.push_back( std::make_shared<SDFile>( std::move( mrl ) ) );
m_files.push_back(
std::make_shared<SDFile>( std::move( mrl ), fileSize, lastModificationDate ) );
}
else
{
m_files.push_back(
std::make_shared<SDFile>( std::move( mrl ), fType, std::move( linkedFile ) ) );
m_files.push_back( std::make_shared<SDFile>(
std::move( mrl ), fType, std::move( linkedFile ), fileSize, lastModificationDate ) );
}
}
} /* namespace medialibrary */

View File

@ -28,22 +28,28 @@
namespace vlc {
namespace medialibrary {
SDFile::SDFile( const std::string mrl )
SDFile::SDFile( const std::string mrl, const int64_t size, const time_t lastModificationDate )
: m_mrl( std::move( mrl ) )
, m_name( utils::fileName( m_mrl ) )
, m_extension( utils::extension( m_mrl ) )
, m_isNetwork( m_mrl.find( "file://" ) != 0 )
, m_size( size )
, m_lastModificationTime( lastModificationDate )
{
}
SDFile::SDFile( const std::string mrl,
const LinkedFileType fType,
const std::string linkedFile )
const std::string linkedFile,
const int64_t size,
const time_t lastModificationDate )
: m_mrl( std::move( mrl ) )
, m_name( utils::fileName( m_mrl ) )
, m_extension( utils::extension( m_mrl ) )
, m_linkedFile( std::move( linkedFile ) )
, m_linkedType( fType )
, m_isNetwork( m_mrl.find( "file://" ) != 0 )
, m_size( size )
, m_lastModificationTime( lastModificationDate )
{
}
@ -68,7 +74,7 @@ SDFile::extension() const
time_t
SDFile::lastModificationDate() const
{
return 0;
return m_lastModificationTime;
}
bool
@ -80,7 +86,7 @@ SDFile::isNetwork() const
int64_t
SDFile::size() const
{
return 0;
return m_size;
}
IFile::LinkedFileType SDFile::linkedType() const

View File

@ -31,8 +31,8 @@ using namespace ::medialibrary::fs;
class SDFile : public IFile
{
public:
explicit SDFile( std::string mrl );
SDFile( std::string mrl, LinkedFileType, std::string linkedFile );
SDFile( std::string mrl, int64_t, time_t );
SDFile( std::string mrl, LinkedFileType, std::string linkedFile, int64_t, time_t );
virtual ~SDFile() = default;
const std::string& mrl() const override;
@ -51,6 +51,8 @@ private:
std::string m_linkedFile;
LinkedFileType m_linkedType = LinkedFileType::None;
bool m_isNetwork;
int64_t m_size = 0;
time_t m_lastModificationTime = 0;
};
} /* namespace medialibrary */