From 177d3b017861ddaff15a6e697fc4242f9b943321 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 3 Sep 2019 19:40:22 +0200 Subject: [PATCH] db/update/Archive: use MakeDirectoryIfModified() --- src/db/update/Archive.cxx | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/src/db/update/Archive.cxx b/src/db/update/Archive.cxx index d769be6f5..a73c5a3a7 100644 --- a/src/db/update/Archive.cxx +++ b/src/db/update/Archive.cxx @@ -37,13 +37,6 @@ #include -static Directory * -LockFindChild(Directory &directory, const char *name) noexcept -{ - const ScopeDatabaseLock protect; - return directory.FindChild(name); -} - static Directory * LockMakeChild(Directory &directory, const char *name) noexcept { @@ -134,46 +127,31 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name, const StorageFileInfo &info, const ArchivePlugin &plugin) noexcept { - Directory *directory = LockFindChild(parent, name); - - if (directory != nullptr && directory->mtime == info.mtime && - !walk_discard) - /* MPD has already scanned the archive, and it hasn't - changed since - don't consider updating it */ - return; - const auto path_fs = storage.MapChildFS(parent.GetPath(), name); if (path_fs.IsNull()) /* not a local file: skip, because the archive API supports only local files */ return; + Directory *directory = + LockMakeVirtualDirectoryIfModified(parent, name, info, + DEVICE_INARCHIVE); + if (directory == nullptr) + /* not modified */ + return; + /* open archive */ std::unique_ptr file; try { file = archive_file_open(&plugin, path_fs); } catch (...) { LogError(std::current_exception()); - if (directory != nullptr) - editor.LockDeleteDirectory(directory); + editor.LockDeleteDirectory(directory); return; } FormatDebug(update_domain, "archive %s opened", path_fs.c_str()); - if (directory == nullptr) { - FormatDebug(update_domain, - "creating archive directory: %s", name); - - const ScopeDatabaseLock protect; - directory = parent.CreateChild(name); - /* mark this directory as archive (we use device for - this) */ - directory->device = DEVICE_INARCHIVE; - } - - directory->mtime = info.mtime; - UpdateArchiveVisitor visitor(*this, *file, directory); file->Visit(visitor); }