db/simple/Song: wrap in std::unique_ptr<>

This commit is contained in:
Max Kellermann
2019-05-21 22:46:34 +02:00
parent 02bb47dd08
commit bbdf2dcf1e
10 changed files with 65 additions and 41 deletions

View File

@@ -82,11 +82,11 @@ UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory,
//add file
Song *song = LockFindSong(directory, name);
if (song == nullptr) {
song = Song::LoadFromArchive(archive, name, directory);
if (song != nullptr) {
auto new_song = Song::LoadFromArchive(archive, name, directory);
if (!new_song) {
{
const ScopeDatabaseLock protect;
directory.AddSong(song);
directory.AddSong(std::move(new_song));
}
modified = true;

View File

@@ -102,8 +102,7 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
}
for (auto &vtrack : v) {
Song *song = Song::NewFrom(std::move(vtrack),
*contdir);
auto song = Song::NewFrom(std::move(vtrack), *contdir);
// shouldn't be necessary but it's there..
song->mtime = info.mtime;
@@ -113,7 +112,7 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
{
const ScopeDatabaseLock protect;
contdir->AddSong(song);
contdir->AddSong(std::move(song));
}
modified = true;

View File

@@ -61,8 +61,8 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
if (song == nullptr) {
FormatDebug(update_domain, "reading %s/%s",
directory.GetPath(), name);
song = Song::LoadFile(storage, name, directory);
if (song == nullptr) {
auto new_song = Song::LoadFile(storage, name, directory);
if (!new_song) {
FormatDebug(update_domain,
"ignoring unrecognized file %s/%s",
directory.GetPath(), name);
@@ -71,7 +71,7 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
{
const ScopeDatabaseLock protect;
directory.AddSong(song);
directory.AddSong(std::move(new_song));
}
modified = true;