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:
parent
35567e6507
commit
96f4394dce
@ -61,7 +61,8 @@ LockFindSong(Directory &directory, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
|
UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory,
|
||||||
|
const char *name)
|
||||||
{
|
{
|
||||||
const char *tmp = strchr(name, '/');
|
const char *tmp = strchr(name, '/');
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
@ -72,7 +73,7 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
|
|||||||
subdir->device = DEVICE_INARCHIVE;
|
subdir->device = DEVICE_INARCHIVE;
|
||||||
|
|
||||||
//create directories first
|
//create directories first
|
||||||
UpdateArchiveTree(*subdir, tmp + 1);
|
UpdateArchiveTree(archive, *subdir, tmp + 1);
|
||||||
} else {
|
} else {
|
||||||
if (StringIsEmpty(name)) {
|
if (StringIsEmpty(name)) {
|
||||||
LogWarning(update_domain,
|
LogWarning(update_domain,
|
||||||
@ -83,7 +84,7 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
|
|||||||
//add file
|
//add file
|
||||||
Song *song = LockFindSong(directory, name);
|
Song *song = LockFindSong(directory, name);
|
||||||
if (song == nullptr) {
|
if (song == nullptr) {
|
||||||
song = Song::LoadFile(storage, name, directory);
|
song = Song::LoadFromArchive(archive, name, directory);
|
||||||
if (song != nullptr) {
|
if (song != nullptr) {
|
||||||
{
|
{
|
||||||
const ScopeDatabaseLock protect;
|
const ScopeDatabaseLock protect;
|
||||||
@ -100,16 +101,18 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
|
|||||||
|
|
||||||
class UpdateArchiveVisitor final : public ArchiveVisitor {
|
class UpdateArchiveVisitor final : public ArchiveVisitor {
|
||||||
UpdateWalk &walk;
|
UpdateWalk &walk;
|
||||||
|
ArchiveFile &archive;
|
||||||
Directory *directory;
|
Directory *directory;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UpdateArchiveVisitor(UpdateWalk &_walk, Directory *_directory)
|
UpdateArchiveVisitor(UpdateWalk &_walk, ArchiveFile &_archive,
|
||||||
:walk(_walk), directory(_directory) {}
|
Directory *_directory)
|
||||||
|
:walk(_walk), archive(_archive), directory(_directory) {}
|
||||||
|
|
||||||
virtual void VisitArchiveEntry(const char *path_utf8) override {
|
virtual void VisitArchiveEntry(const char *path_utf8) override {
|
||||||
FormatDebug(update_domain,
|
FormatDebug(update_domain,
|
||||||
"adding archive file: %s", path_utf8);
|
"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;
|
directory->mtime = info.mtime;
|
||||||
|
|
||||||
UpdateArchiveVisitor visitor(*this, directory);
|
UpdateArchiveVisitor visitor(*this, *file, directory);
|
||||||
file->Visit(visitor);
|
file->Visit(visitor);
|
||||||
file->Close();
|
file->Close();
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ struct stat;
|
|||||||
struct StorageFileInfo;
|
struct StorageFileInfo;
|
||||||
struct Directory;
|
struct Directory;
|
||||||
struct ArchivePlugin;
|
struct ArchivePlugin;
|
||||||
|
class ArchiveFile;
|
||||||
class Storage;
|
class Storage;
|
||||||
class ExcludeList;
|
class ExcludeList;
|
||||||
|
|
||||||
@ -101,7 +102,8 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_ARCHIVE
|
#ifdef ENABLE_ARCHIVE
|
||||||
void UpdateArchiveTree(Directory &parent, const char *name);
|
void UpdateArchiveTree(ArchiveFile &archive, Directory &parent,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
bool UpdateArchiveFile(Directory &directory,
|
bool UpdateArchiveFile(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
|
Loading…
Reference in New Issue
Block a user