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

fs: Use a shared_ptr to manage files

parent 5171b0a2
......@@ -47,7 +47,7 @@ namespace factory
/// \brief createFile creates a representation of a file
/// \param fileName an absolute path to a file
///
virtual std::unique_ptr<fs::IFile> createFile( const std::string& fileName ) = 0;
virtual std::shared_ptr<fs::IFile> createFile( const std::string& fileName ) = 0;
///
/// \brief createDevice creates a representation of a device
/// \param uuid The device UUID
......
......@@ -203,7 +203,7 @@ std::vector<MediaPtr> MediaLibrary::videoFiles()
std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, Folder& parentFolder, fs::IDirectory& parentFolderFs )
{
std::unique_ptr<fs::IFile> fileFs;
std::shared_ptr<fs::IFile> fileFs;
try
{
fileFs = m_fsFactory->createFile( path );
......
......@@ -62,7 +62,7 @@ std::shared_ptr<fs::IDirectory> FileSystemFactory::createDirectory( const std::s
}
}
std::unique_ptr<fs::IFile> FileSystemFactory::createFile(const std::string& fileName)
std::shared_ptr<fs::IFile> FileSystemFactory::createFile(const std::string& fileName)
{
return std::unique_ptr<fs::IFile>( new fs::File( fileName ) );
}
......
......@@ -35,7 +35,7 @@ namespace factory
public:
FileSystemFactory();
virtual std::shared_ptr<fs::IDirectory> createDirectory( const std::string& path ) override;
virtual std::unique_ptr<fs::IFile> createFile( const std::string& fileName ) override;
virtual std::shared_ptr<fs::IFile> createFile( const std::string& fileName ) override;
virtual std::shared_ptr<fs::IDevice> createDevice( const std::string& uuid ) override;
virtual void refresh() override;
......
......@@ -443,15 +443,13 @@ struct FileSystemFactory : public factory::IFileSystem
return d->directory( path );
}
virtual std::unique_ptr<fs::IFile> createFile( const std::string &filePath ) override
virtual std::shared_ptr<fs::IFile> createFile( const std::string &filePath ) override
{
auto d = device( filePath );
if ( d == nullptr )
return nullptr;
auto f = d->file( filePath );
if ( f == nullptr )
return nullptr;
return std::unique_ptr<fs::IFile>( new File( *f ) );
return f;
}
virtual std::shared_ptr<fs::IDevice> createDevice( const std::string& uuid ) override
......@@ -592,9 +590,9 @@ public:
return nullptr;
}
virtual std::unique_ptr<fs::IFile> createFile( const std::string &fileName ) override
virtual std::shared_ptr<fs::IFile> createFile( const std::string &fileName ) override
{
return std::unique_ptr<fs::IFile>( new NoopFile( fileName ) );
return std::shared_ptr<fs::IFile>( new NoopFile( fileName ) );
}
virtual std::shared_ptr<fs::IDevice> createDevice( const std::string& ) 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