DetachedSong: move code from Update() to LoadFile()

Avoid duplicate AllocatedPath::FromUTF8() invocations in two callers.
This commit is contained in:
Max Kellermann
2015-10-20 12:10:42 +02:00
parent 76f85e6f7b
commit fc2154ee92
5 changed files with 36 additions and 26 deletions

View File

@@ -54,17 +54,15 @@ SongLoader::LoadFile(const char *path_utf8, Error &error) const
}
#endif
if (client != nullptr) {
const auto path_fs = AllocatedPath::FromUTF8(path_utf8, error);
if (path_fs.IsNull())
return nullptr;
const auto path_fs = AllocatedPath::FromUTF8(path_utf8, error);
if (path_fs.IsNull())
return nullptr;
if (!client->AllowFile(path_fs, error))
return nullptr;
}
if (client != nullptr && !client->AllowFile(path_fs, error))
return nullptr;
DetachedSong *song = new DetachedSong(path_utf8);
if (!song->Update()) {
if (!song->LoadFile(path_fs)) {
error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_SONG),
"No such file");
delete song;