db/update/Archive: pass ArchiveFile to Song constructor

Don't open the ZIP file again and again for each song file.
This commit is contained in:
Max Kellermann 2016-02-26 15:00:41 +01:00
parent 35567e6507
commit 96f4394dce
2 changed files with 13 additions and 8 deletions

View File

@ -61,7 +61,8 @@ LockFindSong(Directory &directory, const char *name)
}
void
UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory,
const char *name)
{
const char *tmp = strchr(name, '/');
if (tmp) {
@ -72,7 +73,7 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
subdir->device = DEVICE_INARCHIVE;
//create directories first
UpdateArchiveTree(*subdir, tmp + 1);
UpdateArchiveTree(archive, *subdir, tmp + 1);
} else {
if (StringIsEmpty(name)) {
LogWarning(update_domain,
@ -83,7 +84,7 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
//add file
Song *song = LockFindSong(directory, name);
if (song == nullptr) {
song = Song::LoadFile(storage, name, directory);
song = Song::LoadFromArchive(archive, name, directory);
if (song != nullptr) {
{
const ScopeDatabaseLock protect;
@ -100,16 +101,18 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
class UpdateArchiveVisitor final : public ArchiveVisitor {
UpdateWalk &walk;
ArchiveFile &archive;
Directory *directory;
public:
UpdateArchiveVisitor(UpdateWalk &_walk, Directory *_directory)
:walk(_walk), directory(_directory) {}
UpdateArchiveVisitor(UpdateWalk &_walk, ArchiveFile &_archive,
Directory *_directory)
:walk(_walk), archive(_archive), directory(_directory) {}
virtual void VisitArchiveEntry(const char *path_utf8) override {
FormatDebug(update_domain,
"adding archive file: %s", path_utf8);
walk.UpdateArchiveTree(*directory, path_utf8);
walk.UpdateArchiveTree(archive, *directory, path_utf8);
}
};
@ -165,7 +168,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
directory->mtime = info.mtime;
UpdateArchiveVisitor visitor(*this, directory);
UpdateArchiveVisitor visitor(*this, *file, directory);
file->Visit(visitor);
file->Close();
}

View File

@ -30,6 +30,7 @@ struct stat;
struct StorageFileInfo;
struct Directory;
struct ArchivePlugin;
class ArchiveFile;
class Storage;
class ExcludeList;
@ -101,7 +102,8 @@ private:
#ifdef ENABLE_ARCHIVE
void UpdateArchiveTree(Directory &parent, const char *name);
void UpdateArchiveTree(ArchiveFile &archive, Directory &parent,
const char *name);
bool UpdateArchiveFile(Directory &directory,
const char *name, const char *suffix,