Commit 58632c23 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

fs: IDirectory: Remove lastModificationDate

parent 1184a56a
......@@ -41,7 +41,6 @@ namespace fs
virtual const std::vector<std::string>& files() = 0;
/// Returns a list of absolute path to this folder subdirectories
virtual const std::vector<std::string>& dirs() = 0;
virtual unsigned int lastModificationDate() const = 0;
virtual std::shared_ptr<IDevice> device() const = 0;
};
}
......@@ -36,8 +36,13 @@ namespace fs
Directory::Directory( const std::string& path )
: m_path( toAbsolute( path ) )
, m_lastModificationDate( 0 )
{
#ifndef NDEBUG
struct stat s;
lstat( m_path.c_str(), &s );
if ( S_ISDIR( s.st_mode ) == false )
throw std::runtime_error( "The provided path isn't a directory" );
#endif
}
const std::string&Directory::path() const
......@@ -59,19 +64,6 @@ const std::vector<std::string>&Directory::dirs()
return m_dirs;
}
unsigned int Directory::lastModificationDate() const
{
if ( m_lastModificationDate == 0 )
{
struct stat s;
lstat( m_path.c_str(), &s );
if ( S_ISDIR( s.st_mode ) == false )
throw std::runtime_error( "The provided path isn't a directory" );
m_lastModificationDate = s.st_mtim.tv_sec;
}
return m_lastModificationDate;
}
std::shared_ptr<IDevice> Directory::device() const
{
//FIXME: Cache this?
......
......@@ -35,7 +35,6 @@ public:
virtual const std::string& path() const override;
virtual const std::vector<std::string>& files() override;
virtual const std::vector<std::string>& dirs() override;
virtual unsigned int lastModificationDate() const override;
virtual std::shared_ptr<IDevice> device() const override;
private:
......@@ -48,7 +47,6 @@ private:
const std::string m_path;
std::vector<std::string> m_files;
std::vector<std::string> m_dirs;
mutable unsigned int m_lastModificationDate;
};
}
......@@ -97,10 +97,8 @@ class Device;
class Directory : public fs::IDirectory
{
public:
Directory( Directory* parent, const std::string& path, unsigned int lastModif, std::shared_ptr<Device> device )
Directory( const std::string& path, std::shared_ptr<Device> device )
: m_path( path )
, m_parent( parent )
, m_lastModificationDate( lastModif )
, m_device( device )
{
if ( ( *m_path.crbegin() ) != '/' )
......@@ -132,11 +130,6 @@ public:
return m_dirPathes;
}
virtual unsigned int lastModificationDate() const override
{
return m_lastModificationDate;
}
virtual std::shared_ptr<fs::IDevice> device() const override
{
return std::static_pointer_cast<fs::IDevice>( m_device );
......@@ -149,7 +142,6 @@ public:
{
m_files[filePath] = std::make_shared<File>( m_path + filePath );
m_filePathes.clear();
markAsModified();
}
else
{
......@@ -160,23 +152,21 @@ public:
}
}
void addFolder( const std::string& folder, unsigned int lastModif )
void addFolder( const std::string& folder )
{
auto subFolder = utils::file::firstFolder( folder );
auto remainingPath = utils::file::removePath( folder, subFolder );
if ( remainingPath.empty() == true )
{
auto dir = std::make_shared<Directory>( this, m_path + subFolder,
lastModif, m_device );
auto dir = std::make_shared<Directory>( m_path + subFolder, m_device );
m_dirs[subFolder] = dir;
m_dirPathes.clear();
markAsModified();
}
else
{
auto it = m_dirs.find( subFolder );
assert( it != end( m_dirs ) );
it->second->addFolder( remainingPath, lastModif );
it->second->addFolder( remainingPath );
}
}
......@@ -189,7 +179,6 @@ public:
assert( it != end( m_files ) );
m_files.erase( it );
m_filePathes.clear();
markAsModified();
}
else
{
......@@ -247,7 +236,6 @@ public:
assert( it != end( m_dirs ) );
m_dirs.erase( it );
m_dirPathes.clear();
markAsModified();
}
else
{
......@@ -273,21 +261,12 @@ public:
}
}
void markAsModified()
{
if ( m_parent != nullptr )
m_parent->markAsModified();
m_lastModificationDate++;
}
private:
std::string m_path;
std::unordered_map<std::string, std::shared_ptr<File>> m_files;
std::unordered_map<std::string, std::shared_ptr<Directory>> m_dirs;
std::vector<std::string> m_filePathes;
std::vector<std::string> m_dirPathes;
Directory* m_parent;
unsigned int m_lastModificationDate;
std::shared_ptr<Device> m_device;
};
......@@ -309,7 +288,7 @@ public:
// initialize our fake root folder
void setupRoot()
{
m_root = std::make_shared<Directory>( nullptr, m_mountpoint, 0, shared_from_this() );
m_root = std::make_shared<Directory>( m_mountpoint, shared_from_this() );
}
virtual const std::string& uuid() const override { return m_uuid; }
......@@ -333,9 +312,9 @@ public:
m_root->addFile( relativePath( filePath ) );
}
void addFolder( const std::string& path, unsigned int lastModif )
void addFolder( const std::string& path )
{
m_root->addFolder( relativePath( path ), lastModif );
m_root->addFolder( relativePath( path ) );
}
void removeFile( const std::string& filePath )
......@@ -399,7 +378,7 @@ struct FileSystemFactory : public factory::IFileSystem
rootDevice->addFile( Root + "audio.mp3" );
rootDevice->addFile( Root + "not_a_media.something" );
rootDevice->addFile( Root + "some_other_file.seaotter" );
rootDevice->addFolder( SubFolder, 456 );
rootDevice->addFolder( SubFolder );
rootDevice->addFile( SubFolder + "subfile.mp4" );
}
......@@ -426,10 +405,10 @@ struct FileSystemFactory : public factory::IFileSystem
d->addFile( filePath );
}
void addFolder( const std::string& path, unsigned int lastModif )
void addFolder( const std::string& path )
{
auto d = device( path );
d->addFolder( path, lastModif );
d->addFolder( path );
}
void removeFile( const std::string& filePath )
......
......@@ -46,7 +46,7 @@ protected:
{
fsMock.reset( new mock::FileSystemFactory );
cbMock.reset( new mock::WaitForDiscoveryComplete );
fsMock->addFolder( "/a/mnt/", 0 );
fsMock->addFolder( "/a/mnt/" );
fsMock->addDevice( RemovableDeviceMountpoint, RemovableDeviceUuid );
fsMock->addFile( RemovableDeviceMountpoint + "removablefile.mp3" );
fsMock->addFile( RemovableDeviceMountpoint + "removablefile2.mp3" );
......
......@@ -202,7 +202,7 @@ TEST_F( Folders, NewFolderWithFile )
// Do not watch for live changes
ml.reset();
auto newFolder = mock::FileSystemFactory::Root + "newfolder/";
fsMock->addFolder( newFolder, time( nullptr ) );
fsMock->addFolder( newFolder );
fsMock->addFile( newFolder + "newfile.avi" );
// This will trigger a reload
......@@ -307,7 +307,6 @@ TEST_F( Folders, UpdateFile )
ml.reset();
fsMock->file( filePath )->markAsModified();
fsMock->directory( mock::FileSystemFactory::SubFolder )->markAsModified();
cbMock->prepareForReload();
Reload();
......
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