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

FsDiscoverer: Don't pass shared_ptr when no lifetime management is required

parent d37cd870
......@@ -204,7 +204,7 @@ MediaPtr MediaLibrary::file( const std::string& path )
return Media::fetch( m_dbConnection.get(), req, path );
}
std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, FolderPtr parentFolder )
std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, Folder* parentFolder )
{
LOG_INFO( "Adding ", path );
std::unique_ptr<fs::IFile> file;
......
......@@ -39,6 +39,7 @@ class Media;
class Movie;
class Show;
class Device;
class Folder;
class MediaLibrary : public IMediaLibrary
{
......@@ -53,7 +54,7 @@ class MediaLibrary : public IMediaLibrary
virtual std::vector<MediaPtr> audioFiles() override;
virtual std::vector<MediaPtr> videoFiles() override;
virtual MediaPtr file( const std::string& path ) override;
std::shared_ptr<Media> addFile(const std::string& path , FolderPtr parentFolder);
std::shared_ptr<Media> addFile(const std::string& path, Folder* parentFolder);
virtual bool deleteFile(const Media* file );
virtual FolderPtr folder( const std::string& path ) override;
......
......@@ -83,8 +83,8 @@ bool FsDiscoverer::discover( const std::string &entryPoint )
LOG_INFO( "Creating new device in DB ", deviceFs->uuid() );
device = Device::create( m_dbConn, deviceFs->uuid(), deviceFs->isRemovable() );
}
checkFiles( fsDir.get(), f );
checkSubfolders( fsDir.get(), f, blist );
checkFiles( fsDir.get(), f.get() );
checkSubfolders( fsDir.get(), f.get(), blist );
f->setLastModificationDate( fsDir->lastModificationDate() );
return true;
}
......@@ -102,13 +102,13 @@ void FsDiscoverer::reload()
auto folder = m_fsFactory->createDirectory( f->path() );
if ( folder->lastModificationDate() == f->lastModificationDate() )
continue;
checkSubfolders( folder.get(), f, blist );
checkFiles( folder.get(), f );
checkSubfolders( folder.get(), f.get(), blist );
checkFiles( folder.get(), f.get() );
f->setLastModificationDate( folder->lastModificationDate() );
}
}
bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, FolderPtr parentFolder, const std::vector<std::shared_ptr<Folder>> blacklist )
bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, Folder* parentFolder, const std::vector<std::shared_ptr<Folder>> blacklist )
{
// From here we can have:
// - New subfolder(s)
......@@ -142,8 +142,8 @@ bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, FolderPtr parentFold
LOG_INFO( "New folder detected: ", subFolderPath );
// Force a scan by setting lastModificationDate to 0
auto f = Folder::create( m_dbConn, subFolder->path(), 0, subFolder->isRemovable(), parentFolder->id() );
checkFiles( subFolder.get(), f );
checkSubfolders( subFolder.get(), f, blacklist );
checkFiles( subFolder.get(), f.get() );
checkSubfolders( subFolder.get(), f.get(), blacklist );
f->setLastModificationDate( subFolder->lastModificationDate() );
continue;
}
......@@ -157,8 +157,8 @@ bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, FolderPtr parentFold
continue;
}
// This folder was modified, let's recurse
checkSubfolders( subFolder.get(), folderInDb, blacklist );
checkFiles( subFolder.get(), folderInDb );
checkSubfolders( subFolder.get(), folderInDb.get(), blacklist );
checkFiles( subFolder.get(), folderInDb.get() );
folderInDb->setLastModificationDate( subFolder->lastModificationDate() );
subFoldersInDB.erase( it );
}
......@@ -171,7 +171,7 @@ bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, FolderPtr parentFold
return true;
}
void FsDiscoverer::checkFiles( fs::IDirectory* folder, FolderPtr parentFolder )
void FsDiscoverer::checkFiles( fs::IDirectory* folder, Folder* parentFolder )
{
LOG_INFO( "Checking file in ", folder->path() );
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name
......
......@@ -39,8 +39,8 @@ public:
virtual void reload() override;
private:
bool checkSubfolders(fs::IDirectory *folder, FolderPtr parentFolder , const std::vector<std::shared_ptr<Folder> > blacklist);
void checkFiles( fs::IDirectory *folder, FolderPtr parentFolder );
bool checkSubfolders(fs::IDirectory *folder, Folder* parentFolder , const std::vector<std::shared_ptr<Folder> > blacklist);
void checkFiles(fs::IDirectory *folder, Folder* parentFolder );
std::vector<std::shared_ptr<Folder>> blacklist() const;
bool isBlacklisted( const std::string& path, const std::vector<std::shared_ptr<Folder>>& blacklist ) const;
......
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